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 843c5bd commit c88beba
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 1 deletion.
142 changes: 142 additions & 0 deletions step-generation/src/__tests__/absorbanceReaderCloseInitialize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { beforeEach, describe, it, expect, vi, afterEach } from 'vitest'
import { absorbanceReaderCloseInitialize } from '../commandCreators'
import {
absorbanceReaderStateGetter,
getModuleState,
} from '../robotStateSelectors'
import { getInitialRobotStateStandard, makeContext } from '../fixtures'
import { getErrorResult, getSuccessResult } from '../fixtures/commandFixtures'

import type {
AbsorbanceReaderInitializeArgs,
AbsorbanceReaderState,
InvariantContext,
RobotState,
} from '../types'
import {
ABSORBANCE_READER_TYPE,
ABSORBANCE_READER_V1,
} from '@opentrons/shared-data'

vi.mock('../robotStateSelectors')

describe('absorbanceReaderCloseInitialize compound command creator', () => {
let absorbanceReaderCloseInitializeArgs: AbsorbanceReaderInitializeArgs
const ABSORBANCE_READER_MODULE_ID = 'absorbanceReaderModuleId'
const ABSORBANCE_READER_MODULE_SLOT = 'D3'
let robotState: RobotState
let invariantContext: InvariantContext
beforeEach(() => {
absorbanceReaderCloseInitializeArgs = {
commandCreatorFnName: 'absorbanceReaderInitialize',
module: ABSORBANCE_READER_MODULE_ID,
mode: 'single',
wavelengths: [450],
}
invariantContext = {
...makeContext(),
moduleEntities: {
[ABSORBANCE_READER_MODULE_ID]: {
id: ABSORBANCE_READER_MODULE_ID,
type: ABSORBANCE_READER_TYPE,
model: ABSORBANCE_READER_V1,
},
},
}
const state = getInitialRobotStateStandard(invariantContext)

robotState = {
...state,
modules: {
...state.modules,
[ABSORBANCE_READER_MODULE_ID]: {
slot: ABSORBANCE_READER_MODULE_SLOT,
} as any,
},
}
vi.mocked(getModuleState).mockReturnValue({
type: ABSORBANCE_READER_TYPE,
} as any)
})
afterEach(() => {
vi.restoreAllMocks()
})
it('should return an error when module is not found', () => {
const result = absorbanceReaderCloseInitialize(
absorbanceReaderCloseInitializeArgs,
invariantContext,
robotState
)
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(null)

expect(getErrorResult(result).errors).toHaveLength(1)
expect(getErrorResult(result).errors[0]).toMatchObject({
type: 'MISSING_MODULE',
})
})
it('should emit close and intalize commands if single mode', () => {
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(
{} as AbsorbanceReaderState
)

const result = absorbanceReaderCloseInitialize(
absorbanceReaderCloseInitializeArgs,
invariantContext,
robotState
)

expect(getSuccessResult(result).commands).toEqual([
{
commandType: 'absorbanceReader/closeLid',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
},
},
{
commandType: 'absorbanceReader/initialize',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
sampleWavelengths: [450],
measureMode: 'single',
},
},
])
})
it('should emit close and intalize commands if multi mode', () => {
absorbanceReaderCloseInitializeArgs = {
...absorbanceReaderCloseInitializeArgs,
mode: 'multi',
wavelengths: [450, 600],
}
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(
{} as AbsorbanceReaderState
)

const result = absorbanceReaderCloseInitialize(
absorbanceReaderCloseInitializeArgs,
invariantContext,
robotState
)

expect(getSuccessResult(result).commands).toEqual([
{
commandType: 'absorbanceReader/closeLid',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
},
},
{
commandType: 'absorbanceReader/initialize',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
sampleWavelengths: [450, 600],
measureMode: 'multi',
},
},
])
})
})
136 changes: 136 additions & 0 deletions step-generation/src/__tests__/absorbanceReaderCloseRead.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { beforeEach, describe, it, expect, vi, afterEach } from 'vitest'
import { absorbanceReaderCloseRead } from '../commandCreators'
import {
absorbanceReaderStateGetter,
getModuleState,
} from '../robotStateSelectors'
import { getInitialRobotStateStandard, makeContext } from '../fixtures'
import { getErrorResult, getSuccessResult } from '../fixtures/commandFixtures'

