diff --git a/__tests__/App.test.jsx b/__tests__/App.test.jsx index 420d6832ab..013e5cf725 100644 --- a/__tests__/App.test.jsx +++ b/__tests__/App.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { HashRouter } from 'react-router-dom'; +import { MemoryRouter } from 'react-router-dom'; import { I18nProvider } from '@lingui/react'; import { mount, shallow } from 'enzyme'; @@ -12,7 +12,7 @@ const DEFAULT_ACTIVE_GROUP = 'views_group'; describe('', () => { test('expected content is rendered', () => { const appWrapper = mount( - + ', () => { )} /> - + ); // page components @@ -56,6 +56,48 @@ describe('', () => { expect(appWrapper.find('#group_two').length).toBe(1); }); + test('opening the about modal renders prefetched config data', async (done) => { + const ansible_version = '111'; + const version = '222'; + + const getConfig = jest.fn(() => Promise.resolve({ data: { ansible_version, version} })); + const api = { getConfig }; + + const wrapper = mount( + + + + + + ); + + await asyncFlush(); + expect(getConfig).toHaveBeenCalledTimes(1); + + // open about modal + const aboutDropdown = 'Dropdown QuestionCircleIcon'; + const aboutButton = 'DropdownItem li button'; + const aboutModalContent = 'AboutModalBoxContent'; + const aboutModalClose = 'button[aria-label="Close Dialog"]'; + + expect(wrapper.find(aboutModalContent)).toHaveLength(0); + wrapper.find(aboutDropdown).simulate('click'); + wrapper.find(aboutButton).simulate('click'); + wrapper.update(); + + // check about modal content + const content = wrapper.find(aboutModalContent); + expect(content).toHaveLength(1); + expect(content.find('dd').text()).toContain(ansible_version); + expect(content.find('pre').text()).toContain(`< Tower ${version} >`); + + // close about modal + wrapper.find(aboutModalClose).simulate('click'); + expect(wrapper.find(aboutModalContent)).toHaveLength(0); + + done(); + }); + test('onNavToggle sets state.isNavOpen to opposite', () => { const appWrapper = shallow(); const { onNavToggle } = appWrapper.instance(); @@ -89,17 +131,4 @@ describe('', () => { done(); }); - - test('Component makes expected call to api client when mounted', () => { - const getConfig = jest.fn().mockImplementation(() => Promise.resolve({})); - const api = { getConfig }; - const appWrapper = mount( - - - - - - ); - expect(getConfig).toHaveBeenCalledTimes(1); - }); }); diff --git a/src/App.jsx b/src/App.jsx index 93003c0c8d..a87b1a7944 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -28,7 +28,6 @@ class App extends Component { isAboutModalOpen: false, isNavOpen, version: null, - }; this.fetchConfig = this.fetchConfig.bind(this);