Skip to content

Commit

Permalink
new/fixed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Oct 1, 2024
1 parent 77c890e commit bf263e1
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 224 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import type * as React from 'react'
import { describe, it, vi, expect, beforeEach, afterEach } from 'vitest'
import { screen, waitFor } from '@testing-library/react'
import { describe, it, vi, beforeEach, afterEach } from 'vitest'
import { screen } from '@testing-library/react'

import { mockRecoveryContentProps } from '../../__fixtures__'
import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { RetryStep, RetryStepInfo } from '../RetryStep'
import { ERROR_KINDS, RECOVERY_MAP } from '../../constants'
import { RetryStep } from '../RetryStep'
import { RECOVERY_MAP } from '../../constants'
import { SelectRecoveryOption } from '../SelectRecoveryOption'

import { clickButtonLabeled } from '../../__tests__/util'

import type { Mock } from 'vitest'

vi.mock('/app/molecules/Command')
vi.mock('../SelectRecoveryOption')

Expand All @@ -22,14 +18,6 @@ const render = (props: React.ComponentProps<typeof RetryStep>) => {
})[0]
}

const renderRetryStepInfo = (
props: React.ComponentProps<typeof RetryStepInfo>
) => {
return renderWithProviders(<RetryStepInfo {...props} />, {
i18nInstance: i18n,
})[0]
}

describe('RetryStep', () => {
let props: React.ComponentProps<typeof RetryStep>

Expand Down Expand Up @@ -71,74 +59,3 @@ describe('RetryStep', () => {
screen.getByText('MOCK_SELECT_RECOVERY_OPTION')
})
})

describe('RetryStepInfo', () => {
let props: React.ComponentProps<typeof RetryStepInfo>
let mockhandleMotionRouting: Mock
let mockRetryFailedCommand: Mock
let mockResumeRun: Mock

beforeEach(() => {
mockhandleMotionRouting = vi.fn(() => Promise.resolve())
mockRetryFailedCommand = vi.fn(() => Promise.resolve())
mockResumeRun = vi.fn()

props = {
...mockRecoveryContentProps,
routeUpdateActions: {
handleMotionRouting: mockhandleMotionRouting,
} as any,
recoveryCommands: {
retryFailedCommand: mockRetryFailedCommand,
resumeRun: mockResumeRun,
} as any,
}
})

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

it(`renders the component with the correct text for ${ERROR_KINDS.TIP_NOT_DETECTED} `, () => {
renderRetryStepInfo({ ...props, errorKind: ERROR_KINDS.TIP_NOT_DETECTED })
screen.getByText('Retry step')
screen.queryByText(
'First, take any necessary actions to prepare the robot to retry the failed tip pickup.'
)
screen.queryByText('Then, close the robot door before proceeding.')
})

it('renders the component with the correct text for not specifically handled error kinds', () => {
renderRetryStepInfo(props)
screen.getByText('Retry step')
screen.queryByText(
'First, take any necessary actions to prepare the robot to retry the failed step.'
)
screen.queryByText('Then, close the robot door before proceeding.')
})

it('calls the correct routeUpdateActions and recoveryCommands in the correct order when the primary button is clicked', async () => {
renderRetryStepInfo(props)
clickButtonLabeled('Retry now')

await waitFor(() => {
expect(mockhandleMotionRouting).toHaveBeenCalledWith(
true,
RECOVERY_MAP.ROBOT_RETRYING_STEP.ROUTE
)
})
await waitFor(() => {
expect(mockRetryFailedCommand).toHaveBeenCalled()
})
await waitFor(() => {
expect(mockResumeRun).toHaveBeenCalled()
})

expect(mockhandleMotionRouting.mock.invocationCallOrder[0]).toBeLessThan(
mockRetryFailedCommand.mock.invocationCallOrder[0]
)
expect(mockRetryFailedCommand.mock.invocationCallOrder[0]).toBeLessThan(
mockResumeRun.mock.invocationCallOrder[0]
)
})
})
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type * as React from 'react'
import { describe, it, vi, expect, beforeEach, afterEach } from 'vitest'
import { screen, waitFor } from '@testing-library/react'
import { describe, it, vi, expect, beforeEach } from 'vitest'
import { screen } from '@testing-library/react'

