mirror of
https://github.com/ansible/awx.git
synced 2026-02-02 10:08:10 -03:30
Merge pull request #40 from marshmalien/side-nav-bug
Update active nav item based on url
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { HashRouter as Router } from 'react-router-dom';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import App from '../src/App';
|
||||
import api from '../src/api';
|
||||
@@ -21,7 +22,7 @@ describe('<App />', () => {
|
||||
api.isAuthenticated = jest.fn();
|
||||
api.isAuthenticated.mockReturnValue(false);
|
||||
|
||||
const appWrapper = mount(<App />);
|
||||
const appWrapper = mount(<Router><App /></Router>);
|
||||
|
||||
const login = appWrapper.find(Login);
|
||||
expect(login.length).toBe(1);
|
||||
@@ -33,7 +34,7 @@ describe('<App />', () => {
|
||||
api.isAuthenticated = jest.fn();
|
||||
api.isAuthenticated.mockReturnValue(true);
|
||||
|
||||
const appWrapper = mount(<App />);
|
||||
const appWrapper = mount(<Router><App /></Router>);
|
||||
|
||||
const dashboard = appWrapper.find(Dashboard);
|
||||
expect(dashboard.length).toBe(1);
|
||||
@@ -41,35 +42,26 @@ describe('<App />', () => {
|
||||
expect(login.length).toBe(0);
|
||||
});
|
||||
|
||||
test('onNavSelect sets state.activeItem and state.activeGroup', () => {
|
||||
const appWrapper = shallow(<App />);
|
||||
appWrapper.instance().onNavSelect({ itemId: 'foo', groupId: 'bar' });
|
||||
expect(appWrapper.state().activeItem).toBe('foo');
|
||||
expect(appWrapper.state().activeGroup).toBe('bar');
|
||||
});
|
||||
|
||||
test('onNavToggle sets state.isNavOpen to opposite', () => {
|
||||
const appWrapper = shallow(<App />);
|
||||
const appWrapper = shallow(<App.WrappedComponent />);
|
||||
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 />);
|
||||
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().activeItem).toBe(DEFAULT_ACTIVE_ITEM);
|
||||
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
|
||||
});
|
||||
|
||||
test('api.logout called from logout button', async () => {
|
||||
api.get = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||
const appWrapper = mount(<App />);
|
||||
const logoutButton = appWrapper.find('LogoutButton');
|
||||
logoutButton.props().onDevLogout();
|
||||
const appWrapper = shallow(<App.WrappedComponent />);
|
||||
appWrapper.instance().onDevLogout();
|
||||
appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' });
|
||||
expect(api.get).toHaveBeenCalledTimes(1);
|
||||
expect(api.get).toHaveBeenCalledWith(API_LOGOUT);
|
||||
|
||||
Reference in New Issue
Block a user