add more unit test coverage for index.jsx

This commit is contained in:
Jake McDermott
2019-01-07 07:26:21 -05:00
parent cb0367ac28
commit 4936238344
2 changed files with 31 additions and 14 deletions

View File

@@ -1,11 +1,11 @@
import { mount } from 'enzyme';
import { main } from '../src/index';
import { main, getLanguage } from '../src/index';
const render = template => mount(template);
const data = { custom_logo: 'foo', custom_login_info: '' }
describe('index.jsx', () => {
test('initialization', async (done) => {
test('login loads when unauthenticated', async (done) => {
const isAuthenticated = () => false;
const getRoot = jest.fn(() => Promise.resolve({ data }));
@@ -13,7 +13,7 @@ describe('index.jsx', () => {
const wrapper = await main(render, api);
expect(api.getRoot).toHaveBeenCalled();
expect(wrapper.find('Dashboard')).toHaveLength(0);
expect(wrapper.find('App')).toHaveLength(0);
expect(wrapper.find('Login')).toHaveLength(1);
const { src } = wrapper.find('Login Brand img').props();
@@ -22,7 +22,7 @@ describe('index.jsx', () => {
done();
});
test('dashboard is loaded when authenticated', async (done) => {
test('app loads when authenticated', async (done) => {
const isAuthenticated = () => true;
const getRoot = jest.fn(() => Promise.resolve({ data }));
@@ -30,9 +30,22 @@ describe('index.jsx', () => {
const wrapper = await main(render, api);
expect(api.getRoot).toHaveBeenCalled();
expect(wrapper.find('Dashboard')).toHaveLength(1);
expect(wrapper.find('App')).toHaveLength(1);
expect(wrapper.find('Login')).toHaveLength(0);
wrapper.find('header a').simulate('click');
wrapper.update();
expect(wrapper.find('App')).toHaveLength(1);
expect(wrapper.find('Login')).toHaveLength(0);
done();
});
test('getLanguage returns the expected language code', () => {
expect(getLanguage({ languages: ['es-US'] })).toEqual('es');
expect(getLanguage({ languages: ['es-US'], language: 'fr-FR', userLanguage: 'en-US' })).toEqual('es');
expect(getLanguage({ language: 'fr-FR', userLanguage: 'en-US' })).toEqual('fr');
expect(getLanguage({ userLanguage: 'en-US' })).toEqual('en');
});
});