import { mockRecoveryContentProps } from '../../__fixtures__'
import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { SkipStepNewTips, SkipStepWithNewTips } from '../SkipStepNewTips'
import { SkipStepNewTips } from '../SkipStepNewTips'
import { RECOVERY_MAP } from '../../constants'
import { SelectRecoveryOption } from '../SelectRecoveryOption'
import { clickButtonLabeled } from '../../__tests__/util'

import type { Mock } from 'vitest'

Expand All @@ -18,8 +17,9 @@ vi.mock('../../shared', async () => {
const actual = await vi.importActual('../../shared')
return {
...actual,
ReplaceTips: vi.fn(() => <div>MOCK_REPLACE_TIPS</div>),
SelectTips: vi.fn(() => <div>MOCK_SELECT_TIPS</div>),
TwoColLwInfoAndDeck: vi.fn(() => <div>MOCK_REPLACE_TIPS</div>),
SkipStepInfo: vi.fn(() => <div>MOCK_SKIP_STEP_INFO</div>),
}
})

Expand All @@ -29,14 +29,6 @@ const render = (props: React.ComponentProps<typeof SkipStepNewTips>) => {
})[0]
}

const renderSkipStepWithNewTips = (
props: React.ComponentProps<typeof SkipStepWithNewTips>
) => {
return renderWithProviders(<SkipStepWithNewTips {...props} />, {
i18nInstance: i18n,
})[0]
}

describe('SkipStepNewTips', () => {
let props: React.ComponentProps<typeof SkipStepNewTips>
let mockProceedToRouteAndStep: Mock
Expand Down Expand Up @@ -89,7 +81,7 @@ describe('SkipStepNewTips', () => {
},
}
render(props)
screen.getByText('Skip to next step with new tips')
screen.getByText('MOCK_SKIP_STEP_INFO')
})

it('renders SelectRecoveryOption as a fallback', () => {
Expand Down Expand Up @@ -119,56 +111,3 @@ describe('SkipStepNewTips', () => {
)
})
})

describe('SkipStepWithNewTips', () => {
let props: React.ComponentProps<typeof SkipStepWithNewTips>
let mockhandleMotionRouting: Mock
let mockSkipFailedCommand: Mock

beforeEach(() => {
mockhandleMotionRouting = vi.fn(() => Promise.resolve())
mockSkipFailedCommand = vi.fn(() => Promise.resolve())

props = {
...mockRecoveryContentProps,
routeUpdateActions: {
handleMotionRouting: mockhandleMotionRouting,
} as any,
recoveryCommands: {
skipFailedCommand: mockSkipFailedCommand,
} as any,
}
})

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

it('renders the component with the correct text', () => {
renderSkipStepWithNewTips(props)
screen.getByText('Skip to next step with new tips')
screen.queryByText(
'The failed dispense step will not be completed. The run will continue from the next step.'
)
screen.queryByText('Close the robot door before proceeding.')
})

it('calls the correct routeUpdateActions and recoveryCommands in the correct order when the primary button is clicked', async () => {
renderSkipStepWithNewTips(props)
clickButtonLabeled('Continue run now')

await waitFor(() => {
expect(mockhandleMotionRouting).toHaveBeenCalledWith(
true,
RECOVERY_MAP.ROBOT_SKIPPING_STEP.ROUTE
)
})
await waitFor(() => {
expect(mockSkipFailedCommand).toHaveBeenCalled()
})

expect(mockhandleMotionRouting.mock.invocationCallOrder[0]).toBeLessThan(
mockSkipFailedCommand.mock.invocationCallOrder[0]
)
})
})
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import type * as React from 'react'
import { describe, it, vi, expect, beforeEach, afterEach } from 'vitest'
import { screen, waitFor } from '@testing-library/react'
import { describe, it, vi, beforeEach } from 'vitest'
import { screen } from '@testing-library/react'

