mirror of
https://github.com/ansible/awx.git
synced 2026-02-19 12:10:06 -03:30
add params for component routing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { HashRouter as Router } from 'react-router-dom';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import App from '../src/App';
|
||||
import api from '../src/api';
|
||||
@@ -7,6 +7,16 @@ import { API_LOGOUT, API_CONFIG } 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';
|
||||
|
||||
const routeGroups = [{
|
||||
groupId: DEFAULT_ACTIVE_GROUP,
|
||||
title: 'test',
|
||||
routes: [{ path: '/home', title: 'Dashboard', component: Dashboard }],
|
||||
}];
|
||||
|
||||
describe('<App />', () => {
|
||||
test('renders without crashing', () => {
|
||||
@@ -18,7 +28,7 @@ describe('<App />', () => {
|
||||
api.isAuthenticated = jest.fn();
|
||||
api.isAuthenticated.mockReturnValue(false);
|
||||
|
||||
const appWrapper = mount(<MemoryRouter><App /></MemoryRouter>);
|
||||
const appWrapper = mount(<Router><App /></Router>);
|
||||
|
||||
const login = appWrapper.find(Login);
|
||||
expect(login.length).toBe(1);
|
||||
@@ -30,7 +40,7 @@ describe('<App />', () => {
|
||||
api.isAuthenticated = jest.fn();
|
||||
api.isAuthenticated.mockReturnValue(true);
|
||||
|
||||
const appWrapper = mount(<MemoryRouter><App /></MemoryRouter>);
|
||||
const appWrapper = mount(<Router><App routeGroups={routeGroups} /></Router>);
|
||||
|
||||
const dashboard = appWrapper.find(Dashboard);
|
||||
expect(dashboard.length).toBe(1);
|
||||
@@ -39,21 +49,30 @@ describe('<App />', () => {
|
||||
});
|
||||
|
||||
test('onNavToggle sets state.isNavOpen to opposite', () => {
|
||||
const appWrapper = shallow(<App.WrappedComponent />);
|
||||
const appWrapper = shallow(<App />);
|
||||
expect(appWrapper.state().isNavOpen).toBe(true);
|
||||
appWrapper.instance().onNavToggle();
|
||||
expect(appWrapper.state().isNavOpen).toBe(false);
|
||||
});
|
||||
|
||||
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('api.logout called from logout button', async () => {
|
||||
const logOutButtonSelector = 'button[aria-label="Logout"]';
|
||||
api.get = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||
const appWrapper = mount(<MemoryRouter><App /></MemoryRouter>);
|
||||
const logOutButton = appWrapper.find(logOutButtonSelector);
|
||||
expect(logOutButton.length).toBe(1);
|
||||
logOutButton.simulate('click');
|
||||
const appWrapper = shallow(<App />);
|
||||
appWrapper.instance().onDevLogout();
|
||||
appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' });
|
||||
expect(api.get).toHaveBeenCalledWith(API_LOGOUT);
|
||||
await asyncFlush();
|
||||
expect(appWrapper.state().activeItem).toBe(DEFAULT_ACTIVE_ITEM);
|
||||
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
|
||||
});
|
||||
|
||||
test('Componenet makes REST call to API_CONFIG endpoint when mounted', () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
|
||||
|
||||
import api from '../src/api';
|
||||
|
||||
import indexToRender from '../src/index';
|
||||
import { main } from '../src/index';
|
||||
|
||||
const custom_logo = (<div>logo</div>);
|
||||
const custom_login_info = 'custom login info';
|
||||
@@ -15,7 +15,7 @@ describe('index.jsx', () => {
|
||||
api.getRoot = jest.fn().mockImplementation(() => Promise
|
||||
.resolve({ data: { custom_logo, custom_login_info } }));
|
||||
|
||||
await indexToRender();
|
||||
await main();
|
||||
|
||||
expect(ReactDOM.render).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user