From 65e988b44c3398b91e1fe6578303e2c4bacb41db Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 10 Mar 2020 11:39:37 -0400 Subject: [PATCH] Impoves test and removes uncessary condition --- .../screens/Template/shared/SurveyList.jsx | 5 +--- .../Template/shared/SurveyList.test.jsx | 15 ++++++------ .../Template/shared/SurveyToolbar.test.jsx | 24 +++++++++---------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/awx/ui_next/src/screens/Template/shared/SurveyList.jsx b/awx/ui_next/src/screens/Template/shared/SurveyList.jsx index ca5b39055c..3758dbdba9 100644 --- a/awx/ui_next/src/screens/Template/shared/SurveyList.jsx +++ b/awx/ui_next/src/screens/Template/shared/SurveyList.jsx @@ -120,10 +120,7 @@ function SurveyList({ template, i18n }) { const canDelete = template.summary_fields.user_capabilities.delete; let content; - if ( - (isLoading || isToggleLoading || isDeleteLoading) && - questions?.length <= 0 - ) { + if (isLoading || isToggleLoading || isDeleteLoading) { content = ; } else if (contentError) { content = ; diff --git a/awx/ui_next/src/screens/Template/shared/SurveyList.test.jsx b/awx/ui_next/src/screens/Template/shared/SurveyList.test.jsx index 6f3e3e7415..c044eb9da4 100644 --- a/awx/ui_next/src/screens/Template/shared/SurveyList.test.jsx +++ b/awx/ui_next/src/screens/Template/shared/SurveyList.test.jsx @@ -20,7 +20,7 @@ describe('', () => { test('expect component to mount successfully', async () => { let wrapper; await act(async () => { - wrapper = await mountWithContexts( + wrapper = mountWithContexts( ); }); @@ -29,21 +29,20 @@ describe('', () => { test('expect api to be called to get survey', async () => { let wrapper; await act(async () => { - wrapper = await mountWithContexts( + wrapper = mountWithContexts( ); }); expect(JobTemplatesAPI.readSurvey).toBeCalledWith(7); wrapper.update(); - expect(wrapper.find('SurveyListItem').length).toBe(1); }); test('error in retrieving the survey throws an error', async () => { JobTemplatesAPI.readSurvey.mockRejectedValue(new Error()); let wrapper; await act(async () => { - wrapper = await mountWithContexts( + wrapper = mountWithContexts( ); }); @@ -56,7 +55,7 @@ describe('', () => { JobTemplatesAPI.update.mockResolvedValue(); let wrapper; await act(async () => { - wrapper = await mountWithContexts( + wrapper = mountWithContexts( @@ -66,7 +65,7 @@ describe('', () => { expect(wrapper.find('Switch').length).toBe(1); expect(wrapper.find('Switch').prop('isChecked')).toBe(false); await act(async () => { - await wrapper.find('Switch').invoke('onChange')(true); + wrapper.find('Switch').invoke('onChange')(true); }); wrapper.update(); @@ -80,7 +79,7 @@ describe('', () => { test('selectAll enables delete button and calls the api to delete properly', async () => { let wrapper; await act(async () => { - wrapper = await mountWithContexts( + wrapper = mountWithContexts( @@ -127,7 +126,7 @@ describe('Survey with no questions', () => { JobTemplatesAPI.readSurvey.mockResolvedValue({}); let wrapper; await act(async () => { - wrapper = await mountWithContexts( + wrapper = mountWithContexts( ); }); diff --git a/awx/ui_next/src/screens/Template/shared/SurveyToolbar.test.jsx b/awx/ui_next/src/screens/Template/shared/SurveyToolbar.test.jsx index 1b708dc56f..0249332aab 100644 --- a/awx/ui_next/src/screens/Template/shared/SurveyToolbar.test.jsx +++ b/awx/ui_next/src/screens/Template/shared/SurveyToolbar.test.jsx @@ -6,11 +6,11 @@ import SurveyToolbar from './SurveyToolbar'; jest.mock('@api/models/JobTemplates'); describe('', () => { - test('delete Button is disabled', async () => { + test('delete Button is disabled', () => { let wrapper; - await act(async () => { - wrapper = await mountWithContexts( + act(() => { + wrapper = mountWithContexts( ', () => { ); }); - test('delete Button is enabled', async () => { + test('delete Button is enabled', () => { let wrapper; - await act(async () => { - wrapper = await mountWithContexts( + act(() => { + wrapper = mountWithContexts( ', () => { ); }); - test('switch is off', async () => { + test('switch is off', () => { let wrapper; - await act(async () => { - wrapper = await mountWithContexts( + act(() => { + wrapper = mountWithContexts( ', () => { expect(wrapper.find('Switch').prop('isChecked')).toBe(false); }); - test('switch is on', async () => { + test('switch is on', () => { let wrapper; - await act(async () => { - wrapper = await mountWithContexts( + act(() => { + wrapper = mountWithContexts(