Skip to content

Commit

Permalink
refactor: rely on cypress for jobswitch test
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Nov 29, 2023
1 parent 9f5fe2a commit 0796094
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 72 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"stylelint": "^13.13.1",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^22.0.0",
"stylelint-no-unsupported-browser-features": "^5.0.1",
"wait-for-expect": "^3.0.2"
"stylelint-no-unsupported-browser-features": "^5.0.1"
},
"jest": {
"setupFilesAfterEnv": [
Expand Down
66 changes: 1 addition & 65 deletions src/components/Switches/JobSwitch.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react'
import waitForExpect from 'wait-for-expect'
import { shallow, mount } from 'enzyme'
import { CustomDataProvider } from '@dhis2/app-runtime'
import { shallow } from 'enzyme'
import JobSwitch from './JobSwitch'

describe('<JobSwitch>', () => {
Expand All @@ -15,66 +13,4 @@ describe('<JobSwitch>', () => {
/>
)
})

it('enables an inactive job and refetches when toggle is clicked', async () => {
const answerSpy = jest.fn(() => 'response')
const refetchSpy = jest.fn(() => Promise.resolve())

const props = {
id: 'id',
checked: false,
disabled: false,
refetch: refetchSpy,
}
const data = { 'jobConfigurations/id/enable': answerSpy }
const wrapper = mount(<JobSwitch {...props} />, {
wrappingComponent: CustomDataProvider,
wrappingComponentProps: { data },
})

wrapper
.find('input')
.find({ name: 'toggle-job-id' })
.simulate('change', { target: { checked: !props.checked } })

await waitForExpect(() => {
expect(answerSpy).toHaveBeenCalledWith(
'create',
expect.anything(),
expect.anything()
)
expect(refetchSpy).toHaveBeenCalled()
})
})

it('disables an active job and refetches when toggle is clicked', async () => {
const answerSpy = jest.fn(() => 'response')
const refetchSpy = jest.fn(() => Promise.resolve())

const props = {
id: 'id',
checked: true,
disabled: false,
refetch: refetchSpy,
}
const data = { 'jobConfigurations/id/disable': answerSpy }
const wrapper = mount(<JobSwitch {...props} />, {
wrappingComponent: CustomDataProvider,
wrappingComponentProps: { data },
})

wrapper
.find('input')
.find({ name: 'toggle-job-id' })
.simulate('change', { target: { checked: !props.checked } })

await waitForExpect(() => {
expect(answerSpy).toHaveBeenCalledWith(
'create',
expect.anything(),
expect.anything()
)
expect(refetchSpy).toHaveBeenCalled()
})
})
})
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16147,11 +16147,6 @@ w3c-xmlserializer@^2.0.0:
dependencies:
xml-name-validator "^3.0.0"

wait-for-expect@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/wait-for-expect/-/wait-for-expect-3.0.2.tgz#d2f14b2f7b778c9b82144109c8fa89ceaadaa463"
integrity sha512-cfS1+DZxuav1aBYbaO/kE06EOS8yRw7qOFoD3XtjTkYvCvh3zUvNST8DXK/nPaeqIzIv3P3kL3lRJn8iwOiSag==

[email protected]:
version "5.3.0"
resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-5.3.0.tgz#584e17d4b3fe7b46ac2b9f8e5e102c005c2776c7"
Expand Down

0 comments on commit 0796094

Please sign in to comment.