-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
278 additions
and
1 deletion.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
step-generation/src/__tests__/absorbanceReaderCloseInitialize.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
136
step-generation/src/__tests__/absorbanceReaderCloseRead.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters