1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00
awx/__tests__/components/TowerLogo.test.jsx

82 lines
2.2 KiB
React
Raw Normal View History

2018-11-02 23:34:02 +03:00
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { mount } from 'enzyme';
2018-12-10 18:16:52 +03:00
import { I18nProvider } from '@lingui/react';
2018-11-02 23:34:02 +03:00
import TowerLogo from '../../src/components/TowerLogo';
let logoWrapper;
let towerLogoElem;
let brandElem;
const findChildren = () => {
towerLogoElem = logoWrapper.find('TowerLogo');
brandElem = logoWrapper.find('Brand');
};
describe('<TowerLogo />', () => {
test('initially renders without crashing', () => {
2018-12-10 18:16:52 +03:00
logoWrapper = mount(
<MemoryRouter>
<I18nProvider>
<TowerLogo />
</I18nProvider>
</MemoryRouter>
);
2018-11-02 23:34:02 +03:00
findChildren();
expect(logoWrapper.length).toBe(1);
expect(towerLogoElem.length).toBe(1);
expect(brandElem.length).toBe(1);
});
test('adds navigation to route history on click', () => {
2018-12-10 18:16:52 +03:00
logoWrapper = mount(
<MemoryRouter>
<I18nProvider>
<TowerLogo linkTo="/" />
2018-12-10 18:16:52 +03:00
</I18nProvider>
</MemoryRouter>
);
2018-11-02 23:34:02 +03:00
findChildren();
expect(towerLogoElem.props().history.length).toBe(1);
logoWrapper.simulate('click');
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);
});
2018-11-02 23:34:02 +03:00
test('handles mouse over and out state.hover changes', () => {
2018-12-10 18:16:52 +03:00
logoWrapper = mount(
<MemoryRouter>
<I18nProvider>
<TowerLogo />
2018-12-10 18:16:52 +03:00
</I18nProvider>
</MemoryRouter>
);
2018-11-02 23:34:02 +03:00
findChildren();
findChildren();
expect(brandElem.props().src).toBe('tower-logo-header.svg');
brandElem.props().onMouseOver();
expect(towerLogoElem.state().hover).toBe(true);
logoWrapper.update();
findChildren();
expect(brandElem.props().src).toBe('tower-logo-header-hover.svg');
brandElem.props().onMouseOut();
expect(towerLogoElem.state().hover).toBe(false);
logoWrapper.update();
findChildren();
expect(brandElem.props().src).toBe('tower-logo-header.svg');
});
});