Skip to content

Commit 02b3a39

Browse files
committed
the rest test case phase 1
1 parent 6ca27b4 commit 02b3a39

6 files changed

+71
-77
lines changed

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

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react'
22
import { fireEvent, screen } from '@testing-library/react'
3-
import { renderWithProviders } from '@opentrons/components'
3+
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'
4+
45
import {
56
useDeckConfigurationQuery,
67
useUpdateDeckConfigurationMutation,
@@ -10,23 +11,17 @@ import {
1011
WASTE_CHUTE_FIXTURES,
1112
} from '@opentrons/shared-data'
1213

14+
import { renderWithProviders } from '../../../__testing-utils__'
1315
import { i18n } from '../../../i18n'
1416
import { AddFixtureModal } from '../AddFixtureModal'
1517

1618
import type { UseQueryResult } from 'react-query'
1719
import type { DeckConfiguration } from '@opentrons/shared-data'
1820

19-
jest.mock('@opentrons/react-api-client')
20-
const mockSetShowAddFixtureModal = jest.fn()
21-
const mockUpdateDeckConfiguration = jest.fn()
22-
const mockSetCurrentDeckConfig = jest.fn()
23-
24-
const mockUseUpdateDeckConfigurationMutation = useUpdateDeckConfigurationMutation as jest.MockedFunction<
25-
typeof useUpdateDeckConfigurationMutation
26-
>
27-
const mockUseDeckConfigurationQuery = useDeckConfigurationQuery as jest.MockedFunction<
28-
typeof useDeckConfigurationQuery
29-
>
21+
vi.mock('@opentrons/react-api-client')
22+
const mockSetShowAddFixtureModal = vi.fn()
23+
const mockUpdateDeckConfiguration = vi.fn()
24+
const mockSetCurrentDeckConfig = vi.fn()
3025

3126
const render = (props: React.ComponentProps<typeof AddFixtureModal>) => {
3227
return renderWithProviders(<AddFixtureModal {...props} />, {
@@ -44,10 +39,10 @@ describe('Touchscreen AddFixtureModal', () => {
4439
setCurrentDeckConfig: mockSetCurrentDeckConfig,
4540
isOnDevice: true,
4641
}
47-
mockUseUpdateDeckConfigurationMutation.mockReturnValue({
42+
vi.mocked(useUpdateDeckConfigurationMutation).mockReturnValue({
4843
updateDeckConfiguration: mockUpdateDeckConfiguration,
4944
} as any)
50-
mockUseDeckConfigurationQuery.mockReturnValue(({
45+
vi.mocked(useDeckConfigurationQuery).mockReturnValue(({
5146
data: [],
5247
} as unknown) as UseQueryResult<DeckConfiguration>)
5348
})
@@ -97,13 +92,13 @@ describe('Desktop AddFixtureModal', () => {
9792
cutoutId: 'cutoutD3',
9893
setShowAddFixtureModal: mockSetShowAddFixtureModal,
9994
}
100-
mockUseUpdateDeckConfigurationMutation.mockReturnValue({
95+
vi.mocked(useUpdateDeckConfigurationMutation).mockReturnValue({
10196
updateDeckConfiguration: mockUpdateDeckConfiguration,
10297
} as any)
10398
})
10499

105100
afterEach(() => {
106-
jest.clearAllMocks()
101+
vi.clearAllMocks()
107102
})
108103

109104
it('should render text and buttons slot D3', () => {

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as React from 'react'
22
import { fireEvent, screen } from '@testing-library/react'
3-
import { renderWithProviders } from '@opentrons/components'
3+
import { describe, it, beforeEach, vi, expect } from 'vitest'
44

5+
import { renderWithProviders } from '../../../__testing-utils__'
56
import { i18n } from '../../../i18n'
67
import { DeckConfigurationDiscardChangesModal } from '../DeckConfigurationDiscardChangesModal'
78

8-
const mockFunc = jest.fn()
9-
const mockGoBack = jest.fn()
9+
const mockFunc = vi.fn()
10+
const mockGoBack = vi.fn()
1011

11-
jest.mock('react-router-dom', () => {
12-
const reactRouterDom = jest.requireActual('react-router-dom')
12+
vi.mock('react-router-dom', () => {
13+
const reactRouterDom = vi.requireActual('react-router-dom')
1314
return {
1415
...reactRouterDom,
1516
useHistory: () => ({ goBack: mockGoBack } as any),
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as React from 'react'
2+
import { fireEvent, screen } from '@testing-library/react'
3+
import { describe, it, beforeEach, vi, expect } from 'vitest'
24

3-
import { renderWithProviders } from '@opentrons/components'
4-
5+
import { renderWithProviders } from '../../../__testing-utils__'
56
import { i18n } from '../../../i18n'
6-
77
import { DeckFixtureSetupInstructionsModal } from '../DeckFixtureSetupInstructionsModal'
8-
import { fireEvent } from '@testing-library/react'
98

10-
const mockFunc = jest.fn()
11-
const PNG_FILE_NAME = 'deck_fixture_setup_qrcode.png'
9+
const mockFunc = vi.fn()
10+
const PNG_FILE_NAME =
11+
'/app/src/assets/images/on-device-display/deck_fixture_setup_qrcode.png'
1212

1313
const render = (
1414
props: React.ComponentProps<typeof DeckFixtureSetupInstructionsModal>
@@ -29,21 +29,21 @@ describe('Touchscreen DeckFixtureSetupInstructionsModal', () => {
2929
})
3030

3131
it('should render text and image', () => {
32-
const [{ getByText, getByRole }] = render(props)
33-
getByText('Deck fixture setup instructions')
34-
getByText(
32+
render(props)
33+
screen.getByText('Deck fixture setup instructions')
34+
screen.getByText(
3535
"First, unscrew and remove the deck slot where you'll install a fixture. Then put the fixture in place and attach it as needed."
3636
)
37-
getByText(
37+
screen.getByText(
3838
'For details on installing different fixture types, scan the QR code or search for “deck configuration” on support.opentrons.com'
3939
)
40-
const img = getByRole('img')
40+
const img = screen.getByRole('img')
4141
expect(img.getAttribute('src')).toEqual(PNG_FILE_NAME)
4242
})
4343

4444
it('should call a mock function when tapping the close icon', () => {
45-
const [{ getByLabelText }] = render(props)
46-
fireEvent.click(getByLabelText('closeIcon'))
45+
render(props)
46+
fireEvent.click(screen.getByLabelText('closeIcon'))
4747
expect(mockFunc).toHaveBeenCalled()
4848
})
4949
})
@@ -58,19 +58,21 @@ describe('Desktop DeckFixtureSetupInstructionsModal', () => {
5858
})
5959

6060
it('should render text, image, and button', () => {
61-
const [{ getAllByText, getByText, getByRole, queryByText }] = render(props)
62-
expect(getAllByText('Deck fixture setup instructions').length).toBe(2)
63-
getByText(
61+
render(props)
62+
expect(screen.getAllByText('Deck fixture setup instructions').length).toBe(
63+
2
64+
)
65+
screen.getByText(
6466
"First, unscrew and remove the deck slot where you'll install a fixture. Then put the fixture in place and attach it as needed."
6567
)
66-
getByText(
68+
screen.getByText(
6769
'For detailed instructions for different types of fixtures, scan the QR code or go to the link below.'
6870
)
69-
const img = getByRole('img')
71+
const img = screen.getByRole('img')
7072
expect(img.getAttribute('src')).toEqual(PNG_FILE_NAME)
7173
expect(
72-
queryByText('www.opentrons.com/support/fixtures')
74+
screen.queryByText('www.opentrons.com/support/fixtures')
7375
).not.toBeInTheDocument()
74-
getByRole('button', { name: 'Close' })
76+
screen.getByRole('button', { name: 'Close' })
7577
})
7678
})
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
import * as React from 'react'
2-
import { fireEvent } from '@testing-library/react'
3-
import { when, resetAllWhenMocks } from 'jest-when'
2+
import { fireEvent, screen } from '@testing-library/react'
3+
import { when } from 'vitest-when'
44
import { StaticRouter } from 'react-router-dom'
5+
import { describe, it, beforeEach, vi, afterEach, expect } from 'vitest'
56

6-
import { renderWithProviders } from '@opentrons/components'
7-
7+
import { renderWithProviders } from '../../../../__testing-utils__'
88
import { i18n } from '../../../../i18n'
99
import {
1010
useTrackEvent,
1111
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
1212
} from '../../../../redux/analytics'
1313
import { BackToTopButton } from '../BackToTopButton'
1414

15-
jest.mock('@opentrons/components', () => {
16-
const actualComponents = jest.requireActual('@opentrons/components')
17-
return {
18-
...actualComponents,
19-
Tooltip: jest.fn(({ children }) => <div>{children}</div>),
20-
}
21-
})
22-
jest.mock('../../../../redux/analytics')
15+
import type { Mock } from 'vitest'
2316

24-
const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
25-
typeof useTrackEvent
26-
>
17+
vi.mock('../../../../redux/analytics')
2718

2819
const ROBOT_NAME = 'otie'
2920
const RUN_ID = '1'
@@ -44,15 +35,15 @@ const render = () => {
4435
)[0]
4536
}
4637

47-
let mockTrackEvent: jest.Mock
38+
let mockTrackEvent: Mock
4839

4940
describe('BackToTopButton', () => {
5041
beforeEach(() => {
51-
mockTrackEvent = jest.fn()
52-
when(mockUseTrackEvent).calledWith().mockReturnValue(mockTrackEvent)
42+
mockTrackEvent = vi.fn()
43+
when(vi.mocked(useTrackEvent)).calledWith().thenReturn(mockTrackEvent)
5344
})
5445
afterEach(() => {
55-
resetAllWhenMocks()
46+
vi.clearAllMocks()
5647
})
5748

5849
it('should be enabled with no tooltip if there are no missing Ids', () => {
@@ -65,8 +56,8 @@ describe('BackToTopButton', () => {
6556
})
6657

6758
it('should track a mixpanel event when clicked', () => {
68-
const { getByRole } = render()
69-
const button = getByRole('link', { name: 'Back to top' })
59+
render()
60+
const button = screen.getByRole('link', { name: 'Back to top' })
7061
fireEvent.click(button)
7162
expect(mockTrackEvent).toHaveBeenCalledWith({
7263
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
@@ -75,8 +66,8 @@ describe('BackToTopButton', () => {
7566
})
7667

7768
it('should always be enabled', () => {
78-
const { getByRole } = render()
79-
const button = getByRole('button', { name: 'Back to top' })
69+
render()
70+
const button = screen.getByRole('button', { name: 'Back to top' })
8071
expect(button).not.toBeDisabled()
8172
})
8273
})

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react'
2-
import { renderWithProviders } from '@opentrons/components'
2+
import { describe, it, beforeEach } from 'vitest'
3+
import { screen } from '@testing-library/react'
4+
5+
import { renderWithProviders } from '../../../../__testing-utils__'
36
import { i18n } from '../../../../i18n'
47
import { EmptySetupStep } from '../EmptySetupStep'
58

@@ -20,9 +23,9 @@ describe('EmptySetupStep', () => {
2023
})
2124

2225
it('should render the title, description, and label', () => {
23-
const { getByText } = render(props)
24-
getByText('mockTitle')
25-
getByText('mockDescription')
26-
getByText('mockLabel')
26+
render(props)
27+
screen.getByText('mockTitle')
28+
screen.getByText('mockDescription')
29+
screen.getByText('mockLabel')
2730
})
2831
})

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from 'react'
2-
import { fireEvent } from '@testing-library/react'
3-
import { renderWithProviders } from '@opentrons/components'
2+
import { fireEvent, screen } from '@testing-library/react'
3+
import { describe, it, beforeEach } from 'vitest'
4+
5+
import { renderWithProviders } from '../../../../__testing-utils__'
46
import { i18n } from '../../../../i18n'
57
import { ProtocolAnalysisErrorBanner } from '../ProtocolAnalysisErrorBanner'
68

@@ -28,14 +30,14 @@ describe('ProtocolAnalysisErrorBanner', () => {
2830
}
2931
})
3032
it('renders error banner and show error link', () => {
31-
const { getByText, getByLabelText } = render(props)
32-
getByText('Protocol analysis failed.')
33-
getByLabelText('error_link')
33+
render(props)
34+
screen.getByText('Protocol analysis failed.')
35+
screen.getByLabelText('error_link')
3436
})
3537
it('renders error details modal when error link clicked', () => {
36-
const { getByText, getByLabelText } = render(props)
37-
const btn = getByLabelText('error_link')
38+
render(props)
39+
const btn = screen.getByLabelText('error_link')
3840
fireEvent.click(btn)
39-
getByText('protocol analysis error')
41+
screen.getByText('protocol analysis error')
4042
})
4143
})

0 commit comments

Comments
 (0)