Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): Expose Labware Calibration Status on the FileInfo Page #6100

Merged
merged 18 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/src/calibration/__tests__/reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow

import * as Fixtures from '../__fixtures__'
import * as LabwareFixtures from '../labware/__fixtures__'
import * as LabwareFunctions from '../labware'
import * as Actions from '../actions'
import { calibrationReducer } from '../reducer'

Expand All @@ -16,4 +18,17 @@ describe('calibration reducer', () => {
'robot-name': { calibrationStatus: Fixtures.mockCalibrationStatus },
})
})
it('should handle a FETCH_LABWARE_CALIBRATION_SUCCESS', () => {
const action = LabwareFunctions.fetchLabwareCalibrationsSuccess(
'robot-name',
LabwareFixtures.mockAllLabwareCalibraton,
{}
)

expect(calibrationReducer({}, action)).toEqual({
'robot-name': {
labwareCalibration: LabwareFixtures.mockAllLabwareCalibraton,
},
})
})
})
10 changes: 8 additions & 2 deletions app/src/calibration/__tests__/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ describe('calibration selectors', () => {
it('should return status if in state', () => {
const state: $Shape<State> = {
calibration: {
robotName: { calibrationStatus: Fixtures.mockCalibrationStatus },
robotName: {
calibrationStatus: Fixtures.mockCalibrationStatus,
labwareCalibration: null,
},
},
}
expect(Selectors.getCalibrationStatus(state, 'robotName')).toEqual(
Expand All @@ -33,7 +36,10 @@ describe('calibration selectors', () => {
it('should return status if in state', () => {
const state: $Shape<State> = {
calibration: {
robotName: { calibrationStatus: Fixtures.mockCalibrationStatus },
robotName: {
calibrationStatus: Fixtures.mockCalibrationStatus,
labwareCalibration: null,
},
},
}
expect(Selectors.getDeckCalibrationStatus(state, 'robotName')).toEqual(
Expand Down
34 changes: 34 additions & 0 deletions app/src/calibration/api-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,37 @@ export type CalibrationStatus = {|
|},
|},
|}

export type OffsetData = {|
value: Array<number>,
lastModified: string,
|}

export type TipLengthData = {|
value: number,
lastModified: string,
|}

export type CalibrationData = {|
offset: OffsetData,
tipLength: TipLengthData | null,
|}

export type SingleLabwareCalibration = {|
calibrationData: CalibrationData,
loadName: string,
namespace: string,
version: number,
parent: string,
|}

export type LabwareCalibrationObjects = {|
attributes: SingleLabwareCalibration,
type: string,
id: string,
|}

export type AllLabwareCalibrations = {|
data: Array<LabwareCalibrationObjects | null>,
meta: Object,
|}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { setupEpicTestMocks, runEpicTest } from '../../../robot-api/__utils__'
import * as Fixtures from '../../__fixtures__'
import * as Actions from '../../actions'
import { calibrationEpic } from '..'
import { calibrationEpic } from '../../'

const makeTriggerAction = robotName => Actions.fetchCalibrationStatus(robotName)

Expand Down
1 change: 0 additions & 1 deletion app/src/calibration/epic/fetchCalibrationStatusEpic.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const mapResponseToAction: ResponseToActionMapper<FetchCalibrationStatusAction>
) => {
const { host, body, ...responseMeta } = response
const meta = { ...originalAction.meta, response: responseMeta }

return response.ok
? Actions.fetchCalibrationStatusSuccess(host.name, body, meta)
: Actions.fetchCalibrationStatusFailure(host.name, body, meta)
Expand Down
4 changes: 3 additions & 1 deletion app/src/calibration/epic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import { fetchCalibrationStatusEpic } from './fetchCalibrationStatusEpic'

import type { Epic } from '../../types'

export const calibrationEpic: Epic = combineEpics(fetchCalibrationStatusEpic)
export const calibrationStatusEpic: Epic = combineEpics(
fetchCalibrationStatusEpic
)
12 changes: 12 additions & 0 deletions app/src/calibration/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// @flow
// calibration data actions, selectors and constants
import { combineEpics } from 'redux-observable'
import { calibrationStatusEpic } from './epic'
import { labwareCalibrationEpic } from './labware/epic'

import type { Epic } from '../types'

export * from './actions'
export * from './constants'
export * from './selectors'
export * from './labware'

export const calibrationEpic: Epic = combineEpics(
mcous marked this conversation as resolved.
Show resolved Hide resolved
calibrationStatusEpic,
labwareCalibrationEpic
)
17 changes: 17 additions & 0 deletions app/src/calibration/labware/__fixtures__/associate-calibration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @flow
import type { LabwareWithCalibration } from '../types'

export const mockLabwareWithCalibration: Array<LabwareWithCalibration> = [
{
quantity: 1,
display: '',
parent: '',
calibration: { x: 1, y: 1, z: 1 },
},
{
quantity: 1,
display: '',
parent: 'Magnetic Module GEN1',
calibration: null,
},
]
3 changes: 3 additions & 0 deletions app/src/calibration/labware/__fixtures__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow
export * from './labware-calibration'
export * from './associate-calibration'
77 changes: 77 additions & 0 deletions app/src/calibration/labware/__fixtures__/labware-calibration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// @flow
import { GET } from '../../../robot-api'
import {
makeResponseFixtures,
mockFailureBody,
} from '../../../robot-api/__fixtures__'
import { LABWARE_CALIBRATION_PATH } from '../constants'

import type { ResponseFixtures } from '../../../robot-api/__fixtures__'
import type {
LabwareCalibrationObjects,
AllLabwareCalibrations,
} from '../../api-types'

export const mockLabwareCalibration1: LabwareCalibrationObjects = {
attributes: {
calibrationData: {
offset: {
value: [0.0, 0.0, 0.0],
lastModified: '2020-04-05T14:30',
},
tipLength: {
value: 30,
lastModified: '2007-05-05T0:30',
},
},
loadName: 'opentrons_96_tiprack_10ul',
namespace: 'opentrons',
version: 1,
parent: 'fake_id',
},
id: 'some id',
type: 'Labware Calibration',
}

export const mockLabwareCalibration2: LabwareCalibrationObjects = {
attributes: {
calibrationData: {
offset: {
value: [1.0, 1.0, 1.0],
lastModified: '2020-04-05T14:30',
},
tipLength: {
value: 30,
lastModified: '2007-05-05T0:30',
},
},
loadName: 'opentrons_96_tiprack_1000ul',
namespace: 'opentrons',
version: 1,
parent: '',
},
id: 'some id',
type: 'Labware Calibration',
}

export const mockAllLabwareCalibraton: AllLabwareCalibrations = {
data: [mockLabwareCalibration1, mockLabwareCalibration2],
meta: {},
}

export const {
successMeta: mockFetchLabwareCalibrationSuccessMeta,
failureMeta: mockFetchLabwareCalibrationFailureMeta,
success: mockFetchLabwareCalibrationSuccess,
failure: mockFetchLabwareCalibrationFailure,
}: ResponseFixtures<
AllLabwareCalibrations,
{| message: string |}
> = makeResponseFixtures({
method: GET,
path: LABWARE_CALIBRATION_PATH,
successStatus: 200,
successBody: mockAllLabwareCalibraton,
failureStatus: 500,
failureBody: mockFailureBody,
})
87 changes: 87 additions & 0 deletions app/src/calibration/labware/__tests__/actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// @flow

import * as Fixtures from '../__fixtures__'
import * as Actions from '../actions'
import type { LawareCalibrationAction } from '../types'

type ActionSpec = {|
should: string,
creator: (...Array<any>) => LawareCalibrationAction,
args: Array<mixed>,
expected: LawareCalibrationAction,
|}

const SPECS: Array<ActionSpec> = [
{
should: 'create a fetchLabwareCalibration action',
creator: Actions.fetchAllLabwareCalibrations,
args: ['robot-name'],
expected: {
type: 'calibration:FETCH_ALL_LABWARE_CALIBRATIONS',
payload: {
robotName: 'robot-name',
loadName: null,
namespace: null,
version: null,
},
meta: {},
},
},
{
should: 'create a fetchLabwareCalibration action with params',
creator: Actions.fetchAllLabwareCalibrations,
args: ['robot-name', 'fake_labware', 'weird', 1],
expected: {
type: 'calibration:FETCH_ALL_LABWARE_CALIBRATIONS',
payload: {
robotName: 'robot-name',
loadName: 'fake_labware',
namespace: 'weird',
version: 1,
},
meta: {},
},
},
{
should: 'create a fetchLabwareCalibrationSuccess action',
creator: Actions.fetchLabwareCalibrationsSuccess,
args: [
'robot-name',
Fixtures.mockFetchLabwareCalibrationSuccess.body,
{ requestId: '123' },
],
expected: {
type: 'calibration:FETCH_LABWARE_CALIBRATION_SUCCESS',
payload: {
robotName: 'robot-name',
labwareCalibration: Fixtures.mockAllLabwareCalibraton,
},
meta: { requestId: '123' },
},
},
{
should: 'create a fetchLabwareCalibrationFailure action',
creator: Actions.fetchLabwareCalibrationsFailure,
args: [
'robot-name',
Fixtures.mockFetchLabwareCalibrationFailure.body,
{ requestId: '123' },
],
expected: {
type: 'calibration:FETCH_LABWARE_CALIBRATION_FAILURE',
payload: {
robotName: 'robot-name',
error: Fixtures.mockFetchLabwareCalibrationFailure.body,
},
meta: { requestId: '123' },
},
},
]

describe('calibration actions', () => {
SPECS.forEach(({ should, creator, args, expected }) => {
it(should, () => {
expect(creator(...args)).toEqual(expected)
})
})
})
Loading