Skip to content

Commit

Permalink
more vitest migrations for organisms D -> I
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 27, 2024
1 parent 61c6a85 commit 0644c03
Show file tree
Hide file tree
Showing 28 changed files with 530 additions and 617 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import NiceModal from '@ebay/nice-modal-react'
import { fireEvent } from '@testing-library/react'
import { describe, it, beforeEach, expect, vi } from 'vitest'
import { fireEvent, screen } from '@testing-library/react'

import { renderWithProviders } from '@opentrons/components'
import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'

import { handleTipsAttachedModal } from '../TipsAttachedModal'
Expand All @@ -13,7 +14,7 @@ import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_r

import type { PipetteModelSpecs } from '@opentrons/shared-data'

jest.mock('../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun')
vi.mock('../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun')

const MOCK_ACTUAL_PIPETTE = {
...mockPipetteInfo.pipetteSpecs,
Expand All @@ -23,10 +24,7 @@ const MOCK_ACTUAL_PIPETTE = {
},
} as PipetteModelSpecs

const mockOnClose = jest.fn()
const mockUseNotifyCurrentMaintenanceRun = useNotifyCurrentMaintenanceRun as jest.MockedFunction<
typeof useNotifyCurrentMaintenanceRun
>
const mockOnClose = vi.fn()

