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 11 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 { labware as LabwareFunctions } from '../'
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
35 changes: 35 additions & 0 deletions app/src/calibration/api-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,38 @@ 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>,
type: string,
meta: Object,
|}
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: 4 additions & 0 deletions app/src/calibration/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// @flow
// calibration data actions, selectors and constants
import * as labware from './labware'

export * from './actions'
export * from './constants'
export * from './selectors'
export * from './types'
mcous marked this conversation as resolved.
Show resolved Hide resolved
export { labware }
mcous marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions app/src/calibration/labware/__fixtures__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @flow
export * from './labware-calibration'
57 changes: 57 additions & 0 deletions app/src/calibration/labware/__fixtures__/labware-calibration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @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 mockLabwareCalibration: 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 mockAllLabwareCalibraton: AllLabwareCalibrations = {
data: [mockLabwareCalibration],
meta: {},
type: 'Labware Calibration',
mcous marked this conversation as resolved.
Show resolved Hide resolved
}

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,
})
67 changes: 67 additions & 0 deletions app/src/calibration/labware/__tests__/actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// @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 fetchCalibrationStatus action',
creator: Actions.fetchAllLabwareCalibrations,
args: ['robot-name'],
expected: {
type: 'calibration:FETCH_ALL_LABWARE_CALIBRATIONS',
payload: { robotName: 'robot-name' },
meta: {},
},
},
{
should: 'create a fetchCalibrationStatusSuccess 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 fetchCalibrationStatusFailure 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)
})
})
})
30 changes: 30 additions & 0 deletions app/src/calibration/labware/__tests__/selectors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @flow

import * as Fixtures from '../__fixtures__'
import * as StatusFixtures from '../../__fixtures__'
import * as Selectors from '../selectors'

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

describe('labware calibration selectors', () => {
it('should return null if no robot in state', () => {
const state: $Shape<State> = { calibration: {} }
expect(Selectors.getListOfLabwareCalibrations(state, 'robotName')).toBe(
null
)
})

it('should return list of calibrations if in state', () => {
const state: $Shape<State> = {
calibration: {
robotName: {
calibrationStatus: StatusFixtures.mockCalibrationStatus,
labwareCalibration: Fixtures.mockAllLabwareCalibraton,
},
},
}
expect(Selectors.getListOfLabwareCalibrations(state, 'robotName')).toEqual(
Fixtures.mockAllLabwareCalibraton.data
)
})
})
41 changes: 41 additions & 0 deletions app/src/calibration/labware/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// @flow

import * as Constants from './constants'
import * as Types from './types'
import * as APITypes from '../types'

import type {
RobotApiRequestMeta,
RobotApiErrorResponse,
} from '../../robot-api/types'

export const fetchAllLabwareCalibrations = (
robotName: string,
loadName?: string,
namespace?: string,
version?: number
): Types.FetchLabwareCalibrationAction => ({
type: Constants.FETCH_ALL_LABWARE_CALIBRATIONS,
payload: { robotName, loadName, namespace, version },
mcous marked this conversation as resolved.
Show resolved Hide resolved
meta: {},
})

export const fetchLabwareCalibrationsSuccess = (
robotName: string,
labwareCalibration: APITypes.AllLabwareCalibrations,
meta: RobotApiRequestMeta
): Types.FetchAllLabwareCalibrationSuccessAction => ({
type: Constants.FETCH_LABWARE_CALIBRATION_SUCCESS,
payload: { robotName, labwareCalibration },
meta,
})

export const fetchLabwareCalibrationsFailure = (
robotName: string,
error: RobotApiErrorResponse,
meta: RobotApiRequestMeta
): Types.FetchLabwareCalibrationFailureAction => ({
type: Constants.FETCH_LABWARE_CALIBRATION_FAILURE,
payload: { robotName, error },
meta,
})
13 changes: 13 additions & 0 deletions app/src/calibration/labware/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @flow

export const LABWARE_CALIBRATION_PATH: '/labware/calibrations' =
'/labware/calibrations'

export const FETCH_ALL_LABWARE_CALIBRATIONS: 'calibration:FETCH_ALL_LABWARE_CALIBRATIONS' =
'calibration:FETCH_ALL_LABWARE_CALIBRATIONS'

export const FETCH_LABWARE_CALIBRATION_SUCCESS: 'calibration:FETCH_LABWARE_CALIBRATION_SUCCESS' =
'calibration:FETCH_LABWARE_CALIBRATION_SUCCESS'

export const FETCH_LABWARE_CALIBRATION_FAILURE: 'calibration:FETCH_LABWARE_CALIBRATION_FAILURE' =
'calibration:FETCH_LABWARE_CALIBRATION_FAILURE'
Loading