Skip to content

Commit

Permalink
test: add tests for queue components
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Nov 2, 2023
1 parent 7a20811 commit db75603
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 8 deletions.
21 changes: 21 additions & 0 deletions src/components/JobTable/DeleteQueueAction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import { shallow, mount } from 'enzyme'
import DeleteQueueAction from './DeleteQueueAction'

describe('<DeleteQueueAction>', () => {
it('renders without errors', () => {
shallow(<DeleteQueueAction name="name" onSuccess={() => {}} />)
})

it('shows the modal when MenuItem is clicked', () => {
const wrapper = mount(
<DeleteQueueAction name="name" onSuccess={() => {}} />
)

expect(wrapper.find('DeleteQueueModal')).toHaveLength(0)

wrapper.find('a').simulate('click')

expect(wrapper.find('DeleteQueueModal')).toHaveLength(1)
})
})
22 changes: 22 additions & 0 deletions src/components/JobTable/EditQueueAction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import { shallow, mount } from 'enzyme'
import history from '../../services/history'
import EditQueueAction from './EditQueueAction'

jest.mock('../../services/history', () => ({
push: jest.fn(),
}))

describe('<EditQueueAction>', () => {
it('renders without errors', () => {
shallow(<EditQueueAction name="name" />)
})

it('calls history.push correctly when MenuItem is clicked', () => {
const wrapper = mount(<EditQueueAction name="name" />)

wrapper.find('a').simulate('click')

expect(history.push).toHaveBeenCalledWith('/queue/name')
})
})
9 changes: 9 additions & 0 deletions src/components/JobTable/QueueActions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import { shallow } from 'enzyme'
import QueueActions from './QueueActions'

describe('<QueueActions>', () => {
it('renders without errors', () => {
shallow(<QueueActions name="1" refetch={() => {}} />)
})
})
7 changes: 2 additions & 5 deletions src/components/JobTable/QueueTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const QueueTableRow = ({
id,
name,
cronExpression,
delay,
status,
nextExecutionTime,
enabled,
Expand Down Expand Up @@ -47,7 +46,7 @@ const QueueTableRow = ({
<TableCell role="rowheader">{name}</TableCell>
<TableCell>{i18n.t('Queue')}</TableCell>
<TableCell>
<Schedule cronExpression={cronExpression} delay={delay} />
<Schedule cronExpression={cronExpression} />
</TableCell>
<TableCell>
<NextRun
Expand Down Expand Up @@ -79,17 +78,15 @@ const QueueTableRow = ({
)
}

const { shape, string, bool, number, func, arrayOf, object } = PropTypes
const { shape, string, bool, func, arrayOf, object } = PropTypes

QueueTableRow.propTypes = {
queue: shape({
name: string.isRequired,
enabled: bool.isRequired,
id: string.isRequired,
status: string.isRequired,
type: string.isRequired,
cronExpression: string,
delay: number,
nextExecutionTime: string,
sequence: arrayOf(object).isRequired,
}).isRequired,
Expand Down
29 changes: 29 additions & 0 deletions src/components/JobTable/QueueTableRow.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'
import { shallow } from 'enzyme'
import QueueTableRow from './QueueTableRow'

describe('<QueueTableRow>', () => {
it('renders queues without errors', () => {
const queue = {
id: 'lnWRZN67iDU',
name: 'Queue 1',
cronExpression: '0 0 3 ? * MON',
nextExecutionTime: '2021-03-01T03:00:00.000',
status: 'SCHEDULED',
enabled: true,
configurable: true,
sequence: [
{
id: 'lnWRZN67iDU',
name: 'Job 1',
type: 'DATA_INTEGRITY',
cronExpression: '0 0 3 ? * MON',
nextExecutionTime: '2021-03-01T03:00:00.000',
status: 'SCHEDULED',
},
],
}

shallow(<QueueTableRow queue={queue} refetch={() => {}} />)
})
})
6 changes: 3 additions & 3 deletions src/hooks/jobs-and-queues/use-jobs-and-queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const useJobsAndQueues = () => {
return { ...fetch, error, data: undefined }
}

const data = jobsAndQueues.map((schedule) => {
const id = schedule.sequence?.[0]?.id
return { ...schedule, id }
const data = jobsAndQueues.map((jobOrQueue) => {
const id = jobOrQueue.sequence?.[0]?.id
return { ...jobOrQueue, id }
})

return { ...fetch, data }
Expand Down

0 comments on commit db75603

Please sign in to comment.