const render = (pipetteSpecs: PipetteModelSpecs) => {
return renderWithProviders(
Expand All @@ -51,7 +49,7 @@ const render = (pipetteSpecs: PipetteModelSpecs) => {

describe('TipsAttachedModal', () => {
beforeEach(() => {
mockUseNotifyCurrentMaintenanceRun.mockReturnValue({
vi.mocked(useNotifyCurrentMaintenanceRun).mockReturnValue({
data: {
data: {
id: 'test',
Expand All @@ -60,50 +58,44 @@ describe('TipsAttachedModal', () => {
} as any)
})

afterEach(() => {
jest.resetAllMocks()
})

it('renders appropriate warning given the pipette mount', () => {
const [{ getByTestId, getByText, queryByText }] = render(
MOCK_ACTUAL_PIPETTE
)
const btn = getByTestId('testButton')
render(MOCK_ACTUAL_PIPETTE)
const btn = screen.getByTestId('testButton')
fireEvent.click(btn)

getByText('Tips are attached')
queryByText(`${LEFT} Pipette`)
screen.getByText('Tips are attached')
screen.queryByText(`${LEFT} Pipette`)
})
it('clicking the close button properly closes the modal', () => {
const [{ getByTestId, getByText }] = render(MOCK_ACTUAL_PIPETTE)
const btn = getByTestId('testButton')
render(MOCK_ACTUAL_PIPETTE)
const btn = screen.getByTestId('testButton')
fireEvent.click(btn)

const skipBtn = getByText('Skip')
const skipBtn = screen.getByText('Skip')
fireEvent.click(skipBtn)
expect(mockOnClose).toHaveBeenCalled()
})
it('clicking the launch wizard button properly launches the wizard', () => {
const [{ getByTestId, getByText }] = render(MOCK_ACTUAL_PIPETTE)
const btn = getByTestId('testButton')
render(MOCK_ACTUAL_PIPETTE)
const btn = screen.getByTestId('testButton')
fireEvent.click(btn)

const skipBtn = getByText('Begin removal')
const skipBtn = screen.getByText('Begin removal')
fireEvent.click(skipBtn)
getByText('Drop tips')
screen.queryByText('Drop tips')
})
it('renders special text when the pipette is a 96-Channel', () => {
const ninetySixSpecs = {
...MOCK_ACTUAL_PIPETTE,
channels: 96,
} as PipetteModelSpecs

const [{ getByTestId, queryByText, getByText }] = render(ninetySixSpecs)
const btn = getByTestId('testButton')
render(ninetySixSpecs)
const btn = screen.getByTestId('testButton')
fireEvent.click(btn)

const skipBtn = getByText('Begin removal')
const skipBtn = screen.getByText('Begin removal')
fireEvent.click(skipBtn)
queryByText('96-Channel')
screen.queryByText('96-Channel')
})
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { describe, it, beforeEach, expect, vi } from 'vitest'
import { getCommands } from '@opentrons/api-client'

import { getPipettesWithTipAttached } from '../getPipettesWithTipAttached'
import { LEFT, RIGHT } from '@opentrons/shared-data'

import type { GetPipettesWithTipAttached } from '../getPipettesWithTipAttached'

jest.mock('@opentrons/api-client')

const mockGetCommands = getCommands as jest.MockedFunction<typeof getCommands>
vi.mock('@opentrons/api-client')

const mockAttachedInstruments = {
data: [
Expand Down Expand Up @@ -154,7 +153,7 @@ describe('getPipettesWithTipAttached', () => {
runRecord: mockRunRecord as any,
}

mockGetCommands.mockResolvedValue({
vi.mocked(getCommands).mockResolvedValue({
data: mockCommands,
} as any)
})
Expand Down
116 changes: 0 additions & 116 deletions app/src/organisms/EmergencyStop/__tests__/EsoptPressedModal.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import * as React from 'react'
import { fireEvent } from '@testing-library/react'

import { renderWithProviders } from '@opentrons/components'
import { fireEvent, screen } from '@testing-library/react'
import '@testing-library/jest-dom/vitest'
import { describe, it, vi, beforeEach, expect } from 'vitest'
import { renderWithProviders } from '../../../__testing-utils__'

import { i18n } from '../../../i18n'
import { getIsOnDevice } from '../../../redux/config'
import { EstopMissingModal } from '../EstopMissingModal'

jest.mock('../../../redux/config')

const mockGetIsOnDevice = getIsOnDevice as jest.MockedFunction<
typeof getIsOnDevice
>
vi.mock('../../../redux/config')

const render = (props: React.ComponentProps<typeof EstopMissingModal>) => {
return renderWithProviders(<EstopMissingModal {...props} />, {
Expand All @@ -25,18 +22,18 @@ describe('EstopMissingModal - Touchscreen', () => {
beforeEach(() => {
props = {
robotName: 'mockFlex',
closeModal: jest.fn(),
closeModal: vi.fn(),
isDismissedModal: false,
setIsDismissedModal: jest.fn(),
setIsDismissedModal: vi.fn(),
}
mockGetIsOnDevice.mockReturnValue(true)
vi.mocked(getIsOnDevice).mockReturnValue(true)
})

it('should render text', () => {
const [{ getByText }] = render(props)
getByText('E-stop missing')
getByText('Connect the E-stop to continue')
getByText(
render(props)
screen.getByText('E-stop missing')
screen.getByText('Connect the E-stop to continue')
screen.getByText(
'Your E-stop could be damaged or detached. mockFlex lost its connection to the E-stop, so it canceled the protocol. Connect a functioning E-stop to continue.'
)
})
Expand All @@ -48,25 +45,25 @@ describe('EstopMissingModal - Desktop', () => {
beforeEach(() => {
props = {
robotName: 'mockFlex',
closeModal: jest.fn(),
closeModal: vi.fn(),
isDismissedModal: false,
setIsDismissedModal: jest.fn(),
setIsDismissedModal: vi.fn(),
}
mockGetIsOnDevice.mockReturnValue(false)
vi.mocked(getIsOnDevice).mockReturnValue(false)
})

it('should render text', () => {
const [{ getByText }] = render(props)
getByText('E-stop missing')
getByText('Connect the E-stop to continue')
getByText(
render(props)
screen.getByText('E-stop missing')
screen.getByText('Connect the E-stop to continue')
screen.getByText(
'Your E-stop could be damaged or detached. mockFlex lost its connection to the E-stop, so it canceled the protocol. Connect a functioning E-stop to continue.'
)
})

it('should call a mock function when clicking close icon', () => {
const [{ getByTestId }] = render(props)
fireEvent.click(getByTestId('ModalHeader_icon_close_E-stop missing'))
render(props)
fireEvent.click(screen.getByTestId('ModalHeader_icon_close_E-stop missing'))
expect(props.setIsDismissedModal).toHaveBeenCalled()
expect(props.closeModal).toHaveBeenCalled()
})
Expand Down
Loading

0 comments on commit 0644c03

Please sign in to comment.