diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplate.test.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplate.test.jsx index e3e66bf8c1..2a083ffe2a 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplate.test.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplate.test.jsx @@ -74,91 +74,119 @@ describe('', () => { data: { results: [{ id: 1, name: 'Org Foo' }] }, }); }); - beforeEach(() => { - WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValue({ - data: { actions: { PUT: {} } }, - }); - history = createMemoryHistory({ - initialEntries: ['/templates/workflow_job_template/1/details'], - }); - act(() => { - wrapper = mountWithContexts( - ( - {}} me={mockMe} /> - )} - />, - { - context: { - router: { - history, - }, - }, - } - ); - }); - }); afterEach(() => { jest.clearAllMocks(); wrapper.unmount(); }); - test('calls api to get workflow job template data', async () => { - expect(wrapper.find('WorkflowJobTemplate').length).toBe(1); - expect(WorkflowJobTemplatesAPI.readDetail).toBeCalledWith('1'); - wrapper.update(); - await sleep(0); - expect(WorkflowJobTemplatesAPI.readWebhookKey).toBeCalledWith('1'); - expect(WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions).toBeCalled(); + describe('User can PUT', () => { + beforeEach(async () => { + WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValue({ + data: { actions: { PUT: {} } }, + }); + history = createMemoryHistory({ + initialEntries: ['/templates/workflow_job_template/1/details'], + }); + await act(async () => { + wrapper = mountWithContexts( + ( + {}} me={mockMe} /> + )} + />, + { + context: { + router: { + history, + }, + }, + } + ); + }); + }); + test('calls api to get workflow job template data', async () => { + expect(wrapper.find('WorkflowJobTemplate').length).toBe(1); + expect(WorkflowJobTemplatesAPI.readDetail).toBeCalledWith('1'); + wrapper.update(); + await sleep(0); + expect(WorkflowJobTemplatesAPI.readWebhookKey).toBeCalledWith('1'); + expect( + WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions + ).toBeCalled(); - expect(CredentialsAPI.readDetail).toBeCalledWith(1234567); - expect(OrganizationsAPI.read).toBeCalledWith({ - page_size: 1, - role_level: 'notification_admin_role', + expect(CredentialsAPI.readDetail).toBeCalledWith(1234567); + expect(OrganizationsAPI.read).toBeCalledWith({ + page_size: 1, + role_level: 'notification_admin_role', + }); + }); + + test('renders proper tabs', async () => { + const tabs = [ + 'Details', + 'Access', + 'Notifications', + 'Schedules', + 'Visualizer', + 'Completed Jobs', + 'Survey', + ]; + waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0); + wrapper.update(); + wrapper.find('TabContainer').forEach(tc => { + tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`))); + }); + }); + + test('Does not render Notifications tab', async () => { + OrganizationsAPI.read.mockResolvedValue({ + data: { results: [] }, + }); + const tabs = [ + 'Details', + 'Access', + 'Schedules', + 'Visualizer', + 'Completed Jobs', + 'Survey', + ]; + waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0); + wrapper.update(); + wrapper.find('TabContainer').forEach(tc => { + tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`))); + }); }); }); - - test('renders proper tabs', async () => { - const tabs = [ - 'Details', - 'Access', - 'Notifications', - 'Schedules', - 'Visualizer', - 'Completed Jobs', - 'Survey', - ]; - waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0); - wrapper.update(); - wrapper.find('TabContainer').forEach(tc => { - tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`))); + describe('User cannot PUT', () => { + beforeEach(async () => { + WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValueOnce( + { + data: { actions: {} }, + } + ); + history = createMemoryHistory({ + initialEntries: ['/templates/workflow_job_template/1/details'], + }); + await act(async () => { + wrapper = mountWithContexts( + ( + {}} me={mockMe} /> + )} + />, + { + context: { + router: { + history, + }, + }, + } + ); + }); }); - }); - - test('Does not render Notifications tab', async () => { - OrganizationsAPI.read.mockResolvedValue({ - data: { results: [] }, + test('should not call for webhook key', async () => { + expect(WorkflowJobTemplatesAPI.readWebhookKey).not.toBeCalled(); }); - const tabs = [ - 'Details', - 'Access', - 'Schedules', - 'Visualizer', - 'Completed Jobs', - 'Survey', - ]; - waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0); - wrapper.update(); - wrapper.find('TabContainer').forEach(tc => { - tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`))); - }); - }); - test('should not call for webhook key', async () => { - WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValueOnce( - { - data: { actions: {} }, - } - ); - expect(WorkflowJobTemplatesAPI.readWebhookKey).not.toBeCalled(); }); });