Skip to content

Commit bc85fee

Browse files
committed
updated tests for P* cases
1 parent ed01ecf commit bc85fee

File tree

9 files changed

+533
-722
lines changed

9 files changed

+533
-722
lines changed

app/src/__testing-utils__/matchers.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,5 @@ export const nestedTextMatcher = (textMatch: string | RegExp): Matcher => (
2121
return nodeHasText && childrenDontHaveText
2222
}
2323

24-
export const partialComponentPropsMatcher = (argsToMatch: unknown): any =>
25-
// @ts-expect-error(sa, 2021-08-03): when.allArgs not part of type definition yet for jest-when
26-
when.allArgs((args, equals) =>
27-
equals(args[0], expect.objectContaining(argsToMatch))
28-
)
24+
// need componentPropsMatcher
25+
// need partialComponentPropsMatcher

app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx

+39-61
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import * as React from 'react'
22
import { fireEvent, screen } from '@testing-library/react'
3-
import { when, resetAllWhenMocks } from 'jest-when'
3+
import { when } from 'vitest-when'
4+
import { describe, it, beforeEach, vi, afterEach } from 'vitest'
45

5-
import {
6-
DeckConfigurator,
7-
partialComponentPropsMatcher,
8-
renderWithProviders,
9-
} from '@opentrons/components'
6+
import { DeckConfigurator } from '@opentrons/components'
107
import {
118
useDeckConfigurationQuery,
129
useUpdateDeckConfigurationMutation,
1310
} from '@opentrons/react-api-client'
1411

12+
import {
13+
partialComponentPropsMatcher,
14+
renderWithProviders,
15+
} from '../../../__testing-utils__'
1516
import { i18n } from '../../../i18n'
1617
import { useIsRobotViewable, useRunStatuses } from '../../Devices/hooks'
1718
import { DeckFixtureSetupInstructionsModal } from '../DeckFixtureSetupInstructionsModal'
@@ -21,15 +22,15 @@ import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_r
2122

2223
import type { MaintenanceRun } from '@opentrons/api-client'
2324

24-
jest.mock('@opentrons/components/src/hardware-sim/DeckConfigurator/index')
25-
jest.mock('@opentrons/react-api-client')
26-
jest.mock('../DeckFixtureSetupInstructionsModal')
27-
jest.mock('../../Devices/hooks')
28-
jest.mock('../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun')
29-
jest.mock('../../../resources/devices/hooks/useIsEstopNotDisengaged')
25+
vi.mock('@opentrons/components/src/hardware-sim/DeckConfigurator/index')
26+
vi.mock('@opentrons/react-api-client')
27+
vi.mock('../DeckFixtureSetupInstructionsModal')
28+
vi.mock('../../Devices/hooks')
29+
vi.mock('../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun')
30+
vi.mock('../../../resources/devices/hooks/useIsEstopNotDisengaged')
3031

