From df57b144c499d5a445a078b988285c8c228fe602 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Tue, 6 Nov 2018 12:25:36 -0500 Subject: [PATCH] fix logout in App.jsx and update test --- __tests__/App.test.jsx | 9 +++++++-- src/App.jsx | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/__tests__/App.test.jsx b/__tests__/App.test.jsx index 0a9a9dd58b..01e216659d 100644 --- a/__tests__/App.test.jsx +++ b/__tests__/App.test.jsx @@ -4,6 +4,7 @@ import App from '../src/App'; import api from '../src/api'; 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'; @@ -62,11 +63,15 @@ describe('', () => { expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP); }); - test('api.logout called from logout button', () => { - api.logout = jest.fn(); + test('api.logout called from logout button', async () => { + api.logout = jest.fn().mockImplementation(() => Promise.resolve({})); const appWrapper = mount(); const logoutButton = appWrapper.find('LogoutButton'); logoutButton.props().onDevLogout(); + appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' }); expect(api.logout).toHaveBeenCalledTimes(1); + await asyncFlush(); + expect(appWrapper.state().activeItem).toBe(DEFAULT_ACTIVE_ITEM); + expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP); }); }); diff --git a/src/App.jsx b/src/App.jsx index 3852933e6e..cabdf6ddfa 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -76,6 +76,13 @@ class App extends React.Component { this.setState({ activeGroup: 'views_group', activeItem: 'views_group_dashboard' }); } + onDevLogout = () => { + api.logout() + .then(() => { + this.setState({ activeGroup: 'views_group', activeItem: 'views_group_dashboard' }); + }); + } + render () { const { activeItem, activeGroup, isNavOpen } = this.state; const { logo, loginInfo } = this.props; @@ -103,7 +110,7 @@ class App extends React.Component { header={( } - avatar={} + avatar={ this.onDevLogout()} />} showNavToggle onNavToggle={this.onNavToggle} />