Skip to content

Commit

Permalink
test: add sequence edit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Jul 27, 2023
1 parent 637724b commit 0d5df1b
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/pages/SequenceEdit/SequenceEdit.test.js
Original file line number Diff line number Diff line change
@@ -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('<SequenceEdit>', () => {
it('renders a spinner when loading the requested job', () => {
const id = 'id'

useParams.mockImplementation(() => id)
useJobScheduleById.mockImplementation(() => ({ fetching: true }))

const wrapper = shallow(<SequenceEdit />)
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(<SequenceEdit />)
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(<SequenceEdit />)
const jobform = wrapper.find('SequenceEditFormContainer')

expect(jobform).toHaveLength(1)
})
})

0 comments on commit 0d5df1b

Please sign in to comment.