Skip to content

Commit 881ab8c

Browse files
committed
the third phase of the rest of tests
1 parent 7a03259 commit 881ab8c

5 files changed

+112
-147
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import * as React from 'react'
2-
import { when, resetAllWhenMocks } from 'jest-when'
2+
import { when } from 'vitest-when'
33
import { MemoryRouter } from 'react-router-dom'
4+
import { describe, it, beforeEach, afterEach, vi, expect } from 'vitest'
5+
import { screen } from '@testing-library/react'
46

5-
import { renderWithProviders } from '@opentrons/components'
6-
7+
import { renderWithProviders } from '../../../../__testing-utils__'
78
import { i18n } from '../../../../i18n'
89
import { mockDeckCalData } from '../../../../redux/calibration/__fixtures__'
910
import { useDeckCalibrationData } from '../../hooks'
1011
import { SetupDeckCalibration } from '../SetupDeckCalibration'
1112

12-
jest.mock('../../hooks')
13-
14-
const mockUseDeckCalibrationData = useDeckCalibrationData as jest.MockedFunction<
15-
typeof useDeckCalibrationData
16-
>
13+
vi.mock('../../hooks')
1714

1815
const ROBOT_NAME = 'otie'
1916
const RUN_ID = '1'
@@ -31,32 +28,34 @@ const render = () => {
3128

3229
describe('SetupDeckCalibration', () => {
3330
beforeEach(() => {
34-
when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({
31+
when(vi.mocked(useDeckCalibrationData)).calledWith(ROBOT_NAME).thenReturn({
3532
deckCalibrationData: mockDeckCalData,
3633
isDeckCalibrated: true,
3734
})
3835
})
3936
afterEach(() => {
40-
resetAllWhenMocks()
37+
vi.resetAllMocks()
4138
})
4239

4340
it('renders last calibrated content when deck is calibrated', () => {
44-
const { getByText, queryByText } = render()
45-
getByText('Deck Calibration')
46-
queryByText('Last calibrated:')
41+
render()
42+
screen.getByText('Deck Calibration')
43+
screen.queryByText('Last calibrated:')
4744
})
4845
it('renders a link to the calibration dashboard if deck is not calibrated', () => {
49-
when(mockUseDeckCalibrationData).calledWith(ROBOT_NAME).mockReturnValue({
46+
when(vi.mocked(useDeckCalibrationData)).calledWith(ROBOT_NAME).thenReturn({
5047
deckCalibrationData: null,
5148
isDeckCalibrated: false,
5249
})
53-
const { getByRole, getByText } = render()
50+
render()
5451

55-
getByText('Not calibrated yet')
52+
screen.getByText('Not calibrated yet')
5653
expect(
57-
getByRole('link', {
58-
name: 'Calibrate now',
59-
}).getAttribute('href')
54+
screen
55+
.getByRole('link', {
56+
name: 'Calibrate now',
57+
})
58+
.getAttribute('href')
6059
).toBe('/devices/otie/robot-settings/calibration/dashboard')
6160
})
6261
})

app/src/organisms/Devices/ProtocolRun/__tests__/SetupFlexPipetteCalibrationItem.test.tsx

+36-40
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
import * as React from 'react'
2-
import { resetAllWhenMocks } from 'jest-when'
32
import { MemoryRouter } from 'react-router-dom'
4-
import { fireEvent } from '@testing-library/react'
3+
import { fireEvent, screen } from '@testing-library/react'
4+
import { describe, it, beforeEach, vi, afterEach } from 'vitest'
55

6-
import { renderWithProviders } from '@opentrons/components'
76
import { useInstrumentsQuery } from '@opentrons/react-api-client'
87

8+
import { renderWithProviders } from '../../../../__testing-utils__'
99
import { i18n } from '../../../../i18n'
1010
import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis'
1111
import { PipetteWizardFlows } from '../../../PipetteWizardFlows'
1212
import { SetupFlexPipetteCalibrationItem } from '../SetupFlexPipetteCalibrationItem'
1313
import _uncastedModifiedSimpleV6Protocol from '../../hooks/__fixtures__/modifiedSimpleV6.json'
1414
import { CompletedProtocolAnalysis } from '@opentrons/shared-data'
1515

16-
jest.mock('@opentrons/react-api-client')
17-
jest.mock('../../../PipetteWizardFlows')
18-
jest.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis')
19-
jest.mock('../../hooks')
20-
21-
const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction<
22-
typeof useInstrumentsQuery
23-
>
24-
const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction<
25-
typeof useMostRecentCompletedAnalysis
26-
>
27-
const mockPipetteWizardFlows = PipetteWizardFlows as jest.MockedFunction<
28-
typeof PipetteWizardFlows
29-
>
16+
vi.mock('@opentrons/react-api-client')
17+
vi.mock('../../../PipetteWizardFlows')
18+
vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis')
19+
vi.mock('../../hooks')
3020

3121
const RUN_ID = '1'
3222
const modifiedSimpleV6Protocol = ({
@@ -60,34 +50,39 @@ describe('SetupFlexPipetteCalibrationItem', () => {
6050
}
6151

6252
beforeEach(() => {
63-
mockPipetteWizardFlows.mockReturnValue(<div>pipette wizard flows</div>)
64-
mockUseMostRecentCompletedAnalysis.mockReturnValue(modifiedSimpleV6Protocol)
65-
mockUseInstrumentsQuery.mockReturnValue({
53+
vi.mocked(PipetteWizardFlows).mockReturnValue(
54+
<div>pipette wizard flows</div>
55+
)
56+
vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue(
57+
modifiedSimpleV6Protocol
58+
)
59+
vi.mocked(useInstrumentsQuery).mockReturnValue({
6660
data: {
6761
data: [],
6862
},
6963
} as any)
7064
})
7165
afterEach(() => {
72-
resetAllWhenMocks()
66+
vi.clearAllMocks()
7367
})
7468

7569
it('renders the mount and pipette name', () => {
76-
const { getByText } = render()
77-
getByText('Left Mount')
78-
getByText('P10 Single-Channel GEN1')
70+
render()
71+
screen.getByText('Left Mount')
72+
screen.getByText('P10 Single-Channel GEN1')
7973
})
8074

8175
it('renders an attach button if on a Flex and pipette is not attached', () => {
82-
const { getByText, getByRole } = render()
83-
getByText('Left Mount')
84-
getByText('P10 Single-Channel GEN1')
85-
const attach = getByRole('button', { name: 'Attach Pipette' })
76+
render()
77+
screen.getByText('Left Mount')
78+
screen.getByText('P10 Single-Channel GEN1')
79+
const attach = screen.getByRole('button', { name: 'Attach Pipette' })
8680
fireEvent.click(attach)
87-
getByText('pipette wizard flows')
81+
screen.getByText('pipette wizard flows')
8882
})
83+
8984
it('renders a calibrate button if on a Flex and pipette is not calibrated', () => {
90-
mockUseInstrumentsQuery.mockReturnValue({
85+
vi.mocked(useInstrumentsQuery).mockReturnValue({
9186
data: {
9287
data: [
9388
{
@@ -101,15 +96,16 @@ describe('SetupFlexPipetteCalibrationItem', () => {
10196
],
10297
},
10398
} as any)
104-
const { getByText, getByRole } = render()
105-
getByText('Left Mount')
106-
getByText('P10 Single-Channel GEN1')
107-
const attach = getByRole('button', { name: 'Calibrate now' })
99+
render()
100+
screen.getByText('Left Mount')
101+
screen.getByText('P10 Single-Channel GEN1')
102+
const attach = screen.getByRole('button', { name: 'Calibrate now' })
108103
fireEvent.click(attach)
109-
getByText('pipette wizard flows')
104+
screen.getByText('pipette wizard flows')
110105
})
106+
111107
it('renders calibrated text if on a Flex and pipette is calibrated', () => {
112-
mockUseInstrumentsQuery.mockReturnValue({
108+
vi.mocked(useInstrumentsQuery).mockReturnValue({
113109
data: {
114110
data: [
115111
{
@@ -127,9 +123,9 @@ describe('SetupFlexPipetteCalibrationItem', () => {
127123
],
128124
},
129125
} as any)
130-
const { getByText } = render()
131-
getByText('Left Mount')
132-
getByText('P10 Single-Channel GEN1')
133-
getByText('Last calibrated: today')
126+
render()
127+
screen.getByText('Left Mount')
128+
screen.getByText('P10 Single-Channel GEN1')
129+
screen.getByText('Last calibrated: today')
134130
})
135131
})

app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibration.test.tsx

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import * as React from 'react'
2-
import { when, resetAllWhenMocks } from 'jest-when'
3-
4-
import { renderWithProviders } from '@opentrons/components'
2+
import { when } from 'vitest-when'
3+
import { describe, it, beforeEach, vi, afterEach, expect } from 'vitest'
4+
import { screen } from '@testing-library/react'
55

6+
import { renderWithProviders } from '../../../../__testing-utils__'
67
import { i18n } from '../../../../i18n'
78
import { mockTipRackDefinition } from '../../../../redux/custom-labware/__fixtures__'
89
import { useRunPipetteInfoByMount } from '../../hooks'
910
import { SetupPipetteCalibrationItem } from '../SetupPipetteCalibrationItem'
1011
import { SetupInstrumentCalibration } from '../SetupInstrumentCalibration'
1112
import type { PipetteInfo } from '../../hooks'
1213

13-
jest.mock('../../hooks')
14-
jest.mock('../SetupPipetteCalibrationItem')
15-
16-
const mockUseRunPipetteInfoByMount = useRunPipetteInfoByMount as jest.MockedFunction<
17-
typeof useRunPipetteInfoByMount
18-
>
19-
const mockSetupPipetteCalibrationItem = SetupPipetteCalibrationItem as jest.MockedFunction<
20-
typeof SetupPipetteCalibrationItem
21-
>
14+
vi.mock('../../hooks')
15+
vi.mock('../SetupPipetteCalibrationItem')
2216

2317
const ROBOT_NAME = 'otie'
2418
const RUN_ID = '1'
@@ -49,32 +43,36 @@ const render = () => {
4943

5044
describe('SetupPipetteCalibration', () => {
5145
beforeEach(() => {
52-
when(mockUseRunPipetteInfoByMount).calledWith(RUN_ID).mockReturnValue({
46+
when(vi.mocked(useRunPipetteInfoByMount)).calledWith(RUN_ID).thenReturn({
5347
left: PIPETTE_INFO,
5448
right: null,
5549
})
56-
when(mockSetupPipetteCalibrationItem).mockReturnValue(
50+
vi.mocked(SetupPipetteCalibrationItem).mockReturnValue(
5751
<div>Mock SetupPipetteCalibrationItem</div>
5852
)
5953
})
6054
afterEach(() => {
61-
resetAllWhenMocks()
55+
vi.clearAllMocks()
6256
})
6357

6458
it('renders required pipettes title', () => {
65-
const { getByText } = render()
66-
getByText('Required Instrument Calibrations')
59+
render()
60+
screen.getByText('Required Instrument Calibrations')
6761
})
6862
it('renders one SetupPipetteCalibrationItem when protocol run requires one pipette', () => {
69-
const { getAllByText } = render()
70-
expect(getAllByText('Mock SetupPipetteCalibrationItem')).toHaveLength(1)
63+
render()
64+
expect(
65+
screen.getAllByText('Mock SetupPipetteCalibrationItem')
66+
).toHaveLength(1)
7167
})
7268
it('renders two SetupPipetteCalibrationItems when protocol run requires two pipettes', () => {
73-
when(mockUseRunPipetteInfoByMount).calledWith(RUN_ID).mockReturnValue({
69+
when(vi.mocked(useRunPipetteInfoByMount)).calledWith(RUN_ID).thenReturn({
7470
left: PIPETTE_INFO,
7571
right: PIPETTE_INFO,
7672
})
77-
const { getAllByText } = render()
78-
expect(getAllByText('Mock SetupPipetteCalibrationItem')).toHaveLength(2)
73+
render()
74+
expect(
75+
screen.getAllByText('Mock SetupPipetteCalibrationItem')
76+
).toHaveLength(2)
7977
})
8078
})

app/src/organisms/Devices/ProtocolRun/__tests__/SetupPipetteCalibrationItem.test.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as React from 'react'
22
import { when, resetAllWhenMocks } from 'jest-when'
33

4-
import { renderWithProviders } from '@opentrons/components'
5-
4+
import { renderWithProviders } from '../../../../__testing-utils__'}
65
import { i18n } from '../../../../i18n'
76
import { mockDeckCalData } from '../../../../redux/calibration/__fixtures__'
87
import { mockPipetteInfo } from '../../../../redux/pipettes/__fixtures__'

0 commit comments

Comments
 (0)