Skip to content

Commit

Permalink
it.each
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Oct 17, 2024
1 parent bc3cc6f commit 2b5e7d9
Showing 1 changed file with 65 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,97 +6,74 @@ import { getErrorKind } from '../getErrorKind'
import type { RunCommandError, RunTimeCommand } from '@opentrons/shared-data'

describe('getErrorKind', () => {
it(`returns ${ERROR_KINDS.NO_LIQUID_DETECTED} for ${DEFINED_ERROR_TYPES.LIQUID_NOT_FOUND} errorType`, () => {
const result = getErrorKind({
it.each([
{
commandType: 'aspirate',
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
expectedError: ERROR_KINDS.OVERPRESSURE_WHILE_ASPIRATING,
},
{
commandType: 'aspirateInPlace',
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
expectedError: ERROR_KINDS.OVERPRESSURE_WHILE_ASPIRATING,
},
{
commandType: 'dispense',
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
expectedError: ERROR_KINDS.OVERPRESSURE_WHILE_DISPENSING,
},
{
commandType: 'dispenseInPlace',
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
expectedError: ERROR_KINDS.OVERPRESSURE_WHILE_DISPENSING,
},
{
commandType: 'dropTip',
errorType: DEFINED_ERROR_TYPES.TIP_PHYSICALLY_ATTACHED,
expectedError: ERROR_KINDS.TIP_DROP_FAILED,
},
{
commandType: 'dropTipInPlace',
errorType: DEFINED_ERROR_TYPES.TIP_PHYSICALLY_ATTACHED,
expectedError: ERROR_KINDS.TIP_DROP_FAILED,
},
{
commandType: 'liquidProbe',
error: {
isDefined: true,
errorType: DEFINED_ERROR_TYPES.LIQUID_NOT_FOUND,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.NO_LIQUID_DETECTED)
})

const IS_IN_PLACE = [false, true]

IS_IN_PLACE.forEach(isInPlace => {
it(`returns ${ERROR_KINDS.OVERPRESSURE_WHILE_ASPIRATING} for ${DEFINED_ERROR_TYPES.OVERPRESSURE} errorType when using the inPlace command type is ${isInPlace}`, () => {
const result = getErrorKind({
commandType: isInPlace ? 'aspirateInPlace' : 'aspirate',
error: {
isDefined: true,
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.OVERPRESSURE_WHILE_ASPIRATING)
})

it(`returns ${ERROR_KINDS.OVERPRESSURE_WHILE_DISPENSING} for ${DEFINED_ERROR_TYPES.OVERPRESSURE} errorType when using the inPlace command type is ${isInPlace}`, () => {
const result = getErrorKind({
commandType: isInPlace ? 'dispenseInPlace' : 'dispense',
error: {
isDefined: true,
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.OVERPRESSURE_WHILE_DISPENSING)
})

it(`returns ${ERROR_KINDS.TIP_DROP_FAILED} for ${DEFINED_ERROR_TYPES.TIP_PHYSICALLY_ATTACHED} errorType when using the inPlace command type is ${isInPlace}`, () => {
const result = getErrorKind({
commandType: isInPlace ? 'dropTipInPlace' : 'dropTip',
error: {
isDefined: true,
errorType: DEFINED_ERROR_TYPES.TIP_PHYSICALLY_ATTACHED,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.TIP_DROP_FAILED)
})
})

it(`returns ${ERROR_KINDS.TIP_NOT_DETECTED} for ${DEFINED_ERROR_TYPES.TIP_PHYSICALLY_MISSING} errorType`, () => {
const result = getErrorKind({
errorType: DEFINED_ERROR_TYPES.LIQUID_NOT_FOUND,
expectedError: ERROR_KINDS.NO_LIQUID_DETECTED,
},
{
commandType: 'pickUpTip',
error: {
isDefined: true,
errorType: DEFINED_ERROR_TYPES.TIP_PHYSICALLY_MISSING,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.TIP_NOT_DETECTED)
})

it(`returns ${ERROR_KINDS.GRIPPER_ERROR} for ${DEFINED_ERROR_TYPES.GRIPPER_MOVEMENT} errorType`, () => {
const result = getErrorKind({
errorType: DEFINED_ERROR_TYPES.TIP_PHYSICALLY_MISSING,
expectedError: ERROR_KINDS.TIP_NOT_DETECTED,
},
{
commandType: 'moveLabware',
error: {
isDefined: true,
errorType: DEFINED_ERROR_TYPES.GRIPPER_MOVEMENT,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.GRIPPER_ERROR)
})

it(`returns ${ERROR_KINDS.GENERAL_ERROR} for undefined errors`, () => {
const result = getErrorKind({
errorType: DEFINED_ERROR_TYPES.GRIPPER_MOVEMENT,
expectedError: ERROR_KINDS.GRIPPER_ERROR,
},
{
commandType: 'aspirate',
error: {
isDefined: false,
// It should treat this error as undefined because isDefined===false,
// even though the errorType happens to match a defined error.
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.GENERAL_ERROR)
})

it(`returns ${ERROR_KINDS.GENERAL_ERROR} for defined errors not handled explicitly`, () => {
const result = getErrorKind({
errorType: DEFINED_ERROR_TYPES.OVERPRESSURE,
isDefined: false,
expectedError: ERROR_KINDS.GENERAL_ERROR,
},
{
commandType: 'aspirate',
error: ({
isDefined: true,
errorType: 'someHithertoUnknownDefinedErrorType',
} as unknown) as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(ERROR_KINDS.GENERAL_ERROR)
})
errorType: 'someHithertoUnknownDefinedErrorType',
expectedError: ERROR_KINDS.GENERAL_ERROR,
},
])(
'returns $expectedError for $commandType with errorType $errorType',
({ commandType, errorType, expectedError, isDefined = true }) => {
const result = getErrorKind({
commandType,
error: {
isDefined,
errorType,
} as RunCommandError,
} as RunTimeCommand)
expect(result).toEqual(expectedError)
}
)
})

0 comments on commit 2b5e7d9

Please sign in to comment.