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