Skip to content

Commit

Permalink
migrate tests in organisms A and B folders
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 23, 2024
1 parent de33ffd commit 04d7abf
Show file tree
Hide file tree
Showing 34 changed files with 304 additions and 474 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest'
import '@testing-library/jest-dom/vitest'
import { transfer_settings } from '@opentrons/shared-data/protocol/fixtures/6'
import { transfer_settings } from '@opentrons/shared-data'

Check failure on line 3 in app/src/molecules/PythonLabwareOffsetSnippet/__tests__/createSnippet.test.ts

View workflow job for this annotation

GitHub Actions / js checks

'/home/runner/work/opentrons/opentrons/app/node_modules/@opentrons/shared-data/js/index.ts' imported multiple times
import { ModuleModel, CompletedProtocolAnalysis } from '@opentrons/shared-data'

Check failure on line 4 in app/src/molecules/PythonLabwareOffsetSnippet/__tests__/createSnippet.test.ts

View workflow job for this annotation

GitHub Actions / js checks

'/home/runner/work/opentrons/opentrons/app/node_modules/@opentrons/shared-data/js/index.ts' imported multiple times
import { createSnippet } from '../createSnippet'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import * as React from 'react'
import { MemoryRouter } from 'react-router-dom'
import { fireEvent } from '@testing-library/react'
import { renderWithProviders } from '@opentrons/components'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { fireEvent, screen } from '@testing-library/react'
import { i18n } from '../../../i18n'
import {
useTrackEvent,
ANALYTICS_ADD_CUSTOM_LABWARE,
} from '../../../redux/analytics'
import { renderWithProviders } from '../../../__testing-utils__'
import { AddCustomLabwareSlideout } from '..'

jest.mock('../../../redux/custom-labware')
jest.mock('../../../pages/Labware/helpers/getAllDefs')
jest.mock('../../../redux/analytics')
vi.mock('../../../redux/custom-labware')
vi.mock('../../../pages/Labware/helpers/getAllDefs')
vi.mock('../../../redux/analytics')

const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
typeof useTrackEvent
>

let mockTrackEvent: jest.Mock
let mockTrackEvent: any

