mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 20:30:46 -03:30
update app and towerlogo tests and remove stale code
This commit is contained in:
parent
ebd09883fe
commit
e25dcb2448
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { HashRouter as Router } from 'react-router-dom';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import App from '../src/App';
|
||||
import api from '../src/api';
|
||||
@ -7,10 +7,6 @@ import { API_LOGOUT } from '../src/endpoints';
|
||||
|
||||
import Dashboard from '../src/pages/Dashboard';
|
||||
import Login from '../src/pages/Login';
|
||||
import { asyncFlush } from '../jest.setup';
|
||||
|
||||
const DEFAULT_ACTIVE_GROUP = 'views_group';
|
||||
const DEFAULT_ACTIVE_ITEM = 'views_group_dashboard';
|
||||
|
||||
describe('<App />', () => {
|
||||
test('renders without crashing', () => {
|
||||
@ -22,7 +18,7 @@ describe('<App />', () => {
|
||||
api.isAuthenticated = jest.fn();
|
||||
api.isAuthenticated.mockReturnValue(false);
|
||||
|
||||
const appWrapper = mount(<Router><App /></Router>);
|
||||
const appWrapper = mount(<MemoryRouter><App /></MemoryRouter>);
|
||||
|
||||
const login = appWrapper.find(Login);
|
||||
expect(login.length).toBe(1);
|
||||
@ -34,7 +30,7 @@ describe('<App />', () => {
|
||||
api.isAuthenticated = jest.fn();
|
||||
api.isAuthenticated.mockReturnValue(true);
|
||||
|
||||
const appWrapper = mount(<Router><App /></Router>);
|
||||
const appWrapper = mount(<MemoryRouter><App /></MemoryRouter>);
|
||||
|
||||
const dashboard = appWrapper.find(Dashboard);
|
||||
expect(dashboard.length).toBe(1);
|
||||
@ -49,24 +45,15 @@ describe('<App />', () => {
|
||||
expect(appWrapper.state().isNavOpen).toBe(false);
|
||||
});
|
||||
|
||||
test('onLogoClick sets selected nav back to defaults', () => {
|
||||
const appWrapper = shallow(<App.WrappedComponent />);
|
||||
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('api.logout called from logout button', async () => {
|
||||
const logOutButtonSelector = 'button[aria-label="Logout"]';
|
||||
api.get = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||
const appWrapper = shallow(<App.WrappedComponent />);
|
||||
appWrapper.instance().onDevLogout();
|
||||
const appWrapper = mount(<MemoryRouter><App /></MemoryRouter>);
|
||||
const logOutButton = appWrapper.find(logOutButtonSelector);
|
||||
expect(logOutButton.length).toBe(1);
|
||||
logOutButton.simulate('click');
|
||||
appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' });
|
||||
expect(api.get).toHaveBeenCalledTimes(1);
|
||||
expect(api.get).toHaveBeenCalledWith(API_LOGOUT);
|
||||
await asyncFlush();
|
||||
expect(appWrapper.state().activeItem).toBe(DEFAULT_ACTIVE_ITEM);
|
||||
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
|
||||
});
|
||||
});
|
||||
|
||||
@ -43,20 +43,6 @@ describe('<TowerLogo />', () => {
|
||||
expect(towerLogoElem.props().history.length).toBe(2);
|
||||
});
|
||||
|
||||
test('gracefully handles not being passed click handler', () => {
|
||||
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(
|
||||
|
||||
@ -81,13 +81,8 @@ class App extends React.Component {
|
||||
this.setState(({ isNavOpen }) => ({ isNavOpen: !isNavOpen }));
|
||||
};
|
||||
|
||||
onLogoClick = () => {
|
||||
this.setState({ activeGroup: 'views_group' });
|
||||
}
|
||||
|
||||
onDevLogout = async () => {
|
||||
await api.get(API_LOGOUT);
|
||||
this.setState({ activeGroup: 'views_group', activeItem: 'views_group_dashboard' });
|
||||
}
|
||||
|
||||
render () {
|
||||
@ -134,7 +129,7 @@ class App extends React.Component {
|
||||
<Page
|
||||
header={(
|
||||
<PageHeader
|
||||
logo={<TowerLogo onClick={this.onLogoClick} />}
|
||||
logo={<TowerLogo />}
|
||||
toolbar={PageToolbar}
|
||||
showNavToggle
|
||||
onNavToggle={this.onNavToggle}
|
||||
|
||||
@ -15,13 +15,8 @@ class TowerLogo extends Component {
|
||||
}
|
||||
|
||||
onClick = () => {
|
||||
const { history, onClick: handleClick } = this.props;
|
||||
|
||||
if (!handleClick) return;
|
||||
|
||||
const { history } = this.props;
|
||||
history.push('/');
|
||||
|
||||
handleClick();
|
||||
};
|
||||
|
||||
onHover = () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user