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;
let content;
if (
(isLoading || isToggleLoading || isDeleteLoading) &&
questions?.length <= 0
) {
if (isLoading || isToggleLoading || isDeleteLoading) {
content = <ContentLoading />;
} else if (contentError) {
content = <ContentError error={contentError} />;

View File

@ -20,7 +20,7 @@ describe('<SurveyList />', () => {
test('expect component to mount successfully', async () => {
let wrapper;
await act(async () => {
wrapper = await mountWithContexts(
wrapper = mountWithContexts(
<SurveyList template={mockJobTemplateData} />
);
});
@ -29,21 +29,20 @@ describe('<SurveyList />', () => {
test('expect api to be called to get survey', async () => {
let wrapper;
await act(async () => {
wrapper = await mountWithContexts(
wrapper = mountWithContexts(
<SurveyList template={mockJobTemplateData} />
);
});
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(
<SurveyList template={{ ...mockJobTemplateData, id: 'a' }} />
);
});
@ -56,7 +55,7 @@ describe('<SurveyList />', () => {
JobTemplatesAPI.update.mockResolvedValue();
let wrapper;
await act(async () => {
wrapper = await mountWithContexts(
wrapper = mountWithContexts(
<SurveyList
template={{ ...mockJobTemplateData, survey_enabled: false }}
/>
@ -66,7 +65,7 @@ describe('<SurveyList />', () => {
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('<SurveyList />', () => {
test('selectAll enables delete button and calls the api to delete properly', async () => {
let wrapper;
await act(async () => {
wrapper = await mountWithContexts(
wrapper = mountWithContexts(
<SurveyList
template={{ ...mockJobTemplateData, survey_enabled: false }}
/>
@ -127,7 +126,7 @@ describe('Survey with no questions', () => {
JobTemplatesAPI.readSurvey.mockResolvedValue({});
let wrapper;
await act(async () => {
wrapper = await mountWithContexts(
wrapper = mountWithContexts(
<SurveyList template={mockJobTemplateData} />
);
});

View File

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