Skip to content

Commit

Permalink
test(app, components, protocol-designer): testing library lint rules …
Browse files Browse the repository at this point in the history
…to error, fix all occurences

Promote the two previously demoted testing library eslint rules back to error and correct all
outstanding occurences.
  • Loading branch information
b-cooper committed May 31, 2024
1 parent f71ef58 commit d0d9ae3
Show file tree
Hide file tree
Showing 36 changed files with 368 additions and 315 deletions.
35 changes: 17 additions & 18 deletions app/src/App/__tests__/DesktopApp.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { MemoryRouter } from 'react-router-dom'
import { screen } from '@testing-library/react'
import { vi, describe, beforeEach, afterEach, expect, it } from 'vitest'

import { renderWithProviders } from '../../__testing-utils__'
Expand Down Expand Up @@ -61,47 +62,45 @@ describe('DesktopApp', () => {
vi.resetAllMocks()
})
it('renders a Breadcrumbs component', () => {
const [{ getByText }] = render('/devices')
getByText('Mock Breadcrumbs')
render('/devices')
screen.getByText('Mock Breadcrumbs')
})

it('renders an AppSettings component', () => {
const [{ getByText }] = render('/app-settings/general')
getByText('Mock AppSettings')
render('/app-settings/general')
screen.getByText('Mock AppSettings')
})

it('renders a DevicesLanding component from /devices', () => {
const [{ getByText }] = render('/devices')
getByText('Mock DevicesLanding')
render('/devices')
screen.getByText('Mock DevicesLanding')
})

it('renders a DeviceDetails component from /devices/:robotName', () => {
const [{ getByText }] = render('/devices/otie')
getByText('Mock DeviceDetails')
render('/devices/otie')
screen.getByText('Mock DeviceDetails')
})

it('renders a RobotSettings component from /devices/:robotName/robot-settings/:robotSettingsTab', () => {
const [{ getByText }] = render('/devices/otie/robot-settings/calibration')
getByText('Mock RobotSettings')
render('/devices/otie/robot-settings/calibration')
screen.getByText('Mock RobotSettings')
})

it('renders a CalibrationDashboard component from /devices/:robotName/robot-settings/calibration/dashboard', () => {
const [{ getByText }] = render(
'/devices/otie/robot-settings/calibration/dashboard'
)
getByText('Mock CalibrationDashboard')
render('/devices/otie/robot-settings/calibration/dashboard')
screen.getByText('Mock CalibrationDashboard')
})

it('renders a ProtocolsLanding component from /protocols', () => {
const [{ getByText }] = render('/protocols')
getByText('Mock ProtocolsLanding')
render('/protocols')
screen.getByText('Mock ProtocolsLanding')
})

