Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ncdiehl11 committed Jan 16, 2025
1 parent 4f92a98 commit 843c5bd
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 7 deletions.
83 changes: 83 additions & 0 deletions step-generation/src/__tests__/absorbanceReaderCloseLid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { beforeEach, describe, it, expect, vi } from 'vitest'
import {
ABSORBANCE_READER_TYPE,
ABSORBANCE_READER_V1,
} from '@opentrons/shared-data'
import {
getErrorResult,
makeContext,
getInitialRobotStateStandard,
} from '../fixtures'
import { absorbanceReaderCloseLid } from '../commandCreators/atomic/absorbanceReaderCloseLid'
import { absorbanceReaderStateGetter } from '../robotStateSelectors'
import type {
AbsorbanceReaderState,
InvariantContext,
RobotState,
} from '../types'

const moduleId = 'absorbanceReaderId'
vi.mock('../robotStateSelectors')

describe('absorbanceReaderCloseLid', () => {
let invariantContext: InvariantContext
let robotState: RobotState
beforeEach(() => {
invariantContext = makeContext()
invariantContext.moduleEntities[moduleId] = {
id: moduleId,
type: ABSORBANCE_READER_TYPE,
model: ABSORBANCE_READER_V1,
}
robotState = getInitialRobotStateStandard(invariantContext)
robotState.modules[moduleId] = {
slot: 'D3',
moduleState: {
type: ABSORBANCE_READER_TYPE,
initialization: null,
lidOpen: false,
},
}
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(
{} as AbsorbanceReaderState
)
})
it.only('creates absorbance reader close lid command', () => {
const module = moduleId
const result = absorbanceReaderCloseLid(
{
module,
commandCreatorFnName: 'absorbanceReaderCloseLid',
},
invariantContext,
robotState
)
expect(result).toEqual({
commands: [
{
commandType: 'absorbanceReader/closeLid',
key: expect.any(String),
params: {
moduleId: module,
},
},
],
})
})
it('creates returns error if bad module state', () => {
const module = moduleId
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(null)
const result = absorbanceReaderCloseLid(
{
module,
commandCreatorFnName: 'absorbanceReaderCloseLid',
},
invariantContext,
robotState
)
expect(getErrorResult(result).errors).toHaveLength(1)
expect(getErrorResult(result).errors[0]).toMatchObject({
type: 'MISSING_MODULE',
})
})
})
83 changes: 83 additions & 0 deletions step-generation/src/__tests__/absorbanceReaderOpenLid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { beforeEach, describe, it, expect, vi } from 'vitest'
import {
ABSORBANCE_READER_TYPE,
ABSORBANCE_READER_V1,
} from '@opentrons/shared-data'
import {
getErrorResult,
makeContext,
getInitialRobotStateStandard,
} from '../fixtures'
import { absorbanceReaderOpenLid } from '../commandCreators/atomic/absorbanceReaderOpenLid'
import { absorbanceReaderStateGetter } from '../robotStateSelectors'
import type {
AbsorbanceReaderState,
InvariantContext,
RobotState,
} from '../types'

const moduleId = 'absorbanceReaderId'
vi.mock('../robotStateSelectors')

describe('absorbanceReaderOpenLid', () => {
let invariantContext: InvariantContext
let robotState: RobotState
beforeEach(() => {
invariantContext = makeContext()
invariantContext.moduleEntities[moduleId] = {
id: moduleId,
type: ABSORBANCE_READER_TYPE,
model: ABSORBANCE_READER_V1,
}
robotState = getInitialRobotStateStandard(invariantContext)
robotState.modules[moduleId] = {
slot: 'D3',
moduleState: {
type: ABSORBANCE_READER_TYPE,
initialization: null,
lidOpen: false,
},
}
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(
{} as AbsorbanceReaderState
)
})
it('creates absorbance reader open lid command', () => {
const module = moduleId
const result = absorbanceReaderOpenLid(
{
module,
commandCreatorFnName: 'absorbanceReaderOpenLid',
},
invariantContext,
robotState
)
expect(result).toEqual({
commands: [
{
commandType: 'absorbanceReader/openLid',
key: expect.any(String),
params: {
moduleId: module,
},
},
],
})
})
it('creates returns error if bad module state', () => {
const module = moduleId
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(null)
const result = absorbanceReaderOpenLid(
{
module,
commandCreatorFnName: 'absorbanceReaderOpenLid',
},
invariantContext,
robotState
)
expect(getErrorResult(result).errors).toHaveLength(1)
expect(getErrorResult(result).errors[0]).toMatchObject({
type: 'MISSING_MODULE',
})
})
})
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { uuid } from '../../utils'
import { missingModuleError } from '../../errorCreators'
import { getModuleState } from '../../robotStateSelectors'
import { absorbanceReaderStateGetter } from '../../robotStateSelectors'
import type { AbsorbanceReaderLidArgs, CommandCreator } from '../../types'

export const absorbanceReaderCloseLid: CommandCreator<AbsorbanceReaderLidArgs> = (
args,
invariantContext,
prevRobotState
) => {
const absorbanceReaderState = getModuleState(prevRobotState, args.module)
const absorbanceReaderState = absorbanceReaderStateGetter(
prevRobotState,
args.module
)
if (args.module == null || absorbanceReaderState == null) {
return {
errors: [missingModuleError()],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { uuid } from '../../utils'
import { missingModuleError } from '../../errorCreators'
import { getModuleState } from '../../robotStateSelectors'
import { absorbanceReaderStateGetter } from '../../robotStateSelectors'

import type { ModuleOnlyParams } from '@opentrons/shared-data/protocol/types/schemaV4'
import type { CommandCreator } from '../../types'
import type { AbsorbanceReaderLidArgs, CommandCreator } from '../../types'

export const absorbanceReaderOpenLid: CommandCreator<ModuleOnlyParams> = (
export const absorbanceReaderOpenLid: CommandCreator<AbsorbanceReaderLidArgs> = (
args,
invariantContext,
prevRobotState
) => {
const absorbanceReaderState = getModuleState(prevRobotState, args.module)
const absorbanceReaderState = absorbanceReaderStateGetter(
prevRobotState,
args.module
)
if (args.module == null || absorbanceReaderState == null) {
return {
errors: [missingModuleError()],
Expand Down

0 comments on commit 843c5bd

Please sign in to comment.