import { mockRecoveryContentProps } from '../../__fixtures__'
import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { SkipStepSameTips, SkipStepSameTipsInfo } from '../SkipStepSameTips'
import { SkipStepSameTips } from '../SkipStepSameTips'
import { RECOVERY_MAP } from '../../constants'
import { SelectRecoveryOption } from '../SelectRecoveryOption'

import { clickButtonLabeled } from '../../__tests__/util'

import type { Mock } from 'vitest'
import { SkipStepInfo } from '/app/organisms/ErrorRecoveryFlows/shared'

vi.mock('/app/molecules/Command')
vi.mock('/app/organisms/ErrorRecoveryFlows/shared')
vi.mock('../SelectRecoveryOption')

const render = (props: React.ComponentProps<typeof SkipStepSameTips>) => {
Expand All @@ -22,14 +20,6 @@ const render = (props: React.ComponentProps<typeof SkipStepSameTips>) => {
})[0]
}

const renderSkipStepSameTipsInfo = (
props: React.ComponentProps<typeof SkipStepSameTipsInfo>
) => {
return renderWithProviders(<SkipStepSameTipsInfo {...props} />, {
i18nInstance: i18n,
})[0]
}

describe('SkipStepSameTips', () => {
let props: React.ComponentProps<typeof SkipStepSameTips>

Expand All @@ -41,6 +31,7 @@ describe('SkipStepSameTips', () => {
vi.mocked(SelectRecoveryOption).mockReturnValue(
<div>MOCK_SELECT_RECOVERY_OPTION</div>
)
vi.mocked(SkipStepInfo).mockReturnValue(<div>MOCK_SKIP_STEP_INFO</div>)
})

it(`renders SkipStepSameTipsInfo when step is ${RECOVERY_MAP.SKIP_STEP_WITH_SAME_TIPS.STEPS.SKIP}`, () => {
Expand All @@ -52,7 +43,7 @@ describe('SkipStepSameTips', () => {
},
}
render(props)
screen.getByText('Skip to next step with same tips')
screen.getByText('MOCK_SKIP_STEP_INFO')
})

it('renders SelectRecoveryOption as a fallback', () => {
Expand All @@ -67,57 +58,3 @@ describe('SkipStepSameTips', () => {
screen.getByText('MOCK_SELECT_RECOVERY_OPTION')
})
})

describe('SkipStepSameTipsInfo', () => {
let props: React.ComponentProps<typeof SkipStepSameTipsInfo>
let mockhandleMotionRouting: Mock
let mockSkipFailedCommand: Mock

beforeEach(() => {
mockhandleMotionRouting = vi.fn(() => Promise.resolve())
mockSkipFailedCommand = vi.fn(() => Promise.resolve())

props = {
...mockRecoveryContentProps,
routeUpdateActions: {
handleMotionRouting: mockhandleMotionRouting,
} as any,
recoveryCommands: {
skipFailedCommand: mockSkipFailedCommand,
} as any,
}
})

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

it('renders the component with the correct text', () => {
renderSkipStepSameTipsInfo(props)
screen.getByText('Skip to next step with same tips')
screen.queryByText(
'The failed dispense step will not be completed. The run will continue from the next step.'
)
screen.queryByText('Close the robot door before proceeding.')
})

it('calls the correct routeUpdateActions and recoveryCommands in the correct order when the primary button is clicked', async () => {
renderSkipStepSameTipsInfo(props)
clickButtonLabeled('Continue run now')

await waitFor(() => {
expect(mockhandleMotionRouting).toHaveBeenCalledWith(
true,
RECOVERY_MAP.ROBOT_SKIPPING_STEP.ROUTE
)
})

await waitFor(() => {
expect(mockSkipFailedCommand).toHaveBeenCalled()
})

expect(mockhandleMotionRouting.mock.invocationCallOrder[0]).toBeLessThan(
mockSkipFailedCommand.mock.invocationCallOrder[0]
)
})
})
Loading

0 comments on commit bf263e1

Please sign in to comment.