-
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.
feat(app): update pipette attach flow to include calibration (#6760)
When attaching a pipette, if you do not currently have a pipette offset calibration stored for that combination of pipette serial number and mount, attach pipette flow will directly feed into the pipette offset calibration flow (which may also include tip length cal for the tip used in pipette offset cal) Closes #2130
- Loading branch information
Showing
10 changed files
with
365 additions
and
111 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
app/src/components/CalibratePipetteOffset/__tests__/useCalibratePipetteOffset.test.js
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,130 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import uniqueId from 'lodash/uniqueId' | ||
import { mountWithStore } from '@opentrons/components/__utils__' | ||
import { act } from 'react-dom/test-utils' | ||
|
||
import * as RobotApi from '../../../robot-api' | ||
import * as Sessions from '../../../sessions' | ||
import { mockPipetteOffsetCalibrationSessionAttributes } from '../../../sessions/__fixtures__' | ||
|
||
import { useCalibratePipetteOffset } from '../useCalibratePipetteOffset' | ||
|
||
import type { State } from '../../../types' | ||
import type { SessionType } from '../../../sessions' | ||
|
||
jest.mock('../../../sessions/selectors') | ||
jest.mock('../../../robot-api/selectors') | ||
jest.mock('lodash/uniqueId') | ||
|
||
const mockUniqueId: JestMockFn<[string | void], string> = uniqueId | ||
const mockGetRobotSessionOfType: JestMockFn< | ||
[State, string, SessionType], | ||
$Call<typeof Sessions.getRobotSessionOfType, State, string, SessionType> | ||
> = Sessions.getRobotSessionOfType | ||
const mockGetRequestById: JestMockFn< | ||
[State, string], | ||
$Call<typeof RobotApi.getRequestById, State, string> | ||
> = RobotApi.getRequestById | ||
|
||
describe('useCalibratePipetteOffset hook', () => { | ||
let startCalibration | ||
let CalWizardComponent | ||
const robotName = 'robotName' | ||
const mountString = 'left' | ||
const onComplete = jest.fn() | ||
|
||
const TestUseCalibratePipetteOffset = () => { | ||
const [_startCalibration, _CalWizardComponent] = useCalibratePipetteOffset( | ||
robotName, | ||
{ | ||
mount: mountString, | ||
shouldRecalibrateTipLength: false, | ||
hasCalibrationBlock: false, | ||
tipRackDefinition: null, | ||
}, | ||
onComplete | ||
) | ||
React.useEffect(() => { | ||
startCalibration = _startCalibration | ||
CalWizardComponent = _CalWizardComponent | ||
}) | ||
return <>{CalWizardComponent}</> | ||
} | ||
|
||
beforeEach(() => { | ||
let mockIdCounter = 0 | ||
mockUniqueId.mockImplementation(() => `mockId_${mockIdCounter++}`) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('returns start callback, and no wizard if session not present', () => { | ||
const { store } = mountWithStore(<TestUseCalibratePipetteOffset />, { | ||
initialState: { robotApi: {}, sessions: {} }, | ||
}) | ||
expect(typeof startCalibration).toBe('function') | ||
expect(CalWizardComponent).toBe(null) | ||
|
||
act(() => startCalibration()) | ||
|
||
expect(store.dispatch).toHaveBeenCalledWith({ | ||
...Sessions.ensureSession( | ||
robotName, | ||
Sessions.SESSION_TYPE_PIPETTE_OFFSET_CALIBRATION, | ||
{ | ||
mount: mountString, | ||
shouldRecalibrateTipLength: false, | ||
hasCalibrationBlock: false, | ||
tipRackDefinition: null, | ||
} | ||
), | ||
meta: { requestId: expect.any(String) }, | ||
}) | ||
}) | ||
|
||
it('wizard should appear after create request succeeds with session and close on closeWizard', () => { | ||
const seshId = 'fake-session-id' | ||
const mockPipOffsetCalSession = { | ||
id: seshId, | ||
...mockPipetteOffsetCalibrationSessionAttributes, | ||
details: { | ||
...mockPipetteOffsetCalibrationSessionAttributes.details, | ||
currentStep: Sessions.PIP_OFFSET_STEP_CALIBRATION_COMPLETE, | ||
}, | ||
} | ||
const { store, wrapper } = mountWithStore( | ||
<TestUseCalibratePipetteOffset />, | ||
{ | ||
initialState: { robotApi: {} }, | ||
} | ||
) | ||
mockGetRobotSessionOfType.mockReturnValue(mockPipOffsetCalSession) | ||
mockGetRequestById.mockReturnValue({ | ||
status: RobotApi.SUCCESS, | ||
response: { | ||
method: 'POST', | ||
ok: true, | ||
path: '/', | ||
status: 200, | ||
}, | ||
}) | ||
act(() => startCalibration()) | ||
wrapper.setProps({}) | ||
expect(CalWizardComponent).not.toBe(null) | ||
|
||
wrapper | ||
.find('button[title="Return tip to tip rack and exit"]') | ||
.invoke('onClick')() | ||
wrapper.setProps({}) | ||
expect(store.dispatch).toHaveBeenCalledWith({ | ||
...Sessions.deleteSession(robotName, seshId), | ||
meta: { requestId: expect.any(String) }, | ||
}) | ||
wrapper.setProps({}) // update so delete request can be handled on success | ||
expect(CalWizardComponent).toBe(null) | ||
expect(onComplete).toHaveBeenCalled() | ||
}) | ||
}) |
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
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
Oops, something went wrong.