fleet/frontend/components/AuthenticatedAdminRoutes/AuthenticatedAdminRoutes.tests.js
Zach Wasserman 0670db66c4
Migrate JS tests to Jest and update libraries (#74)
- Move from Mocha to Jest for JS testing (Jest seems to have better support for
 'watching' tests and a more active community these days).
- Codemod existing tests to Jest syntax (using https://github.com/skovhus/jest-codemods)
- Fix some errors in tests that were previously hidden.
- Update Babel.
2020-12-01 10:15:12 -08:00

37 lines
1.1 KiB
JavaScript

import { mount } from 'enzyme';
import ConnectedAdminRoutes from './AuthenticatedAdminRoutes';
import { connectedComponent, reduxMockStore } from '../../test/helpers';
describe('AuthenticatedAdminRoutes - layout', () => {
const redirectToHomeAction = {
type: '@@router/CALL_HISTORY_METHOD',
payload: {
method: 'push',
args: ['/'],
},
};
it('redirects to the homepage if the user is not an admin', () => {
const user = { id: 1, admin: false };
const storeWithoutAdminUser = { auth: { user } };
const mockStore = reduxMockStore(storeWithoutAdminUser);
mount(
connectedComponent(ConnectedAdminRoutes, { mockStore }),
);
expect(mockStore.getActions()).toContainEqual(redirectToHomeAction);
});
it('does not redirect if the user is an admin', () => {
const user = { id: 1, admin: true };
const storeWithAdminUser = { auth: { user } };
const mockStore = reduxMockStore(storeWithAdminUser);
mount(
connectedComponent(ConnectedAdminRoutes, { mockStore }),
);
expect(mockStore.getActions()).not.toContainEqual(redirectToHomeAction);
});
});