it('renders a ProtocolRunDetails component from /devices/:robotName/protocol-runs/:runId/:protocolRunDetailsTab', () => {
const [{ getByText }] = render(
render(
'/devices/otie/protocol-runs/95e67900-bc9f-4fbf-92c6-cc4d7226a51b/setup'
)
getByText('Mock ProtocolRunDetails')
screen.getByText('Mock ProtocolRunDetails')
})

it('should poll for software updates', () => {
Expand Down
10 changes: 5 additions & 5 deletions app/src/atoms/MenuList/__tests__/OverflowBtn.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { vi, it, expect, describe } from 'vitest'
import { fireEvent } from '@testing-library/react'
import { fireEvent, screen } from '@testing-library/react'
import { COLORS } from '@opentrons/components'

import { renderWithProviders } from '../../../__testing-utils__'
Expand All @@ -13,21 +13,21 @@ const render = (props: React.ComponentProps<typeof OverflowBtn>) => {
describe('OverflowBtn', () => {
it('renders a clickable button', () => {
const handleClick = vi.fn()
const { getByRole } = render({
render({
onClick: handleClick,
})

const button = getByRole('button')
const button = screen.getByRole('button')
fireEvent.click(button)
expect(handleClick).toHaveBeenCalledTimes(1)
})

it('renders a hover state', () => {
const { getByRole } = render({
render({
onClick: vi.fn(),
})

expect(getByRole('button')).toHaveStyle(
expect(screen.getByRole('button')).toHaveStyle(
`background-color: ${COLORS.transparent}`
)
})
Expand Down
4 changes: 2 additions & 2 deletions app/src/atoms/buttons/__tests__/FloatingActionButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe('FloatingActionButton', () => {
})

it('renders floating action button with text - active', () => {
const { getByRole } = render(props)
const button = getByRole('button')
render(props)
const button = screen.getByRole('button')
expect(button).toHaveStyle(
`padding: ${SPACING.spacing12} ${SPACING.spacing24}`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ describe('Module Update Banner', () => {
...props,
calibratePipetteRequired: true,
}
const { queryByText } = render(props)
expect(queryByText('Calibrate now')).not.toBeInTheDocument()
render(props)
expect(screen.queryByText('Calibrate now')).not.toBeInTheDocument()
})

it('should not render a calibrate link if pipette firmware update is required', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ describe('CalibrateTipLength', () => {
currentStep: Sessions.DECK_STEP_PREPARING_PIPETTE,
},
}
const { getByRole } = render({ isJogging: false, session })[0]
const forwardButton = getByRole('button', { name: 'forward' })
render({ isJogging: false, session })
const forwardButton = screen.getByRole('button', { name: 'forward' })
fireEvent.click(forwardButton)
expect(dispatchRequests).toHaveBeenCalledWith(
Sessions.createSessionCommand('robot-name', session.id, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { it, describe } from 'vitest'
import { screen } from '@testing-library/react'

import { renderWithProviders } from '../../../../__testing-utils__'
import * as Sessions from '../../../../redux/sessions'
Expand All @@ -15,40 +16,40 @@ const render = (props: React.ComponentProps<typeof Body>) => {

describe('Body', () => {
it('renders correct text for health check', () => {
const { getByText } = render({
render({
sessionType: Sessions.SESSION_TYPE_CALIBRATION_HEALTH_CHECK,
})
getByText(
screen.getByText(
'Calibration Health Check diagnoses problems with Deck, Tip Length, and Pipette Offset Calibration.'
)
getByText(
screen.getByText(
'You will move the pipettes to various positions, which will be compared against your existing calibration data.'
)
getByText(
screen.getByText(
'If there is a large difference, you will be prompted to redo some or all of your calibrations.'
)
})
it('renders correct text for deck cal', () => {
const { getByText } = render({
render({
sessionType: Sessions.SESSION_TYPE_DECK_CALIBRATION,
})
getByText(
screen.getByText(
'Deck calibration ensures positional accuracy so that your robot moves as expected. It will accurately establish the OT-2’s deck orientation relative to the gantry.'
)
})
it('renders correct text for pip offset cal', () => {
const { getByText } = render({
render({
sessionType: Sessions.SESSION_TYPE_PIPETTE_OFFSET_CALIBRATION,
})
getByText(
screen.getByText(
'Calibrating pipette offset measures a pipette’s position relative to the pipette mount and the deck.'
)
})
it('renders correct text for tip length cal', () => {
const { getByText } = render({
render({
sessionType: Sessions.SESSION_TYPE_TIP_LENGTH_CALIBRATION,
})
getByText(
screen.getByText(
'Tip length calibration measures the distance between the bottom of the tip and the pipette’s nozzle.'
)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { it, describe } from 'vitest'
import { screen } from '@testing-library/react'

import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
Expand All @@ -16,12 +17,14 @@ const render = (sessionType: 'tipLengthCalibration' | 'deckCalibration') => {

describe('InvalidationWarning', () => {
it('renders correct text - deck calibration', () => {
const { getByText } = render('deckCalibration')
getByText('Recalibrating the deck clears pipette offset data')
getByText('Pipette offsets for both mounts will have to be recalibrated.')
render('deckCalibration')
screen.getByText('Recalibrating the deck clears pipette offset data')
screen.getByText(
'Pipette offsets for both mounts will have to be recalibrated.'
)
})
it('renders correct text - tip length calibration', () => {
const { getByText } = render('tipLengthCalibration')
getByText('Recalibrating tip length will clear pipette offset data.')
render('tipLengthCalibration')
screen.getByText('Recalibrating tip length will clear pipette offset data.')
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { fireEvent } from '@testing-library/react'
import { fireEvent, screen } from '@testing-library/react'
import { vi, it, describe, expect, beforeEach } from 'vitest'

import { usePipettesQuery } from '@opentrons/react-api-client'
Expand Down Expand Up @@ -64,30 +64,30 @@ describe('ChooseTipRack', () => {
})

it('renders the correct text', () => {
const { getByText, getByAltText } = render(props)
getByText('Choose a tip rack')
getByText('select tip rack')
getByText('mock select')
getByText(
render(props)
screen.getByText('Choose a tip rack')
screen.getByText('select tip rack')
screen.getByText('mock select')
screen.getByText(
'Choose what tip rack you’d like to use to calibrate your tip length.'
)
getByText('Want to use a tip rack that’s not listed here?')
screen.getByText('Want to use a tip rack that’s not listed here?')

getByText(
screen.getByText(
'Opentrons tip racks are highly recommended. Accuracy cannot be guaranteed with other tip racks.'
)
getByText('300ul Tiprack FIXTURE')
getByAltText('300ul Tiprack FIXTURE image')
getByText(
screen.getByText('300ul Tiprack FIXTURE')
screen.getByAltText('300ul Tiprack FIXTURE image')
screen.getByText(
'It’s extremely important to perform this calibration using the Opentrons tips and tip racks specified above, as the robot determines accuracy based on the known measurements of these tips.'
)
})

it('renders the buttons and they work as expected', () => {
const { getByRole } = render(props)
getByRole('link', { name: 'Need help?' })
const cancel = getByRole('button', { name: 'cancel' })
const confirm = getByRole('button', { name: 'Confirm tip rack' })
render(props)
screen.getByRole('link', { name: 'Need help?' })
const cancel = screen.getByRole('button', { name: 'cancel' })
const confirm = screen.getByRole('button', { name: 'Confirm tip rack' })
fireEvent.click(cancel)
expect(props.closeModal).toHaveBeenCalled()
fireEvent.click(confirm)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { it, describe, beforeEach } from 'vitest'
import { screen } from '@testing-library/react'

import { i18n } from '../../../i18n'
import { renderWithProviders } from '../../../__testing-utils__'
Expand All @@ -26,8 +27,8 @@ describe('ChosenTipRackRender', () => {
})

it('renders text and image alt text when tip rack is Opentrons 96 1000uL', () => {
const { getByText, getByAltText } = render(props)
getByText('Opentrons 96 tip rack 1000ul')
getByAltText('Opentrons 96 tip rack 1000ul image')
render(props)
screen.getByText('Opentrons 96 tip rack 1000ul')
screen.getByAltText('Opentrons 96 tip rack 1000ul image')
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { fireEvent, renderHook } from '@testing-library/react'
import { fireEvent, renderHook, screen } from '@testing-library/react'
import { I18nextProvider } from 'react-i18next'
import { vi, it, describe, expect } from 'vitest'

Expand Down Expand Up @@ -43,11 +43,11 @@ describe('useConfirmCrashRecovery', () => {
expect(link).not.toBeNull()
expect(confirmation).toBeNull()

const { getByText, getByRole } = renderWithProviders(link, {
renderWithProviders(link, {
i18nInstance: i18n,
})[0]
getByText('Jog too far or bend a tip?')
getByRole('button', { name: 'Start over' })
})
screen.getByText('Jog too far or bend a tip?')
screen.getByRole('button', { name: 'Start over' })
})

it('renders the modal with the right props when you click the link', () => {
Expand All @@ -65,26 +65,29 @@ describe('useConfirmCrashRecovery', () => {
)

// render returned confirmation if not null, otherwise render the link
const { getByRole, rerender } = renderWithProviders(
<div>{result.current[1] ?? result.current[0]}</div>,
{ i18nInstance: i18n }
)[0]
renderWithProviders(<div>{result.current[1] ?? result.current[0]}</div>, {
i18nInstance: i18n,
})
// click the link to launch the modal
fireEvent.click(getByRole('button', { name: 'Start over' }))
fireEvent.click(screen.getByRole('button', { name: 'Start over' }))
// the confirmation should now not be null
expect(result.current[1]).not.toBeNull()
// the explicitly rerender to incorporate newly non-null confirmation
rerender(<div>{result.current[1] ?? result.current[0]}</div>)
renderWithProviders(<div>{result.current[1] ?? result.current[0]}</div>, {
i18nInstance: i18n,
})

// click the "back" link in the confirmation
const closeConfirmationButton = getByRole('button', { name: 'resume' })
const closeConfirmationButton = screen.getByRole('button', {
name: 'resume',
})
fireEvent.click(closeConfirmationButton)
// the confirmation should now be null once more
expect(result.current[1]).toBeNull()

// open the confirmation again and click the proceed to start over button
fireEvent.click(getByRole('button', { name: 'Start over' }))
const startOverButton = getByRole('button', { name: 'Start over' })
fireEvent.click(screen.getByRole('button', { name: 'Start over' }))
const startOverButton = screen.getByRole('button', { name: 'Start over' })
fireEvent.click(startOverButton)
expect(mockSendCommands).toHaveBeenCalledWith({
command: sharedCalCommands.INVALIDATE_LAST_ACTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ describe('CalibrationTaskList', () => {
})

it('does not show the Calibrations complete screen when viewing a completed task list', () => {
const [{ queryByText }] = render()
expect(queryByText('Calibrations complete!')).toBeFalsy()
render()
expect(screen.queryByText('Calibrations complete!')).toBeFalsy()
})

it('shows the Calibrations complete screen after the calibrations are completed', () => {
Expand Down
Loading

0 comments on commit d0d9ae3

Please sign in to comment.