1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00
awx/__tests__/index.test.jsx

52 lines
1.7 KiB
React
Raw Normal View History

2019-01-02 10:28:24 +03:00
import { mount } from 'enzyme';
import { main, getLanguage } from '../src/index';
2018-11-02 20:45:11 +03:00
2019-01-02 10:28:24 +03:00
const render = template => mount(template);
2019-01-24 21:05:36 +03:00
const data = { custom_logo: 'foo', custom_login_info: '' };
2018-11-02 20:45:11 +03:00
2019-01-02 10:28:24 +03:00
describe('index.jsx', () => {
test('login loads when unauthenticated', async (done) => {
2019-01-02 10:28:24 +03:00
const isAuthenticated = () => false;
const getRoot = jest.fn(() => Promise.resolve({ data }));
2018-11-02 20:45:11 +03:00
2019-01-02 10:28:24 +03:00
const api = { getRoot, isAuthenticated };
const wrapper = await main(render, api);
2018-11-02 20:45:11 +03:00
2019-01-02 10:28:24 +03:00
expect(api.getRoot).toHaveBeenCalled();
expect(wrapper.find('App')).toHaveLength(0);
2019-01-02 10:28:24 +03:00
expect(wrapper.find('Login')).toHaveLength(1);
2018-11-02 20:45:11 +03:00
2019-01-02 10:28:24 +03:00
const { src } = wrapper.find('Login Brand img').props();
expect(src).toContain(data.custom_logo);
done();
});
test('app loads when authenticated', async (done) => {
2019-01-02 10:28:24 +03:00
const isAuthenticated = () => true;
const getRoot = jest.fn(() => Promise.resolve({ data }));
const api = { getRoot, isAuthenticated };
const wrapper = await main(render, api);
2018-11-02 20:45:11 +03:00
2019-01-02 10:28:24 +03:00
expect(api.getRoot).toHaveBeenCalled();
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);
2019-01-02 10:28:24 +03:00
expect(wrapper.find('Login')).toHaveLength(0);
2018-11-02 20:45:11 +03:00
2019-01-02 10:28:24 +03:00
done();
2018-11-02 20:45:11 +03:00
});
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');
});
2018-11-02 20:45:11 +03:00
});