Skip to content

Commit

Permalink
update R -> U in organisms vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 23, 2024
1 parent 04d7abf commit b7326fd
Show file tree
Hide file tree
Showing 44 changed files with 1,205 additions and 1,612 deletions.
5 changes: 3 additions & 2 deletions app/src/__fixtures__/queryResults.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { vi } from 'vitest'
import type { UseQueryResult } from 'react-query'

export function mockSuccessQueryResults<Result>(
Expand All @@ -23,7 +24,7 @@ export function mockSuccessQueryResults<Result>(
isPlaceholderData: false,
isPreviousData: false,
isStale: false,
refetch: jest.fn(),
remove: jest.fn(),
refetch: vi.fn(),
remove: vi.fn(),
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import * as React from 'react'

import { renderWithProviders } from '@opentrons/components'

import { screen } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { i18n } from '../../../../i18n'
import { renderWithProviders } from '../../../../__testing-utils__'
import { mockFetchModulesSuccessActionPayloadModules } from '../../../../redux/modules/__fixtures__'
import { ModuleCalibrationOverflowMenu } from '../ModuleCalibrationOverflowMenu'
import { formatLastCalibrated } from '../utils'
import { ModuleCalibrationItems } from '../ModuleCalibrationItems'

import type { AttachedModule } from '@opentrons/api-client'

jest.mock('../ModuleCalibrationOverflowMenu')

const mockModuleCalibrationOverflowMenu = ModuleCalibrationOverflowMenu as jest.MockedFunction<
typeof ModuleCalibrationOverflowMenu
>
vi.mock('../ModuleCalibrationOverflowMenu')

const mockCalibratedModule = {
id: '1436cd6085f18e5c315d65bd835d899a631cc2ba',
Expand Down Expand Up @@ -71,36 +67,38 @@ describe('ModuleCalibrationItems', () => {
beforeEach(() => {
props = {
attachedModules: mockFetchModulesSuccessActionPayloadModules,
updateRobotStatus: jest.fn(),
updateRobotStatus: vi.fn(),
formattedPipetteOffsetCalibrations: [],
robotName: ROBOT_NAME,
}
mockModuleCalibrationOverflowMenu.mockReturnValue(
vi.mocked(ModuleCalibrationOverflowMenu).mockReturnValue(
<div>mock ModuleCalibrationOverflowMenu</div>
)
})

it('should render module information and overflow menu', () => {
const [{ getByText, getAllByText }] = render(props)
getByText('Module')
getByText('Serial')
getByText('Last Calibrated')
getByText('Magnetic Module GEN1')
getByText('def456')
getByText('Temperature Module GEN1')
getByText('abc123')
getByText('Thermocycler Module GEN1')
getByText('ghi789')
expect(getAllByText('Not calibrated').length).toBe(3)
expect(getAllByText('mock ModuleCalibrationOverflowMenu').length).toBe(3)
render(props)
screen.getByText('Module')
screen.getByText('Serial')
screen.getByText('Last Calibrated')
screen.getByText('Magnetic Module GEN1')
screen.getByText('def456')
screen.getByText('Temperature Module GEN1')
screen.getByText('abc123')
screen.getByText('Thermocycler Module GEN1')
screen.getByText('ghi789')
expect(screen.getAllByText('Not calibrated').length).toBe(3)
expect(
screen.getAllByText('mock ModuleCalibrationOverflowMenu').length
).toBe(3)
})

it('should display last calibrated time if a module is calibrated', () => {
props = {
...props,
attachedModules: [mockCalibratedModule] as AttachedModule[],
}
const [{ getByText }] = render(props)
getByText(formatLastCalibrated('2023-06-01T14:42:20.131798+00:00'))
render(props)
screen.getByText(formatLastCalibrated('2023-06-01T14:42:20.131798+00:00'))
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react'
import { fireEvent, screen, waitFor } from '@testing-library/react'
import { renderWithProviders } from '@opentrons/components'
import { when, resetAllWhenMocks } from 'jest-when'

import { when } from 'vitest-when'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { i18n } from '../../../../i18n'
import { renderWithProviders } from '../../../../__testing-utils__'
import { ModuleWizardFlows } from '../../../ModuleWizardFlows'
import { useChainLiveCommands } from '../../../../resources/runs/hooks'
import { mockThermocyclerGen2 } from '../../../../redux/modules/__fixtures__'
Expand All @@ -14,11 +14,11 @@ import { ModuleCalibrationOverflowMenu } from '../ModuleCalibrationOverflowMenu'

import type { Mount } from '@opentrons/components'

jest.mock('@opentrons/react-api-client')
jest.mock('../../../ModuleWizardFlows')
jest.mock('../../../Devices/hooks')
jest.mock('../../../../resources/runs/hooks')
jest.mock('../../../../resources/devices/hooks/useIsEstopNotDisengaged')
vi.mock('@opentrons/react-api-client')
vi.mock('../../../ModuleWizardFlows')
vi.mock('../../../Devices/hooks')
vi.mock('../../../../resources/runs/hooks')
vi.mock('../../../../resources/devices/hooks/useIsEstopNotDisengaged')

const mockPipetteOffsetCalibrations = [
{
Expand Down Expand Up @@ -88,19 +88,6 @@ const mockTCHeating = {
},
} as any

const mockModuleWizardFlows = ModuleWizardFlows as jest.MockedFunction<
typeof ModuleWizardFlows
>
const mockUseRunStatuses = useRunStatuses as jest.MockedFunction<
typeof useRunStatuses
>
const mockUseChainLiveCommands = useChainLiveCommands as jest.MockedFunction<
typeof useChainLiveCommands
>
const mockUseIsEstopNotDisengaged = useIsEstopNotDisengaged as jest.MockedFunction<
typeof useIsEstopNotDisengaged
>

const render = (
props: React.ComponentProps<typeof ModuleCalibrationOverflowMenu>
) => {
Expand All @@ -113,36 +100,29 @@ const ROBOT_NAME = 'mockRobot'

describe('ModuleCalibrationOverflowMenu', () => {
let props: React.ComponentProps<typeof ModuleCalibrationOverflowMenu>
let mockChainLiveCommands = jest.fn()
let mockChainLiveCommands = vi.fn()

beforeEach(() => {
props = {
isCalibrated: false,
attachedModule: mockThermocyclerGen2,
updateRobotStatus: jest.fn(),
updateRobotStatus: vi.fn(),
formattedPipetteOffsetCalibrations: mockPipetteOffsetCalibrations,
robotName: ROBOT_NAME,
}
mockChainLiveCommands = jest.fn()
mockChainLiveCommands = vi.fn()
mockChainLiveCommands.mockResolvedValue(null)
mockModuleWizardFlows.mockReturnValue(<div>module wizard flows</div>)
mockUseRunStatuses.mockReturnValue({
vi.mocked(ModuleWizardFlows).mockReturnValue(<div>module wizard flows</div>)
vi.mocked(useRunStatuses).mockReturnValue({
isRunRunning: false,
isRunStill: false,
isRunIdle: false,
isRunTerminal: false,
})
mockUseChainLiveCommands.mockReturnValue({
vi.mocked(useChainLiveCommands).mockReturnValue({
chainLiveCommands: mockChainLiveCommands,
} as any)
when(mockUseIsEstopNotDisengaged)
.calledWith(ROBOT_NAME)
.mockReturnValue(false)
})

afterEach(() => {
jest.clearAllMocks()
resetAllWhenMocks()
when(useIsEstopNotDisengaged).calledWith(ROBOT_NAME).thenReturn(false)
})

it('should render overflow menu buttons - not calibrated', () => {
Expand Down Expand Up @@ -295,7 +275,7 @@ describe('ModuleCalibrationOverflowMenu', () => {
})

it('should be disabled when running', () => {
mockUseRunStatuses.mockReturnValue({
vi.mocked(useRunStatuses).mockReturnValue({
isRunRunning: true,
isRunStill: false,
isRunIdle: false,
Expand All @@ -307,9 +287,7 @@ describe('ModuleCalibrationOverflowMenu', () => {
})

it('should be disabled when e-stop button is pressed', () => {
when(mockUseIsEstopNotDisengaged)
.calledWith(ROBOT_NAME)
.mockReturnValue(true)
when(useIsEstopNotDisengaged).calledWith(ROBOT_NAME).thenReturn(true)
const [{ getByLabelText }] = render(props)
expect(getByLabelText('ModuleCalibrationOverflowMenu')).toBeDisabled()
})
Expand Down
Loading

0 comments on commit b7326fd

Please sign in to comment.