add unit test coverage for TowerLogo.jsx

This commit is contained in:
Jake McDermott 2019-01-07 07:30:58 -05:00
parent 4936238344
commit 8756da59fa
No known key found for this signature in database
GPG Key ID: 9A6F084352C3A0B7
4 changed files with 21 additions and 31 deletions

View File

@ -108,17 +108,6 @@ describe('<App />', () => {
});
});
test('onLogoClick sets selected nav back to defaults', () => {
const appWrapper = shallow(<App />);
appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' });
expect(appWrapper.state().activeItem).toBe('bar');
expect(appWrapper.state().activeGroup).toBe('foo');
appWrapper.instance().onLogoClick();
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
});
test('onLogout makes expected call to api client', async (done) => {
const logout = jest.fn(() => Promise.resolve());
const api = { logout };

View File

@ -29,11 +29,10 @@ describe('<TowerLogo />', () => {
});
test('adds navigation to route history on click', () => {
const onLogoClick = jest.fn();
logoWrapper = mount(
<MemoryRouter>
<I18nProvider>
<TowerLogo onClick={onLogoClick} />
<TowerLogo linkTo="/" />
</I18nProvider>
</MemoryRouter>
);
@ -43,12 +42,26 @@ describe('<TowerLogo />', () => {
expect(towerLogoElem.props().history.length).toBe(2);
});
test('linkTo prop is optional', () => {
logoWrapper = mount(
<MemoryRouter>
<I18nProvider>
<TowerLogo />
</I18nProvider>
</MemoryRouter>
);
findChildren();
expect(towerLogoElem.props().history.length).toBe(1);
logoWrapper.simulate('click');
expect(towerLogoElem.props().history.length).toBe(1);
});
test('handles mouse over and out state.hover changes', () => {
const onLogoClick = jest.fn();
logoWrapper = mount(
<MemoryRouter>
<I18nProvider>
<TowerLogo onClick={onLogoClick} />
<TowerLogo />
</I18nProvider>
</MemoryRouter>
);

View File

@ -34,7 +34,6 @@ class App extends Component {
this.onLogout = this.onLogout.bind(this);
this.onAboutModalClose = this.onAboutModalClose.bind(this);
this.onAboutModalOpen = this.onAboutModalOpen.bind(this);
this.onLogoClick = this.onLogoClick.bind(this);
this.onNavToggle = this.onNavToggle.bind(this);
};
@ -72,10 +71,6 @@ class App extends Component {
this.setState(({ isNavOpen }) => ({ isNavOpen: !isNavOpen }));
}
onLogoClick () {
this.setState({ activeGroup: 'views_group' });
}
render () {
const {
ansible_version,
@ -105,11 +100,7 @@ class App extends Component {
<PageHeader
showNavToggle
onNavToggle={this.onNavToggle}
logo={
<TowerLogo
onClick={this.onLogoClick}
/>
}
logo={<TowerLogo linkTo="/"/>}
toolbar={
<PageHeaderToolbar
isAboutDisabled={!version}

View File

@ -18,13 +18,11 @@ class TowerLogo extends Component {
}
onClick () {
const { history, onClick: handleClick } = this.props;
const { history, linkTo } = this.props;
if (!handleClick) return;
if (!linkTo) return;
history.push('/');
handleClick();
history.push(linkTo);
}
onHover () {
@ -35,11 +33,10 @@ class TowerLogo extends Component {
render () {
const { hover } = this.state;
const { onClick: handleClick } = this.props;
let src = TowerLogoHeader;
if (hover && handleClick) {
if (hover) {
src = TowerLogoHeaderHover;
}