From dfecd4ad9d087eb68225bc061a764b1a80fd68d0 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Mon, 11 May 2020 11:16:29 -0700 Subject: [PATCH] fix tests --- .../LaunchPrompt/LaunchPrompt.test.jsx | 47 +++++++++---- .../PromptDetail/PromptDetail.test.jsx | 69 ++++++++++++++++++- 2 files changed, 100 insertions(+), 16 deletions(-) diff --git a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.test.jsx b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.test.jsx index 78e8dc5504..650e2cc640 100644 --- a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.test.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.test.jsx @@ -1,16 +1,22 @@ import React from 'react'; import { act, isElementOfType } from 'react-dom/test-utils'; -import { mountWithContexts } from '@testUtils/enzymeHelpers'; +import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers'; import LaunchPrompt from './LaunchPrompt'; -import InventoryStep from './InventoryStep'; -import CredentialsStep from './CredentialsStep'; -import OtherPromptsStep from './OtherPromptsStep'; -import PreviewStep from './PreviewStep'; -import { InventoriesAPI, CredentialsAPI, CredentialTypesAPI } from '@api'; +import InventoryStep from './steps/InventoryStep'; +import CredentialsStep from './steps/CredentialsStep'; +import OtherPromptsStep from './steps/OtherPromptsStep'; +import PreviewStep from './steps/PreviewStep'; +import { + InventoriesAPI, + CredentialsAPI, + CredentialTypesAPI, + JobTemplatesAPI, +} from '@api'; jest.mock('@api/models/Inventories'); jest.mock('@api/models/CredentialTypes'); jest.mock('@api/models/Credentials'); +jest.mock('@api/models/JobTemplates'); let config; const resource = { @@ -31,6 +37,13 @@ describe('LaunchPrompt', () => { data: { results: [{ id: 1 }], count: 1 }, }); CredentialTypesAPI.loadAllTypes({ data: { results: [{ type: 'ssh' }] } }); + JobTemplatesAPI.readSurvey.mockResolvedValue({ + data: { + name: '', + description: '', + spec: [{ type: 'text', variable: 'foo' }], + }, + }); config = { can_start_without_user_input: false, @@ -73,13 +86,14 @@ describe('LaunchPrompt', () => { /> ); }); - const steps = wrapper.find('Wizard').prop('steps'); + const wizard = await waitForElement(wrapper, 'Wizard'); + const steps = wizard.prop('steps'); expect(steps).toHaveLength(5); - expect(steps[0].name).toEqual('Inventory'); + expect(steps[0].name.props.children).toEqual('Inventory'); expect(steps[1].name).toEqual('Credentials'); - expect(steps[2].name).toEqual('Other Prompts'); - expect(steps[3].name).toEqual('Survey'); + expect(steps[2].name.props.children).toEqual('Other Prompts'); + expect(steps[3].name.props.children).toEqual('Survey'); expect(steps[4].name).toEqual('Preview'); }); @@ -98,10 +112,11 @@ describe('LaunchPrompt', () => { /> ); }); - const steps = wrapper.find('Wizard').prop('steps'); + const wizard = await waitForElement(wrapper, 'Wizard'); + const steps = wizard.prop('steps'); expect(steps).toHaveLength(2); - expect(steps[0].name).toEqual('Inventory'); + expect(steps[0].name.props.children).toEqual('Inventory'); expect(isElementOfType(steps[0].component, InventoryStep)).toEqual(true); expect(isElementOfType(steps[1].component, PreviewStep)).toEqual(true); }); @@ -121,7 +136,8 @@ describe('LaunchPrompt', () => { /> ); }); - const steps = wrapper.find('Wizard').prop('steps'); + const wizard = await waitForElement(wrapper, 'Wizard'); + const steps = wizard.prop('steps'); expect(steps).toHaveLength(2); expect(steps[0].name).toEqual('Credentials'); @@ -144,10 +160,11 @@ describe('LaunchPrompt', () => { /> ); }); - const steps = wrapper.find('Wizard').prop('steps'); + const wizard = await waitForElement(wrapper, 'Wizard'); + const steps = wizard.prop('steps'); expect(steps).toHaveLength(2); - expect(steps[0].name).toEqual('Other Prompts'); + expect(steps[0].name.props.children).toEqual('Other Prompts'); expect(isElementOfType(steps[0].component, OtherPromptsStep)).toEqual(true); expect(isElementOfType(steps[1].component, PreviewStep)).toEqual(true); }); diff --git a/awx/ui_next/src/components/PromptDetail/PromptDetail.test.jsx b/awx/ui_next/src/components/PromptDetail/PromptDetail.test.jsx index 17ecfd4e30..0ee3a43a1c 100644 --- a/awx/ui_next/src/components/PromptDetail/PromptDetail.test.jsx +++ b/awx/ui_next/src/components/PromptDetail/PromptDetail.test.jsx @@ -67,7 +67,7 @@ describe('PromptDetail', () => { expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value); } - expect(wrapper.find('PromptDetail h2').text()).toBe('Prompted Values'); + expect(wrapper.find('PromptDetail h2')).toHaveLength(0); assertDetail('Name', 'Mock JT'); assertDetail('Description', 'Mock JT Description'); assertDetail('Type', 'Job Template'); @@ -143,4 +143,71 @@ describe('PromptDetail', () => { expect(overrideDetails.find('VariablesDetail').length).toBe(0); }); }); + + describe('with overrides', () => { + let wrapper; + const overrides = { + extra_vars: '---one: two\nbar: baz', + inventory: { + name: 'Override inventory', + }, + }; + + beforeAll(() => { + wrapper = mountWithContexts( + + ); + }); + + afterAll(() => { + wrapper.unmount(); + }); + + test('should render overridden details', () => { + function assertDetail(label, value) { + expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label); + expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value); + } + + expect(wrapper.find('PromptDetail h2').text()).toBe('Prompted Values'); + assertDetail('Name', 'Mock JT'); + assertDetail('Description', 'Mock JT Description'); + assertDetail('Type', 'Job Template'); + assertDetail('Job Type', 'Run'); + assertDetail('Inventory', 'Override inventory'); + assertDetail('Source Control Branch', 'Foo branch'); + assertDetail('Limit', 'alpha:beta'); + assertDetail('Verbosity', '3 (Debug)'); + assertDetail('Show Changes', 'Off'); + expect(wrapper.find('VariablesDetail').prop('value')).toEqual( + '---one: two\nbar: baz' + ); + expect( + wrapper + .find('Detail[label="Credentials"]') + .containsAllMatchingElements([ + + SSH:Credential 1 + , + + Awx:Credential 2 + , + ]) + ).toEqual(true); + expect( + wrapper + .find('Detail[label="Job Tags"]') + .containsAnyMatchingElements([T_100, T_200]) + ).toEqual(true); + expect( + wrapper + .find('Detail[label="Skip Tags"]') + .containsAllMatchingElements([S_100, S_200]) + ).toEqual(true); + }); + }); });