const render = (
props: React.ComponentProps<typeof AddCustomLabwareSlideout>
Expand All @@ -35,18 +32,18 @@ const render = (
describe('AddCustomLabwareSlideout', () => {
const props: React.ComponentProps<typeof AddCustomLabwareSlideout> = {
isExpanded: true,
onCloseClick: jest.fn(() => null),
onCloseClick: vi.fn(() => null),
}
beforeEach(() => {
mockTrackEvent = jest.fn()
mockUseTrackEvent.mockReturnValue(mockTrackEvent)
mockTrackEvent = vi.fn()
vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent)
})

it('renders correct title and labware cards and clicking on button triggers analytics event', () => {
const [{ getByText, getByRole }] = render(props)
getByText('Import a Custom Labware Definition')
getByText('Or choose a file from your computer to upload.')
const btn = getByRole('button', { name: 'Upload' })
render(props)
screen.getByText('Import a Custom Labware Definition')
screen.getByText('Or choose a file from your computer to upload.')
const btn = screen.getByRole('button', { name: 'Upload' })
fireEvent.click(btn)
expect(mockTrackEvent).toHaveBeenCalledWith({
name: ANALYTICS_ADD_CUSTOM_LABWARE,
Expand All @@ -55,7 +52,7 @@ describe('AddCustomLabwareSlideout', () => {
})

it('renders drag and drop section', () => {
const [{ getByRole }] = render(props)
getByRole('button', { name: 'browse' })
render(props)
screen.getByRole('button', { name: 'browse' })
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { fireEvent, screen } from '@testing-library/react'
import { renderWithProviders } from '@opentrons/components'
import { i18n } from '../../../i18n'
import { getCustomLabwareDirectory } from '../../../redux/custom-labware'
import {
Expand All @@ -9,33 +9,29 @@ import {
} from '../../../redux/analytics'

import { AdditionalCustomLabwareSourceFolder } from '../AdditionalCustomLabwareSourceFolder'
import { renderWithProviders } from '../../../__testing-utils__'

jest.mock('../../../redux/custom-labware')
jest.mock('../../../redux/analytics')
vi.mock('../../../redux/custom-labware')
vi.mock('../../../redux/analytics')

const render = () => {
return renderWithProviders(<AdditionalCustomLabwareSourceFolder />, {
i18nInstance: i18n,
})
}

const mockTrackEvent = jest.fn()

const mockGetCustomLabwarePath = getCustomLabwareDirectory as jest.MockedFunction<
typeof getCustomLabwareDirectory
>
const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
typeof useTrackEvent
>
const mockTrackEvent = vi.fn()

describe('AdditionalCustomLabwareSourceFolder', () => {
beforeEach(() => {
mockUseTrackEvent.mockReturnValue(mockTrackEvent)
mockGetCustomLabwarePath.mockReturnValue('')
vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent)
vi.mocked(getCustomLabwareDirectory).mockReturnValue('')
})

it('renders the custom labware section with source folder selected', () => {
mockGetCustomLabwarePath.mockReturnValue('/mock/custom-labware-path')
vi.mocked(getCustomLabwareDirectory).mockReturnValue(
'/mock/custom-labware-path'
)
render()
screen.getByText(
'If you want to specify a folder to manually manage Custom Labware files, you can add the directory here.'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as React from 'react'
import { screen, fireEvent } from '@testing-library/react'

import {
renderWithProviders,
useConditionalConfirm,
} from '@opentrons/components'
import { screen, fireEvent, waitFor } from '@testing-library/react'

Check failure on line 2 in app/src/organisms/AdvancedSettings/__tests__/ClearUnavailableRobots.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

'waitFor' is defined but never used
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { useConditionalConfirm } from '@opentrons/components'
import { i18n } from '../../../i18n'
import {
getReachableRobots,
Expand All @@ -14,43 +11,44 @@ import {
mockReachableRobot,
mockUnreachableRobot,
} from '../../../redux/discovery/__fixtures__'
import { renderWithProviders } from '../../../__testing-utils__'
import { ClearUnavailableRobots } from '../ClearUnavailableRobots'
import type * as OpentronsComponents from '@opentrons/components'

const mockConfirm = vi.fn()
const mockCancel = vi.fn()

jest.mock('@opentrons/components/src/hooks')
jest.mock('../../../redux/discovery')
vi.mock('@opentrons/components', async importOriginal => {
const actual = await importOriginal<typeof OpentronsComponents>()
return {
...actual,
useConditionalConfirm: vi.fn(() => ({
confirm: mockConfirm,
showConfirmation: true,
cancel: mockCancel,
})),
}
})

const mockGetUnreachableRobots = getUnreachableRobots as jest.MockedFunction<
typeof getUnreachableRobots
>
const mockGetReachableRobots = getReachableRobots as jest.MockedFunction<
typeof getReachableRobots
>
const mockUseConditionalConfirm = useConditionalConfirm as jest.MockedFunction<
typeof useConditionalConfirm
>
vi.mock('../../../redux/discovery')

const render = () => {
return renderWithProviders(<ClearUnavailableRobots />, {
i18nInstance: i18n,
})
}

const mockConfirm = jest.fn()
const mockCancel = jest.fn()

describe('ClearUnavailableRobots', () => {
beforeEach(() => {
mockGetUnreachableRobots.mockReturnValue([mockUnreachableRobot])
mockGetReachableRobots.mockReturnValue([mockReachableRobot])
mockUseConditionalConfirm.mockReturnValue({
vi.mocked(getUnreachableRobots).mockReturnValue([mockUnreachableRobot])
vi.mocked(getReachableRobots).mockReturnValue([mockReachableRobot])
vi.mocked(useConditionalConfirm).mockReturnValue({
confirm: mockConfirm,
showConfirmation: true,
cancel: mockCancel,
})
})

afterEach(() => {})

it('should render text and button', () => {
render()
screen.getByText('Clear Unavailable Robots')
Expand All @@ -69,7 +67,8 @@ describe('ClearUnavailableRobots', () => {
name: 'Clear unavailable robots list',
})
)
screen.getByText('Clear unavailable robots?')

screen.getByText('Clear unavailable robots')
screen.getByText(
'Clearing the list of unavailable robots on the Devices page cannot be undone.'
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import * as React from 'react'
import { screen, fireEvent } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach } from 'vitest'

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

import { renderWithProviders } from '../../../__testing-utils__'
import { getDevtoolsEnabled, toggleDevtools } from '../../../redux/config'
import { EnableDevTools } from '../EnableDevTools'

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

const mockGetDevtoolsEnabled = getDevtoolsEnabled as jest.MockedFunction<
typeof getDevtoolsEnabled
>
const mockToggleDevtools = toggleDevtools as jest.MockedFunction<
typeof toggleDevtools
>
vi.mock('../../../redux/config')

const render = () => {
return renderWithProviders(<EnableDevTools />, {
Expand All @@ -24,11 +17,7 @@ const render = () => {

describe('EnableDevTools', () => {
beforeEach(() => {
mockGetDevtoolsEnabled.mockReturnValue(true)
})

afterEach(() => {
jest.clearAllMocks()
vi.mocked(getDevtoolsEnabled).mockReturnValue(true)
})

it('should render text and toggle button', () => {
Expand All @@ -46,6 +35,6 @@ describe('EnableDevTools', () => {
name: 'enable_dev_tools',
})
fireEvent.click(toggleButton)
expect(mockToggleDevtools).toHaveBeenCalled()
expect(vi.mocked(toggleDevtools)).toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
import * as React from 'react'
import { screen, fireEvent } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach } from 'vitest'

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

import {
resetUseTrashSurfaceForTipCal,
setUseTrashSurfaceForTipCal,
} from '../../../redux/calibration'
import { getUseTrashSurfaceForTipCal } from '../../../redux/config'
import { renderWithProviders } from '../../../__testing-utils__'
import { OT2AdvancedSettings } from '../OT2AdvancedSettings'

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

const mockResetUseTrashSurfaceForTipCal = resetUseTrashSurfaceForTipCal as jest.MockedFunction<
typeof resetUseTrashSurfaceForTipCal
>

const mockSetUseTrashSurfaceForTipCal = setUseTrashSurfaceForTipCal as jest.MockedFunction<
typeof setUseTrashSurfaceForTipCal
>

const mockGetUseTrashSurfaceForTipCal = getUseTrashSurfaceForTipCal as jest.MockedFunction<
typeof getUseTrashSurfaceForTipCal
>
vi.mock('../../../redux/calibration')
vi.mock('../../../redux/config')

const render = () => {
return renderWithProviders(<OT2AdvancedSettings />, {
Expand All @@ -34,11 +23,7 @@ const render = () => {

describe('OT2AdvancedSettings', () => {
beforeEach(() => {
mockGetUseTrashSurfaceForTipCal.mockReturnValue(true)
})

afterEach(() => {
jest.clearAllMocks()
vi.mocked(getUseTrashSurfaceForTipCal).mockReturnValue(true)
})

it('should render text and toggle button', () => {
Expand All @@ -60,17 +45,17 @@ describe('OT2AdvancedSettings', () => {
name: 'Always use calibration block to calibrate',
})
fireEvent.click(radioButton)
expect(mockSetUseTrashSurfaceForTipCal).toHaveBeenCalledWith(false)
expect(vi.mocked(setUseTrashSurfaceForTipCal)).toHaveBeenCalledWith(false)
})

it('should call mock setUseTrashSurfaceForTipCal with true when selecting always trash', () => {
mockGetUseTrashSurfaceForTipCal.mockReturnValue(false)
vi.mocked(getUseTrashSurfaceForTipCal).mockReturnValue(false)
render()
const radioButton = screen.getByRole('radio', {
name: 'Always use trash bin to calibrate',
})
fireEvent.click(radioButton)
expect(mockSetUseTrashSurfaceForTipCal).toHaveBeenCalledWith(true)
expect(vi.mocked(setUseTrashSurfaceForTipCal)).toHaveBeenCalledWith(true)
})

it('should call mock resetUseTrashSurfaceForTipCal when selecting always prompt', () => {
Expand All @@ -79,6 +64,6 @@ describe('OT2AdvancedSettings', () => {
name: 'Always show the prompt to choose calibration block or trash bin',
})
fireEvent.click(radioButton)
expect(mockResetUseTrashSurfaceForTipCal).toHaveBeenCalled()
expect(vi.mocked(resetUseTrashSurfaceForTipCal)).toHaveBeenCalled()
})
})
Loading

0 comments on commit 04d7abf

Please sign in to comment.