From 0d5df1ba1312536fa3dc2772bc19a446157596a1 Mon Sep 17 00:00:00 2001 From: ismay Date: Thu, 27 Jul 2023 16:41:41 +0200 Subject: [PATCH] test: add sequence edit test --- src/pages/SequenceEdit/SequenceEdit.test.js | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/pages/SequenceEdit/SequenceEdit.test.js diff --git a/src/pages/SequenceEdit/SequenceEdit.test.js b/src/pages/SequenceEdit/SequenceEdit.test.js new file mode 100644 index 000000000..4b60d0ae8 --- /dev/null +++ b/src/pages/SequenceEdit/SequenceEdit.test.js @@ -0,0 +1,62 @@ +import React from 'react' +import { shallow } from 'enzyme' +import { useParams } from 'react-router-dom' +import { useJobScheduleById } from '../../hooks/job-schedules' +import SequenceEdit from './SequenceEdit' + +jest.mock('react-router-dom', () => ({ + useParams: jest.fn(), +})) + +jest.mock('../../hooks/job-schedules', () => ({ + useJobScheduleById: jest.fn(), +})) + +describe('', () => { + it('renders a spinner when loading the requested job', () => { + const id = 'id' + + useParams.mockImplementation(() => id) + useJobScheduleById.mockImplementation(() => ({ fetching: true })) + + const wrapper = shallow() + const spinner = wrapper.find('Spinner') + + expect(spinner).toHaveLength(1) + }) + + it('renders errors encountered during fetching', () => { + const id = 'id' + + useParams.mockImplementation(() => id) + useJobScheduleById.mockImplementation(() => ({ + fetching: false, + error: new Error('Something went wrong'), + })) + + const wrapper = shallow() + const noticebox = wrapper.find('NoticeBox') + + expect(noticebox).toHaveLength(1) + }) + + it('renders without errors when loading has completed', () => { + const id = 'id' + + useParams.mockImplementation(() => id) + useJobScheduleById.mockImplementation(() => ({ + fetching: false, + error: undefined, + data: { + name: '', + cronExpression: '', + sequence: [], + }, + })) + + const wrapper = shallow() + const jobform = wrapper.find('SequenceEditFormContainer') + + expect(jobform).toHaveLength(1) + }) +})