Skip to content

Commit

Permalink
Fixup tests and flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura-Danielle committed Jul 9, 2020
1 parent 00fc80a commit 530d447
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 203 deletions.
4 changes: 2 additions & 2 deletions app/src/calibration/__tests__/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ describe('calibration reducer', () => {
it('should handle a FETCH_LABWARE_CALIBRATION_SUCCESS', () => {
const action = LabwareActions.fetchLabwareCalibrationSuccess(
'robot-name',
[LabwareFixtures.mockLabwareCalibration],
LabwareFixtures.mockAllLabwareCalibraton,
{}
)

expect(calibrationReducer({}, action)).toEqual({
'robot-name': {
labwareCalibration: [LabwareFixtures.mockLabwareCalibration],
labwareCalibration: LabwareFixtures.mockAllLabwareCalibraton,
},
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export const {
success: mockFetchLabwareCalibrationSuccess,
failure: mockFetchLabwareCalibrationFailure,
}: ResponseFixtures<
Array<?LabwareCalibrationObjects>,
AllLabwareCalibrations,
{| message: string |}
> = makeResponseFixtures({
method: GET,
path: LABWARE_CALIBRATION_PATH,
successStatus: 200,
successBody: [mockLabwareCalibration],
successBody: mockAllLabwareCalibraton,
failureStatus: 500,
failureBody: mockFailureBody,
})
2 changes: 1 addition & 1 deletion app/src/calibration/labware/__tests__/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const SPECS: Array<ActionSpec> = [
type: 'calibration:FETCH_LABWARE_CALIBRATION_SUCCESS',
payload: {
robotName: 'robot-name',
labwareCalibration: [Fixtures.mockLabwareCalibration],
labwareCalibration: Fixtures.mockAllLabwareCalibraton,
},
meta: { requestId: '123' },
},
Expand Down
29 changes: 5 additions & 24 deletions app/src/calibration/labware/__tests__/selectors.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

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

import type { State } from '../../../types'
Expand All @@ -10,42 +11,22 @@ describe('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: null,
labwareCalibration: [Fixtures.mockLabwareCalibration],
calibrationStatus: StatusFixtures.mockCalibrationStatus,
labwareCalibration: Fixtures.mockAllLabwareCalibraton,
},
},
}
expect(
Selectors.getListOfLabwareCalibrations(state, 'robotName')
).toEqual([Fixtures.mockLabwareCalibration])
).toEqual(Fixtures.mockAllLabwareCalibraton.data)
})
})
})

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

// it('should return the single labware', () => {
// const state: $Shape<State> = {
// calibration: {
// robotName: { calibrationStatus: Fixtures.mockCalibrationStatus },
// },
// labwareCalibration: {},
// }
// expect(Selectors.getDeckCalibrationStatus(state, 'robotName')).toEqual(
// Fixtures.mockCalibrationStatus.deckCalibration.status
// )
// })
// })
// })
19 changes: 0 additions & 19 deletions app/src/calibration/labware/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@ export const fetchAllLabwareCalibrations = (
meta: {},
})

export const fetchSingleLabwareCalibration = (
robotName: string,
calibrationId: string
): Types.FetchSingleLabwareCalibrationAction => ({
type: Constants.FETCH_SINGLE_LABWARE_CALIBRATION,
payload: { robotName, calibrationId },
meta: {},
})

export const fetchSingleLabwareCalibrationSuccess = (
robotName: string,
labwareCalibration: APITypes.LabwareCalibrationObjects,
meta: RobotApiRequestMeta
): Types.FetchSingleLabwareCalibrationSuccessAction => ({
type: Constants.FETCH_LABWARE_CALIBRATION_SUCCESS,
payload: { robotName, labwareCalibration },
meta,
})

