From a67d107a5844510e4980b0a770056830ea71cdd5 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 8 Nov 2022 09:20:38 -0500 Subject: [PATCH] Fixes page crash when job template has been deleted. Adds unit tests --- .../WorkflowOutputNavigation.js | 22 ++--- .../WorkflowOutputNavigation.test.js | 85 +++++++++++++++++++ 2 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.test.js diff --git a/awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.js b/awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.js index e3dafc1a67..ebedbd06fc 100644 --- a/awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.js +++ b/awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.js @@ -24,12 +24,10 @@ function WorkflowOutputNavigation({ relatedJobs, parentRef }) { const { id } = useParams(); const relevantResults = relatedJobs.filter( - ({ - job: jobId, - summary_fields: { - unified_job_template: { unified_job_type }, - }, - }) => jobId && `${jobId}` !== id && unified_job_type !== 'workflow_approval' + ({ job: jobId, summary_fields }) => + jobId && + `${jobId}` !== id && + summary_fields.job.type !== 'workflow_approval' ); const [isOpen, setIsOpen] = useState(false); @@ -101,16 +99,14 @@ function WorkflowOutputNavigation({ relatedJobs, parentRef }) { {sortedJobs?.map((node) => ( {stringIsUUID(node.identifier) - ? node.summary_fields.unified_job_template.name + ? node.summary_fields.job.name : node.identifier} ))} diff --git a/awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.test.js b/awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.test.js new file mode 100644 index 0000000000..7e54240c6f --- /dev/null +++ b/awx/ui/src/components/WorkflowOutputNavigation/WorkflowOutputNavigation.test.js @@ -0,0 +1,85 @@ +import React from 'react'; +import { within, render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import WorkflowOutputNavigation from './WorkflowOutputNavigation'; +import { createMemoryHistory } from 'history'; +import { I18nProvider } from '@lingui/react'; +import { i18n } from '@lingui/core'; +import { en } from 'make-plural/plurals'; +import english from '../../../src/locales/en/messages'; +import { Router } from 'react-router-dom'; + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useParams: () => ({ + id: 1, + }), +})); +const jobs = [ + { + id: 1, + summary_fields: { + job: { + name: 'Ansible', + type: 'project_update', + id: 1, + status: 'successful', + }, + }, + job: 4, + }, + { + id: 2, + summary_fields: { + job: { + name: 'Durham', + type: 'job', + id: 2, + status: 'successful', + }, + }, + job: 3, + }, + { + id: 3, + summary_fields: { + job: { + name: 'Red hat', + type: 'job', + id: 3, + status: 'successful', + }, + }, + job: 2, + }, +]; + +describe('', () => { + test('Should open modal and deprovision node', async () => { + i18n.loadLocaleData({ en: { plurals: en } }); + i18n.load({ en: english }); + i18n.activate('en'); + const user = userEvent.setup(); + const ref = jest + .spyOn(React, 'useRef') + .mockReturnValueOnce({ current: 'div' }); + const history = createMemoryHistory({ + initialEntries: ['jobs/playbook/2/output'], + }); + render( + + + + + + ); + + const button = screen.getByRole('button'); + await user.click(button); + + await waitFor(() => screen.getByText('Workflow Nodes')); + await waitFor(() => screen.getByText('Red hat')); + await waitFor(() => screen.getByText('Durham')); + await waitFor(() => screen.getByText('Ansible')); + }); +});