update App.jsx and improve coverage

abstract LogoutButton to component
This commit is contained in:
John Mitchell
2018-11-02 17:47:59 -04:00
parent 08d2718f5e
commit 7b099578c8
4 changed files with 90 additions and 11 deletions

View File

@@ -5,6 +5,9 @@ import api from '../src/api';
import Dashboard from '../src/pages/Dashboard';
import Login from '../src/pages/Login';
const DEFAULT_ACTIVE_GROUP = 'views_group';
const DEFAULT_ACTIVE_ITEM = 'views_group_dashboard';
describe('<App />', () => {
test('renders without crashing', () => {
const appWrapper = shallow(<App />);
@@ -34,4 +37,36 @@ describe('<App />', () => {
const login = appWrapper.find(Login);
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 />);
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().activeItem).toBe(DEFAULT_ACTIVE_ITEM);
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
});
test('api.logout called from logout button', () => {
api.logout = jest.fn();
const appWrapper = mount(<App />);
const logoutButton = appWrapper.find('LogoutButton');
logoutButton.props().onDevLogout();
expect(api.logout).toHaveBeenCalledTimes(1);
});
});