export const fetchLabwareCalibrationSuccess = (
robotName: string,
labwareCalibration: APITypes.AllLabwareCalibrations,
Expand Down
2 changes: 0 additions & 2 deletions app/src/calibration/labware/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export const LABWARE_CALIBRATION_PATH: '/labware/calibrations' =

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

export const FETCH_LABWARE_CALIBRATION_SUCCESS: 'calibration:FETCH_LABWARE_CALIBRATION_SUCCESS' =
'calibration:FETCH_LABWARE_CALIBRATION_SUCCESS'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { labwareCalibrationEpic } from '..'

const makeTriggerActionAllCalibrations = robotName =>
Actions.fetchAllLabwareCalibrations(robotName)
const makeTriggerActionSingleCalibrations = robotName =>
Actions.fetchSingleLabwareCalibration(robotName)

describe('fetch labware calibration epics', () => {
afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import type { FetchLabwareCalibrationAction } from '../types'

const mapActionToRequest: ActionToRequestMapper<FetchLabwareCalibrationAction> = action => {
// $FlowFixMe(lc, 2020-07-08): lodash flow types do not support keys with values of different types
const queryDict = omitBy(action.payload, isEmpty)
const payloadWithoutRobot = omitBy(action.payload, function(value, key) {
return key === 'robotName'
})
// $FlowFixMe(lc, 2020-07-08): lodash flow types do not support keys with values of different types
const queryDict = omitBy(payloadWithoutRobot, isEmpty)

return {
method: GET,
path: Constants.LABWARE_CALIBRATION_PATH,
Expand Down

This file was deleted.

4 changes: 1 addition & 3 deletions app/src/calibration/labware/epic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import { combineEpics } from 'redux-observable'
import { fetchAllLabwareCalibrationEpic } from './fetchAllLabwareCalibrationEpic'
import { fetchSingleLabwareCalibrationEpic } from './fetchSingleLabwareCalibrationEpic'

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

export const labwareCalibrationEpic: Epic = combineEpics(
fetchAllLabwareCalibrationEpic,
fetchSingleLabwareCalibrationEpic
fetchAllLabwareCalibrationEpic
)
26 changes: 1 addition & 25 deletions app/src/calibration/labware/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import type {

import typeof {
FETCH_ALL_LABWARE_CALIBRATIONS,
FETCH_SINGLE_LABWARE_CALIBRATION,
FETCH_LABWARE_CALIBRATION_SUCCESS,
FETCH_LABWARE_CALIBRATION_FAILURE,
} from './constants'

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

export type FetchLabwareCalibrationAction = {|
type: FETCH_ALL_LABWARE_CALIBRATIONS,
Expand All @@ -28,15 +24,6 @@ export type FetchLabwareCalibrationAction = {|
meta: RobotApiRequestMeta,
|}

export type FetchSingleLabwareCalibrationAction = {|
type: FETCH_SINGLE_LABWARE_CALIBRATION,
payload: {|
robotName: string,
calibrationId: string,
|},
meta: RobotApiRequestMeta,
|}

export type FetchAllLabwareCalibrationSuccessAction = {|
type: FETCH_LABWARE_CALIBRATION_SUCCESS,
payload: {|
Expand All @@ -46,15 +33,6 @@ export type FetchAllLabwareCalibrationSuccessAction = {|
meta: RobotApiRequestMeta,
|}

export type FetchSingleLabwareCalibrationSuccessAction = {|
type: FETCH_LABWARE_CALIBRATION_SUCCESS,
payload: {|
robotName: string,
labwareCalibration: LabwareCalibrationObjects,
|},
meta: RobotApiRequestMeta,
|}

export type FetchLabwareCalibrationFailureAction = {|
type: FETCH_LABWARE_CALIBRATION_FAILURE,
payload: {| robotName: string, error: RobotApiErrorResponse |},
Expand All @@ -63,7 +41,5 @@ export type FetchLabwareCalibrationFailureAction = {|

export type LawareCalibrationAction =
| FetchLabwareCalibrationAction
| FetchSingleLabwareCalibrationAction
| FetchAllLabwareCalibrationSuccessAction
| FetchSingleLabwareCalibrationSuccessAction
| FetchLabwareCalibrationFailureAction
9 changes: 6 additions & 3 deletions app/src/components/FileInfo/ProtocolLabwareList.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ export function ProtocolLabwareList({
const [targetProps, tooltipProps] = useHoverTooltip({
placement: TOOLTIP_AUTO,
})
const iconComponent = <Icon name="information" className={styles.info_icon} />
const iconComponent = (
<Icon name="information" className={styles.calibration_data_info_icon} />
)
const toolTipComponent = (
<Tooltip {...tooltipProps}>
{'calibrated offset from labware origin point'}
</Tooltip>
)

return (
<Flex
textAlign={DIRECTION_COLUMN}
Expand All @@ -64,8 +67,8 @@ export function ProtocolLabwareList({
toolTipComponent={toolTipComponent}
toolTipProps={targetProps}
>
<table>
<tbody borderSpacing={SPACING_1}>{calibration}</tbody>
<table style={{ borderSpacing: { SPACING_1 } }}>
<tbody>{calibration}</tbody>
</table>
</SectionContentFlex>
</Flex>
Expand Down
63 changes: 57 additions & 6 deletions app/src/components/FileInfo/__tests__/continue.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
// @flow
import * as React from 'react'
import { Provider } from 'react-redux'
import { mount } from 'enzyme'

import { getCalibrateLocation, getRunLocation } from '../../../nav'
import { PrimaryButton } from '@opentrons/components'
import { Continue } from '../Continue'

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

jest.mock('../../nav')

const mockGetCalNavigation: JestMockFn<
[State],
$Call<typeof getCalibrateLocation, State>
> = getCalibrateLocation

const mockGetRunNavigation: JestMockFn<
[State],
$Call<typeof getRunLocation, State>
> = getRunLocation

const mockRunPath = '/path/to/run'
const mockCalPath = '/path/to/cal'

describe('Continue to run or calibration button component', () => {
const render = (status: boolean = false) => {
return mount(<Continue labwareCalibrated={status} />)
let mockStore
let render

const CALIBRATE_SELECTOR = {
id: 'calibrate',
path: mockCalPath,
title: 'CALIBRATE',
iconName: 'ot-calibrate',
disabledReason: null,
}

const RUN_SELECTOR = {
id: 'run',
path: mockRunPath,
title: 'RUN',
iconName: 'ot-run',
disabledReason: null,
}

beforeEach(() => {
mockGetCalNavigation.mockReturnValue(CALIBRATE_SELECTOR)
mockGetRunNavigation.mockReturnValue(RUN_SELECTOR)

mockStore = {
subscribe: () => {},
getState: () => ({ state: true }),
dispatch: jest.fn(),
}
render = (labwareCalibrated: boolean = false) =>
mount(
<Provider store={mockStore}>
<Continue labwareCalibrated={labwareCalibrated} />
</Provider>
)
})

it('Default button renders to continue to labware when not all labware is calibrated', () => {
const wrapper = render()
const button = wrapper.find(PrimaryButton)
console.log(button)
expect(button.children).toEqual('Proceed to Calibrate')
expect(wrapper.children).toEqual('Proceed to Calibrate')
expect(button.props.path).toEqual(mockCalPath)
})

it('renders nothing when calibration is OK', () => {
const wrapper = render(true)
const button = wrapper.find(PrimaryButton)
console.log(button.children)
expect(button.children).toEqual('Proceed to Calibrate')
expect(wrapper.children).toEqual('Proceed to Run')
expect(button.props.path).toEqual(mockRunPath)
})
})
Loading

0 comments on commit 530d447

Please sign in to comment.