Impoves test and removes uncessary condition

This commit is contained in:
Alex Corey
2020-03-10 11:39:37 -04:00
parent 3a6528dc0d
commit 65e988b44c
3 changed files with 20 additions and 24 deletions

View File

@@ -120,10 +120,7 @@ function SurveyList({ template, i18n }) {
const canDelete = template.summary_fields.user_capabilities.delete; const canDelete = template.summary_fields.user_capabilities.delete;
let content; let content;
if ( if (isLoading || isToggleLoading || isDeleteLoading) {
(isLoading || isToggleLoading || isDeleteLoading) &&
questions?.length <= 0
) {
content = <ContentLoading />; content = <ContentLoading />;
} else if (contentError) { } else if (contentError) {
content = <ContentError error={contentError} />; content = <ContentError error={contentError} />;

View File

@@ -20,7 +20,7 @@ describe('<SurveyList />', () => {
test('expect component to mount successfully', async () => { test('expect component to mount successfully', async () => {
let wrapper; let wrapper;
await act(async () => { await act(async () => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyList template={mockJobTemplateData} /> <SurveyList template={mockJobTemplateData} />
); );
}); });
@@ -29,21 +29,20 @@ describe('<SurveyList />', () => {
test('expect api to be called to get survey', async () => { test('expect api to be called to get survey', async () => {
let wrapper; let wrapper;
await act(async () => { await act(async () => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyList template={mockJobTemplateData} /> <SurveyList template={mockJobTemplateData} />
); );
}); });
expect(JobTemplatesAPI.readSurvey).toBeCalledWith(7); expect(JobTemplatesAPI.readSurvey).toBeCalledWith(7);
wrapper.update(); wrapper.update();
expect(wrapper.find('SurveyListItem').length).toBe(1); expect(wrapper.find('SurveyListItem').length).toBe(1);
}); });
test('error in retrieving the survey throws an error', async () => { test('error in retrieving the survey throws an error', async () => {
JobTemplatesAPI.readSurvey.mockRejectedValue(new Error()); JobTemplatesAPI.readSurvey.mockRejectedValue(new Error());
let wrapper; let wrapper;
await act(async () => { await act(async () => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyList template={{ ...mockJobTemplateData, id: 'a' }} /> <SurveyList template={{ ...mockJobTemplateData, id: 'a' }} />
); );
}); });
@@ -56,7 +55,7 @@ describe('<SurveyList />', () => {
JobTemplatesAPI.update.mockResolvedValue(); JobTemplatesAPI.update.mockResolvedValue();
let wrapper; let wrapper;
await act(async () => { await act(async () => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyList <SurveyList
template={{ ...mockJobTemplateData, survey_enabled: false }} template={{ ...mockJobTemplateData, survey_enabled: false }}
/> />
@@ -66,7 +65,7 @@ describe('<SurveyList />', () => {
expect(wrapper.find('Switch').length).toBe(1); expect(wrapper.find('Switch').length).toBe(1);
expect(wrapper.find('Switch').prop('isChecked')).toBe(false); expect(wrapper.find('Switch').prop('isChecked')).toBe(false);
await act(async () => { await act(async () => {
await wrapper.find('Switch').invoke('onChange')(true); wrapper.find('Switch').invoke('onChange')(true);
}); });
wrapper.update(); wrapper.update();
@@ -80,7 +79,7 @@ describe('<SurveyList />', () => {
test('selectAll enables delete button and calls the api to delete properly', async () => { test('selectAll enables delete button and calls the api to delete properly', async () => {
let wrapper; let wrapper;
await act(async () => { await act(async () => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyList <SurveyList
template={{ ...mockJobTemplateData, survey_enabled: false }} template={{ ...mockJobTemplateData, survey_enabled: false }}
/> />
@@ -127,7 +126,7 @@ describe('Survey with no questions', () => {
JobTemplatesAPI.readSurvey.mockResolvedValue({}); JobTemplatesAPI.readSurvey.mockResolvedValue({});
let wrapper; let wrapper;
await act(async () => { await act(async () => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyList template={mockJobTemplateData} /> <SurveyList template={mockJobTemplateData} />
); );
}); });

View File

@@ -6,11 +6,11 @@ import SurveyToolbar from './SurveyToolbar';
jest.mock('@api/models/JobTemplates'); jest.mock('@api/models/JobTemplates');
describe('<SurveyToolbar />', () => { describe('<SurveyToolbar />', () => {
test('delete Button is disabled', async () => { test('delete Button is disabled', () => {
let wrapper; let wrapper;
await act(async () => { act(() => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyToolbar <SurveyToolbar
isDeleteDisabled isDeleteDisabled
onSelectAll={jest.fn()} onSelectAll={jest.fn()}
@@ -26,10 +26,10 @@ describe('<SurveyToolbar />', () => {
); );
}); });
test('delete Button is enabled', async () => { test('delete Button is enabled', () => {
let wrapper; let wrapper;
await act(async () => { act(() => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyToolbar <SurveyToolbar
isDeleteDisabled={false} isDeleteDisabled={false}
onSelectAll={jest.fn()} onSelectAll={jest.fn()}
@@ -47,10 +47,10 @@ describe('<SurveyToolbar />', () => {
); );
}); });
test('switch is off', async () => { test('switch is off', () => {
let wrapper; let wrapper;
await act(async () => { act(() => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyToolbar <SurveyToolbar
surveyEnabled={false} surveyEnabled={false}
isDeleteDisabled={false} isDeleteDisabled={false}
@@ -66,10 +66,10 @@ describe('<SurveyToolbar />', () => {
expect(wrapper.find('Switch').prop('isChecked')).toBe(false); expect(wrapper.find('Switch').prop('isChecked')).toBe(false);
}); });
test('switch is on', async () => { test('switch is on', () => {
let wrapper; let wrapper;
await act(async () => { act(() => {
wrapper = await mountWithContexts( wrapper = mountWithContexts(
<SurveyToolbar <SurveyToolbar
surveyEnabled surveyEnabled
isDeleteDisabled={false} isDeleteDisabled={false}