fleet/frontend/components/App/App.tests.jsx
Mike Stone 448e806c36 374 confirm invite (#583)
* ConfirmInviteForm

* Render ConfirmInvitePage at /invites/:invite_token

* Add email, pre-fill name, and handle successful submit

* Fix button text
2016-12-29 15:27:43 -05:00

104 lines
2.9 KiB
JavaScript

import expect, { spyOn, restoreSpies } from 'expect';
import { mount } from 'enzyme';
import ConnectedApp from './App';
import * as authActions from '../../redux/nodes/auth/actions';
import helpers from '../../test/helpers';
import local from '../../utilities/local';
const {
connectedComponent,
reduxMockStore,
} = helpers;
describe('App - component', () => {
const store = { app: {}, auth: {}, notifications: {} };
const mockStore = reduxMockStore(store);
const component = mount(
connectedComponent(ConnectedApp, { mockStore })
);
afterEach(() => {
restoreSpies();
local.setItem('auth_token', null);
});
it('renders', () => {
expect(component).toExist();
});
it('loads the current user if there is an auth token but no user', () => {
local.setItem('auth_token', 'ABC123');
const spy = spyOn(authActions, 'fetchCurrentUser').andCall(() => {
return (dispatch) => {
dispatch({ type: 'LOAD_USER_ACTION' });
return Promise.resolve();
};
});
const application = connectedComponent(ConnectedApp, { mockStore });
mount(application);
expect(spy).toHaveBeenCalled();
});
it('does not load the current user if is it already loaded', () => {
local.setItem('auth_token', 'ABC123');
const spy = spyOn(authActions, 'fetchCurrentUser').andCall(() => {
return { type: 'LOAD_USER_ACTION' };
});
const storeWithUser = {
app: {},
auth: {
user: {
id: 1,
email: 'hi@thegnar.co',
},
},
notifications: {},
};
const mockStoreWithUser = reduxMockStore(storeWithUser);
const application = connectedComponent(ConnectedApp, { mockStore: mockStoreWithUser });
mount(application);
expect(spy).toNotHaveBeenCalled();
});
it('does not load the current user if there is no auth token', () => {
local.setItem('auth_token', null);
const spy = spyOn(authActions, 'fetchCurrentUser').andCall(() => {
return { type: 'LOAD_USER_ACTION' };
});
const application = connectedComponent(ConnectedApp, { mockStore });
mount(application);
expect(spy).toNotHaveBeenCalled();
});
it('renders the FlashMessage component when notifications are present', () => {
const storeWithNotifications = {
app: {},
auth: {
},
notifications: {
alertType: 'success',
isVisible: true,
message: 'nice jerb!',
},
};
const mockStoreWithNotifications = reduxMockStore(storeWithNotifications);
const componentWithFlash = connectedComponent(ConnectedApp, {
mockStore: mockStoreWithNotifications,
});
const componentWithoutFlash = connectedComponent(ConnectedApp, {
mockStore,
});
const appWithFlash = mount(componentWithFlash);
const appWithoutFlash = mount(componentWithoutFlash);
expect(appWithFlash.find('FlashMessage').html()).toExist();
expect(appWithoutFlash.find('FlashMessage').html()).toNotExist();
});
});