mirror of
https://github.com/ansible/awx.git
synced 2026-02-19 20:20:06 -03:30
test fixup
This commit is contained in:
@@ -1,22 +1,38 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import api from '../src/api';
|
||||
|
||||
import { mount } from 'enzyme';
|
||||
import { main } from '../src/index';
|
||||
|
||||
const custom_logo = (<div>logo</div>);
|
||||
const custom_login_info = 'custom login info';
|
||||
|
||||
jest.mock('react-dom', () => ({ render: jest.fn() }));
|
||||
const render = template => mount(template);
|
||||
const data = { custom_logo: 'foo', custom_login_info: '' }
|
||||
|
||||
describe('index.jsx', () => {
|
||||
test('renders without crashing', async () => {
|
||||
api.getRoot = jest.fn().mockImplementation(() => Promise
|
||||
.resolve({ data: { custom_logo, custom_login_info } }));
|
||||
test('initialization', async (done) => {
|
||||
const isAuthenticated = () => false;
|
||||
const getRoot = jest.fn(() => Promise.resolve({ data }));
|
||||
|
||||
await main();
|
||||
const api = { getRoot, isAuthenticated };
|
||||
const wrapper = await main(render, api);
|
||||
|
||||
expect(ReactDOM.render).toHaveBeenCalled();
|
||||
expect(api.getRoot).toHaveBeenCalled();
|
||||
expect(wrapper.find('Dashboard')).toHaveLength(0);
|
||||
expect(wrapper.find('Login')).toHaveLength(1);
|
||||
|
||||
const { src } = wrapper.find('Login Brand img').props();
|
||||
expect(src).toContain(data.custom_logo);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('dashboard is loaded when authenticated', async (done) => {
|
||||
const isAuthenticated = () => true;
|
||||
const getRoot = jest.fn(() => Promise.resolve({ data }));
|
||||
|
||||
const api = { getRoot, isAuthenticated };
|
||||
const wrapper = await main(render, api);
|
||||
|
||||
expect(api.getRoot).toHaveBeenCalled();
|
||||
expect(wrapper.find('Dashboard')).toHaveLength(1);
|
||||
expect(wrapper.find('Login')).toHaveLength(0);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user