From e3cfdb74baa5df8e297ae450fec8abccbf5e12a4 Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 3 Feb 2020 17:42:39 -0500 Subject: [PATCH] Adds basic unit test coverage to visualizer components (not including modals). --- .../WorkflowOutputToolbar.test.jsx | 46 ++-- .../Modals/DeleteAllNodesModal.jsx | 2 + .../Modals/LinkModals/LinkModal.jsx | 3 + .../Visualizer.test.jsx | 207 ++++++++++++++++ .../VisualizerGraph.jsx | 8 +- .../VisualizerGraph.test.jsx | 226 +++++++++++++++++ .../VisualizerLink.jsx | 41 ++-- .../VisualizerLink.test.jsx | 147 +++++++++++ .../VisualizerNode.jsx | 45 ++-- .../VisualizerNode.test.jsx | 230 ++++++++++++++++++ .../VisualizerStartScreen.test.jsx | 22 ++ .../VisualizerToolbar.jsx | 6 +- .../VisualizerToolbar.test.jsx | 94 +++++++ 13 files changed, 1018 insertions(+), 59 deletions(-) create mode 100644 awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Visualizer.test.jsx create mode 100644 awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerGraph.test.jsx create mode 100644 awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerLink.test.jsx create mode 100644 awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerNode.test.jsx create mode 100644 awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerStartScreen.test.jsx create mode 100644 awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerToolbar.test.jsx diff --git a/awx/ui_next/src/screens/Job/WorkflowOutput/WorkflowOutputToolbar.test.jsx b/awx/ui_next/src/screens/Job/WorkflowOutput/WorkflowOutputToolbar.test.jsx index 4afe13e93f..3523e08f32 100644 --- a/awx/ui_next/src/screens/Job/WorkflowOutput/WorkflowOutputToolbar.test.jsx +++ b/awx/ui_next/src/screens/Job/WorkflowOutput/WorkflowOutputToolbar.test.jsx @@ -1,13 +1,17 @@ import React from 'react'; -import { WorkflowStateContext } from '@contexts/Workflow'; +import { + WorkflowDispatchContext, + WorkflowStateContext, +} from '@contexts/Workflow'; import { mountWithContexts } from '@testUtils/enzymeHelpers'; import WorkflowOutputToolbar from './WorkflowOutputToolbar'; +let wrapper; +const dispatch = jest.fn(); const job = { id: 1, status: 'successful', }; - const workflowContext = { nodes: [], showLegend: false, @@ -15,16 +19,7 @@ const workflowContext = { }; describe('WorkflowOutputToolbar', () => { - test('mounts successfully', () => { - const wrapper = mountWithContexts( - - - - ); - expect(wrapper).toHaveLength(1); - }); - - test('shows correct number of nodes', () => { + beforeAll(() => { const nodes = [ { id: 1, @@ -37,12 +32,31 @@ describe('WorkflowOutputToolbar', () => { isDeleted: true, }, ]; - const wrapper = mountWithContexts( - - - + wrapper = mountWithContexts( + + + + + ); + }); + + afterAll(() => { + wrapper.unmount(); + }); + + test('Shows correct number of nodes', () => { // The start node (id=1) and deleted nodes (isDeleted=true) should be ignored expect(wrapper.find('Badge').text()).toBe('1'); }); + + test('Toggle Legend button dispatches as expected', () => { + wrapper.find('CompassIcon').simulate('click'); + expect(dispatch).toHaveBeenCalledWith({ type: 'TOGGLE_LEGEND' }); + }); + + test('Toggle Tools button dispatches as expected', () => { + wrapper.find('WrenchIcon').simulate('click'); + expect(dispatch).toHaveBeenCalledWith({ type: 'TOGGLE_TOOLS' }); + }); }); diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/DeleteAllNodesModal.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/DeleteAllNodesModal.jsx index 324bb98b87..9947656801 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/DeleteAllNodesModal.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/DeleteAllNodesModal.jsx @@ -11,6 +11,7 @@ function DeleteAllNodesModal({ i18n }) { , diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerToolbar.test.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerToolbar.test.jsx new file mode 100644 index 0000000000..c0699d36c1 --- /dev/null +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/VisualizerToolbar.test.jsx @@ -0,0 +1,94 @@ +import React from 'react'; +import { + WorkflowDispatchContext, + WorkflowStateContext, +} from '@contexts/Workflow'; +import { mountWithContexts } from '@testUtils/enzymeHelpers'; +import VisualizerToolbar from './VisualizerToolbar'; + +let wrapper; +const close = jest.fn(); +const dispatch = jest.fn(); +const save = jest.fn(); +const template = { + id: 1, + name: 'Test JT', +}; +const workflowContext = { + nodes: [], + showLegend: false, + showTools: false, +}; + +describe('VisualizerToolbar', () => { + beforeAll(() => { + const nodes = [ + { + id: 1, + }, + { + id: 2, + }, + { + id: 3, + isDeleted: true, + }, + ]; + wrapper = mountWithContexts( + + + + + + ); + }); + + afterAll(() => { + wrapper.unmount(); + }); + + test('Shows correct number of nodes', () => { + // The start node (id=1) and deleted nodes (isDeleted=true) should be ignored + expect(wrapper.find('Badge').text()).toBe('1'); + }); + + test('Toggle Legend button dispatches as expected', () => { + wrapper.find('CompassIcon').simulate('click'); + expect(dispatch).toHaveBeenCalledWith({ type: 'TOGGLE_LEGEND' }); + }); + + test('Toggle Tools button dispatches as expected', () => { + wrapper.find('WrenchIcon').simulate('click'); + expect(dispatch).toHaveBeenCalledWith({ type: 'TOGGLE_TOOLS' }); + }); + + test('Delete All button dispatches as expected', () => { + wrapper.find('TrashAltIcon').simulate('click'); + expect(dispatch).toHaveBeenCalledWith({ + type: 'SET_SHOW_DELETE_ALL_NODES_MODAL', + value: true, + }); + }); + + test('Delete All button dispatches as expected', () => { + wrapper.find('TrashAltIcon').simulate('click'); + expect(dispatch).toHaveBeenCalledWith({ + type: 'SET_SHOW_DELETE_ALL_NODES_MODAL', + value: true, + }); + }); + + test('Save button calls expected function', () => { + wrapper.find('button[aria-label="Save"]').simulate('click'); + expect(save).toHaveBeenCalled(); + }); + + test('Close button calls expected function', () => { + wrapper.find('TimesIcon').simulate('click'); + expect(close).toHaveBeenCalled(); + }); +});