3132
const ROBOT_NAME = 'otie'
32-
const mockUpdateDeckConfiguration = jest.fn()
33+
const mockUpdateDeckConfiguration = vi.fn()
3334
const RUN_STATUSES = {
3435
isRunRunning: false,
3536
isRunStill: false,
@@ -40,31 +41,6 @@ const mockCurrnetMaintenanceRun = {
4041
data: { id: 'mockMaintenanceRunId' },
4142
} as MaintenanceRun
4243

43-
const mockUseDeckConfigurationQuery = useDeckConfigurationQuery as jest.MockedFunction<
44-
typeof useDeckConfigurationQuery
45-
>
46-
const mockUseUpdateDeckConfigurationMutation = useUpdateDeckConfigurationMutation as jest.MockedFunction<
47-
typeof useUpdateDeckConfigurationMutation
48-
>
49-
const mockDeckFixtureSetupInstructionsModal = DeckFixtureSetupInstructionsModal as jest.MockedFunction<
50-
typeof DeckFixtureSetupInstructionsModal
51-
>
52-
const mockDeckConfigurator = DeckConfigurator as jest.MockedFunction<
53-
typeof DeckConfigurator
54-
>
55-
const mockUseRunStatuses = useRunStatuses as jest.MockedFunction<
56-
typeof useRunStatuses
57-
>
58-
const mockUseNotifyCurrentMaintenanceRun = useNotifyCurrentMaintenanceRun as jest.MockedFunction<
59-
typeof useNotifyCurrentMaintenanceRun
60-
>
61-
const mockUseIsEstopNotDisengaged = useIsEstopNotDisengaged as jest.MockedFunction<
62-
typeof useIsEstopNotDisengaged
63-
>
64-
const mockUseIsRobotViewable = useIsRobotViewable as jest.MockedFunction<
65-
typeof useIsRobotViewable
66-
>
67-
6844
const render = (
6945
props: React.ComponentProps<typeof DeviceDetailsDeckConfiguration>
7046
) => {
@@ -80,26 +56,28 @@ describe('DeviceDetailsDeckConfiguration', () => {
8056
props = {
8157
robotName: ROBOT_NAME,
8258
}
83-
mockUseDeckConfigurationQuery.mockReturnValue({ data: [] } as any)
84-
mockUseUpdateDeckConfigurationMutation.mockReturnValue({
59+
vi.mocked(useDeckConfigurationQuery).mockReturnValue({ data: [] } as any)
60+
vi.mocked(useUpdateDeckConfigurationMutation).mockReturnValue({
8561
updateDeckConfiguration: mockUpdateDeckConfiguration,
8662
} as any)
87-
mockDeckFixtureSetupInstructionsModal.mockReturnValue(
63+
vi.mocked(DeckFixtureSetupInstructionsModal).mockReturnValue(
8864
<div>mock DeckFixtureSetupInstructionsModal</div>
8965
)
90-
when(mockDeckConfigurator).mockReturnValue(<div>mock DeckConfigurator</div>)
91-
mockUseRunStatuses.mockReturnValue(RUN_STATUSES)
92-
mockUseNotifyCurrentMaintenanceRun.mockReturnValue({
66+
when(vi.mocked(DeckConfigurator)).thenReturn(
67+
<div>mock DeckConfigurator</div>
68+
)
69+
vi.mocked(useRunStatuses).mockReturnValue(RUN_STATUSES)
70+
vi.mocked(useNotifyCurrentMaintenanceRun).mockReturnValue({
9371
data: {},
9472
} as any)
95-
when(mockUseIsEstopNotDisengaged)
73+
when(vi.mocked(useIsEstopNotDisengaged))
9674
.calledWith(ROBOT_NAME)
97-
.mockReturnValue(false)
98-
when(mockUseIsRobotViewable).calledWith(ROBOT_NAME).mockReturnValue(true)
75+
.thenReturn(false)
76+
when(vi.mocked(useIsRobotViewable)).calledWith(ROBOT_NAME).thenReturn(true)
9977
})
10078

10179
afterEach(() => {
102-
resetAllWhenMocks()
80+
vi.resetAllMocks()
10381
})
10482

10583
it('should render text and button', () => {
@@ -119,10 +97,10 @@ describe('DeviceDetailsDeckConfiguration', () => {
11997

12098
it('should render banner and make deck configurator disabled when running', () => {
12199
RUN_STATUSES.isRunRunning = true
122-
mockUseRunStatuses.mockReturnValue(RUN_STATUSES)
123-
when(mockDeckConfigurator)
100+
vi.mocked(useRunStatuses).mockReturnValue(RUN_STATUSES)
101+
when(vi.mocked(DeckConfigurator))
124102
.calledWith(partialComponentPropsMatcher({ readOnly: true }))
125-
.mockReturnValue(<div>disabled mock DeckConfigurator</div>)
103+
.thenReturn(<div>disabled mock DeckConfigurator</div>)
126104
render(props)
127105
screen.getByText(
128106
'Deck configuration is not available when run is in progress'
@@ -131,12 +109,12 @@ describe('DeviceDetailsDeckConfiguration', () => {
131109
})
132110

133111
it('should render banner and make deck configurator disabled when a maintenance run exists', () => {
134-
mockUseNotifyCurrentMaintenanceRun.mockReturnValue({
112+
vi.mocked(useNotifyCurrentMaintenanceRun).mockReturnValue({
135113
data: mockCurrnetMaintenanceRun,
136114
} as any)
137-
when(mockDeckConfigurator)
115+
when(vi.mocked(DeckConfigurator))
138116
.calledWith(partialComponentPropsMatcher({ readOnly: true }))
139-
.mockReturnValue(<div>disabled mock DeckConfigurator</div>)
117+
.thenReturn(<div>disabled mock DeckConfigurator</div>)
140118
render(props)
141119
screen.getByText(
142120
'Deck configuration is not available when the robot is busy'
@@ -145,26 +123,26 @@ describe('DeviceDetailsDeckConfiguration', () => {
145123
})
146124

147125
it('should render no deck fixtures, if deck configs are not set', () => {
148-
when(mockUseDeckConfigurationQuery)
126+
when(vi.mocked(useDeckConfigurationQuery))
149127
.calledWith()
150-
.mockReturnValue([] as any)
128+
.thenReturn([] as any)
151129
render(props)
152130
screen.getByText('No deck fixtures')
153131
})
154132

155133
it('should render disabled deck configurator when e-stop is pressed', () => {
156-
when(mockUseIsEstopNotDisengaged)
134+
when(vi.mocked(useIsEstopNotDisengaged))
157135
.calledWith(ROBOT_NAME)
158-
.mockReturnValue(true)
159-
when(mockDeckConfigurator)
136+
.thenReturn(true)
137+
when(vi.mocked(DeckConfigurator))
160138
.calledWith(partialComponentPropsMatcher({ readOnly: true }))
161-
.mockReturnValue(<div>disabled mock DeckConfigurator</div>)
139+
.thenReturn(<div>disabled mock DeckConfigurator</div>)
162140
render(props)
163141
screen.getByText('disabled mock DeckConfigurator')
164142
})
165143

166144
it('should render not viewable text when robot is not viewable', () => {
167-
when(mockUseIsRobotViewable).calledWith(ROBOT_NAME).mockReturnValue(false)
145+
when(vi.mocked(useIsRobotViewable)).calledWith(ROBOT_NAME).thenReturn(false)
168146
render(props)
169147
screen.getByText('Robot must be on the network to see deck configuration')
170148
})

0 commit comments

Comments
 (0)