Skip to content

Commit

Permalink
refactor liquid command generator and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shlokamin committed Apr 12, 2022
1 parent d35e40f commit fef525c
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 211 deletions.
17 changes: 17 additions & 0 deletions protocol-designer/src/file-data/__tests__/createFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
fixtureP300Single,
} from '@opentrons/shared-data/pipette/fixtures/name'
import { LabwareDefinition2 } from '@opentrons/shared-data'
import { getLoadLiquidCommands } from '../../load-file/migration/utils/getLoadLiquidCommands'
import { createFile, getLabwareDefinitionsInUse } from '../selectors'
import {
fileMetadata,
Expand All @@ -29,6 +30,12 @@ import {
} from '../../../../step-generation/src/types'
import { LabwareDefByDefURI } from '../../labware-defs'

jest.mock('../../load-file/migration/utils/getLoadLiquidCommands')

const mockGetLoadLiquidCommands = getLoadLiquidCommands as jest.MockedFunction<
typeof getLoadLiquidCommands
>

const getAjvValidator = (_protocolSchema: Record<string, any>) => {
const ajv = new Ajv({
allErrors: true,
Expand Down Expand Up @@ -57,6 +64,12 @@ const expectResultToMatchSchema = (
}

describe('createFile selector', () => {
beforeEach(() => {
mockGetLoadLiquidCommands.mockReturnValue([])
})
afterEach(() => {
jest.restoreAllMocks()
})
it('should return a schema-valid JSON V6 protocol', () => {
// @ts-expect-error(sa, 2021-6-15): resultFunc not part of Selector type
const result = createFile.resultFunc(
Expand All @@ -79,6 +92,10 @@ describe('createFile selector', () => {
// have the opportunity to validate their part of the schema
expect(!isEmpty(result.labware)).toBe(true)
expect(!isEmpty(result.pipettes)).toBe(true)
expect(mockGetLoadLiquidCommands).toHaveBeenCalledWith(
ingredients,
ingredLocations
)
})
})
describe('getLabwareDefinitionsInUse util', () => {
Expand Down
5 changes: 4 additions & 1 deletion protocol-designer/src/file-data/selectors/fileCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ export const createFile: Selector<ProtocolFile> = createSelector(
}
)

const loadLiquidCommands = getLoadLiquidCommands(designerApplication)
const loadLiquidCommands = getLoadLiquidCommands(
ingredients,
ingredLocations
)
const modules: ProtocolFile['modules'] = mapValues(
moduleEntities,
(moduleEntity: ModuleEntity, moduleId: string) => ({
Expand Down
5 changes: 4 additions & 1 deletion protocol-designer/src/load-file/migration/6_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ export const migrateFile = (
}
)

const loadLiquidCommands = getLoadLiquidCommands(designerApplication)
const loadLiquidCommands = getLoadLiquidCommands(
designerApplication?.data?.ingredients,
designerApplication?.data?.ingredLocations
)
const migratedV5Commands = migrateCommands(commands)

const liquids: ProtocolFile['liquids'] =
Expand Down
224 changes: 25 additions & 199 deletions protocol-designer/src/load-file/migration/__tests__/6_0_0.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { migrateFile } from '../6_0_0'
import { getLoadLiquidCommands } from '../utils/getLoadLiquidCommands'
import _oldProtocol from 'protocol-designer/fixtures/protocol/5/doItAllV5.json'
import _oldProtocolMultipleLiquids from 'protocol-designer/fixtures/protocol/5/multipleLiquids.json'
import type { ProtocolFile, ProtocolFileV5 } from '@opentrons/shared-data'
import type { ProtocolFileV5 } from '@opentrons/shared-data'

const oldProtocol = (_oldProtocol as unknown) as ProtocolFileV5<any>

jest.mock('../utils/getLoadLiquidCommands')

const mockGetLoadLiquidCommands = getLoadLiquidCommands as jest.MockedFunction<
typeof getLoadLiquidCommands
>

describe('v6 migration', () => {
let migratedFile = {} as ProtocolFile
beforeEach(() => {
migratedFile = migrateFile(oldProtocol)
mockGetLoadLiquidCommands.mockReturnValue([])
})
afterEach(() => {
jest.restoreAllMocks()
})
it('removes slot from modules and labware', () => {
const migratedFile = migrateFile(oldProtocol)

expect(
oldProtocol.modules[
'0b419310-75c7-11ea-b42f-4b64e50f43e5:magneticModuleType'
Expand All @@ -35,6 +45,7 @@ describe('v6 migration', () => {
).toBeUndefined()
})
it('removes mount from pipettes', () => {
const migratedFile = migrateFile(oldProtocol)
expect(
oldProtocol.pipettes['0b3f2210-75c7-11ea-b42f-4b64e50f43e5'].mount
).toEqual('left')
Expand All @@ -44,17 +55,20 @@ describe('v6 migration', () => {
).toBeUndefined()
})
it('adds deckId to Robot', () => {
const migratedFile = migrateFile(oldProtocol)
expect(oldProtocol.robot).toEqual({ model: 'OT-2 Standard' })
expect(migratedFile.robot).toEqual({
model: 'OT-2 Standard',
deckId: 'ot2_standard',
})
})
it('adds a liquids key', () => {
const migratedFile = migrateFile(oldProtocol)
const expectedLiquids = { '0': { displayName: 'Water', description: null } }
expect(migratedFile.liquids).toEqual(expectedLiquids)
})
it('creates loadModule commands', () => {
const migratedFile = migrateFile(oldProtocol)
const expectedLoadModuleCommands = [
{
key: expect.any(String),
Expand All @@ -81,6 +95,7 @@ describe('v6 migration', () => {
expect(loadModuleCommands).toEqual(expectedLoadModuleCommands)
})
it('creates loadPipette commands', () => {
const migratedFile = migrateFile(oldProtocol)
const expectedLoadPipetteCommands = [
{
key: expect.any(String),
Expand All @@ -97,6 +112,7 @@ describe('v6 migration', () => {
expect(loadPipetteCommands).toEqual(expectedLoadPipetteCommands)
})
it('creates loadLabware commands', () => {
const migratedFile = migrateFile(oldProtocol)
const loadLabwareCommands = migratedFile.commands.filter(
command => command.commandType === 'loadLabware'
)
Expand Down Expand Up @@ -142,204 +158,14 @@ describe('v6 migration', () => {
expect(loadLabwareCommands).toEqual(expectedLoadLabwareCommaands)
})
it('creates loadLiquid commands', () => {
const expectedLoadLiquidCommands = [
{
key: expect.any(String),
commandType: 'loadLiquid',
params: {
liquidId: '0',
labwareId:
'6114d3d0-b759-11ec-81e8-7fa12dc3e861:opentrons/opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap/1', // this is just taken from the fixture
volumeByWell: {
A1: 222,
B1: 222,
C1: 222,
D1: 222,
A2: 222,
B2: 222,
C2: 222,
D2: 222,
},
},
},
{
key: expect.any(String),
commandType: 'loadLiquid',
params: {
liquidId: '1',
labwareId:
'6114d3d0-b759-11ec-81e8-7fa12dc3e861:opentrons/opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap/1', // this is just taken from the fixture
volumeByWell: {
A3: 333,
B3: 333,
C3: 333,
D3: 333,
A4: 333,
B4: 333,
C4: 333,
D4: 333,
},
},
},
{
key: expect.any(String),
commandType: 'loadLiquid',
params: {
liquidId: '2',
labwareId:
'6114d3d0-b759-11ec-81e8-7fa12dc3e861:opentrons/opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap/1', // this is just taken from the fixture
volumeByWell: {
A5: 444,
B5: 444,
C5: 444,
D5: 444,
A6: 444,
B6: 444,
C6: 444,
D6: 444,
},
},
},
{
key: expect.any(String),
commandType: 'loadLiquid',
params: {
liquidId: '0',
labwareId:
'64c66a20-b759-11ec-81e8-7fa12dc3e861:opentrons/usascientific_96_wellplate_2.4ml_deep/1', // this is just taken from the fixture
volumeByWell: {
A1: 555,
B1: 555,
C1: 555,
D1: 555,
E1: 555,
F1: 555,
G1: 555,
H1: 555,
A2: 555,
B2: 555,
C2: 555,
D2: 555,
E2: 555,
F2: 555,
G2: 555,
H2: 555,
A3: 555,
B3: 555,
C3: 555,
D3: 555,
E3: 555,
F3: 555,
G3: 555,
H3: 555,
},
},
},
{
key: expect.any(String),
commandType: 'loadLiquid',
params: {
liquidId: '1',
labwareId:
'64c66a20-b759-11ec-81e8-7fa12dc3e861:opentrons/usascientific_96_wellplate_2.4ml_deep/1', // this is just taken from the fixture
volumeByWell: {
A4: 666,
B4: 666,
C4: 666,
D4: 666,
E4: 666,
F4: 666,
G4: 666,
H4: 666,
A5: 666,
B5: 666,
C5: 666,
D5: 666,
E5: 666,
F5: 666,
G5: 666,
H5: 666,
A6: 666,
B6: 666,
C6: 666,
D6: 666,
E6: 666,
F6: 666,
G6: 666,
H6: 666,
},
},
},
{
key: expect.any(String),
commandType: 'loadLiquid',
params: {
liquidId: '2',
labwareId:
'64c66a20-b759-11ec-81e8-7fa12dc3e861:opentrons/usascientific_96_wellplate_2.4ml_deep/1', // this is just taken from the fixture
volumeByWell: {
A7: 777,
B7: 777,
C7: 777,
D7: 777,
E7: 777,
F7: 777,
G7: 777,
H7: 777,
A8: 777,
B8: 777,
C8: 777,
D8: 777,
E8: 777,
F8: 777,
G8: 777,
H8: 777,
A9: 777,
B9: 777,
C9: 777,
D9: 777,
E9: 777,
F9: 777,
G9: 777,
H9: 777,
A10: 777,
B10: 777,
C10: 777,
D10: 777,
E10: 777,
F10: 777,
G10: 777,
H10: 777,
A11: 777,
B11: 777,
C11: 777,
D11: 777,
E11: 777,
F11: 777,
G11: 777,
H11: 777,
A12: 777,
B12: 777,
C12: 777,
D12: 777,
E12: 777,
F12: 777,
G12: 777,
H12: 777,
},
},
},
]

const migratedLiquidsFile = migrateFile(_oldProtocolMultipleLiquids as any)
const loadLiquidCommands = migratedLiquidsFile.commands.filter(
command => command.commandType === 'loadLiquid'
)
expect(loadLiquidCommands).toEqual(
expect.arrayContaining(expectedLoadLiquidCommands)
migrateFile(oldProtocol)
expect(mockGetLoadLiquidCommands).toHaveBeenCalledWith(
_oldProtocol.designerApplication.data.ingredients,
_oldProtocol.designerApplication.data.ingredLocations
)
})
it('replaces air gap commands with aspirate commands', () => {
const migratedFile = migrateFile(oldProtocol)
const expectedConvertedAirgapCommands = [
{
key: expect.any(String), // no key used to exist in v5 commands
Expand Down
Loading

0 comments on commit fef525c

Please sign in to comment.