import type {
AbsorbanceReaderReadArgs,
AbsorbanceReaderState,
InvariantContext,
RobotState,
} from '../types'
import {
ABSORBANCE_READER_TYPE,
ABSORBANCE_READER_V1,
} from '@opentrons/shared-data'

vi.mock('../robotStateSelectors')

describe('absorbanceReaderCloseRead compound command creator', () => {
let absorbanceReaderCloseReadArgs: AbsorbanceReaderReadArgs
const ABSORBANCE_READER_MODULE_ID = 'absorbanceReaderModuleId'
const ABSORBANCE_READER_OUTPUT_PATH = 'outputPath.csv'
const ABSORBANCE_READER_MODULE_SLOT = 'D3'
let robotState: RobotState
let invariantContext: InvariantContext
beforeEach(() => {
absorbanceReaderCloseReadArgs = {
commandCreatorFnName: 'absorbanceReaderRead',
module: ABSORBANCE_READER_MODULE_ID,
fileName: null,
}
invariantContext = {
...makeContext(),
moduleEntities: {
[ABSORBANCE_READER_MODULE_ID]: {
id: ABSORBANCE_READER_MODULE_ID,
type: ABSORBANCE_READER_TYPE,
model: ABSORBANCE_READER_V1,
},
},
}
const state = getInitialRobotStateStandard(invariantContext)

robotState = {
...state,
modules: {
...state.modules,
[ABSORBANCE_READER_MODULE_ID]: {
slot: ABSORBANCE_READER_MODULE_SLOT,
} as any,
},
}
vi.mocked(getModuleState).mockReturnValue({
type: ABSORBANCE_READER_TYPE,
} as any)
})
afterEach(() => {
vi.restoreAllMocks()
})
it('should return an error when module is not found', () => {
const result = absorbanceReaderCloseRead(
absorbanceReaderCloseReadArgs,
invariantContext,
robotState
)
vi.mocked(absorbanceReaderStateGetter).mockReturnValue(null)

expect(getErrorResult(result).errors).toHaveLength(1)
expect(getErrorResult(result).errors[0]).toMatchObject({
type: 'MISSING_MODULE',
})
})
it.only('should emit close and read commands without fileName param', () => {
vi.mocked(absorbanceReaderStateGetter).mockReturnValue({
initialization: {},
} as AbsorbanceReaderState)
const result = absorbanceReaderCloseRead(
absorbanceReaderCloseReadArgs,
invariantContext,
robotState
)

expect(getSuccessResult(result).commands).toEqual([
{
commandType: 'absorbanceReader/closeLid',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
},
},
{
commandType: 'absorbanceReader/read',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
},
},
])
})
it.only('should emit close and read commands with fileName param', () => {
vi.mocked(absorbanceReaderStateGetter).mockReturnValue({
initialization: {},
} as AbsorbanceReaderState)
absorbanceReaderCloseReadArgs = {
...absorbanceReaderCloseReadArgs,
fileName: ABSORBANCE_READER_OUTPUT_PATH,
}
const result = absorbanceReaderCloseRead(
absorbanceReaderCloseReadArgs,
invariantContext,
robotState
)

expect(getSuccessResult(result).commands).toEqual([
{
commandType: 'absorbanceReader/closeLid',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
},
},
{
commandType: 'absorbanceReader/read',
key: expect.any(String),
params: {
moduleId: 'absorbanceReaderModuleId',
fileName: ABSORBANCE_READER_OUTPUT_PATH,
},
},
])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const absorbanceReaderCloseRead: CommandCreator<AbsorbanceReaderReadArgs>
if (errors.length > 0) {
return { errors }
}

const { module, fileName } = args
const commandCreators: CurriedCommandCreator[] = [
curryCommandCreator(absorbanceReaderCloseLid, {
Expand Down

0 comments on commit c88beba

Please sign in to comment.