-
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.
refactor(app): update H-S running modal command to stop active H-S mo…
…dules (#11244) * refactor(app): update H-S running modal command to stop active H-S modules This PR will use the HS running modal before starting a run to stop all active heater shakes. It also fixes a bug where the wrong heater shaker was rendered when opening the wizard from the setup page. closes #11194
- Loading branch information
Showing
11 changed files
with
378 additions
and
69 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
app/src/organisms/Devices/HeaterShakerIsRunningModal/__tests__/hooks.test.tsx
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,153 @@ | ||
import * as React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { createStore } from 'redux' | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import { HEATERSHAKER_MODULE_V1 } from '@opentrons/shared-data' | ||
import { useProtocolDetailsForRun } from '../../hooks' | ||
import { useHeaterShakerModuleIdsFromRun } from '../hooks' | ||
import { RUN_ID_1 } from '../../../RunTimeControl/__fixtures__' | ||
|
||
import type { Store } from 'redux' | ||
import type { State } from '../../../../redux/types' | ||
|
||
jest.mock('../../hooks') | ||
|
||
const mockUseProtocolDetailsForRun = useProtocolDetailsForRun as jest.MockedFunction< | ||
typeof useProtocolDetailsForRun | ||
> | ||
|
||
describe('useHeaterShakerModuleIdsFromRun', () => { | ||
const store: Store<State> = createStore(jest.fn(), {}) | ||
|
||
beforeEach(() => { | ||
store.dispatch = jest.fn() | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should return a heater shaker module id from protocol analysis load command result', () => { | ||
mockUseProtocolDetailsForRun.mockReturnValue({ | ||
protocolData: { | ||
pipettes: {}, | ||
labware: {}, | ||
modules: { | ||
heatershaker_id: { | ||
model: HEATERSHAKER_MODULE_V1, | ||
}, | ||
}, | ||
labwareDefinitions: {}, | ||
commands: [ | ||
{ | ||
id: 'mock_command_1', | ||
createdAt: '2022-07-27T22:26:33.846399+00:00', | ||
commandType: 'loadModule', | ||
key: '286d7201-bfdc-4c2c-ae67-544367dbbabe', | ||
status: 'succeeded', | ||
params: { | ||
model: HEATERSHAKER_MODULE_V1, | ||
location: { | ||
slotName: '1', | ||
}, | ||
moduleId: 'heatershaker_id', | ||
}, | ||
result: { | ||
moduleId: 'heatershaker_id', | ||
definition: {}, | ||
model: HEATERSHAKER_MODULE_V1, | ||
serialNumber: 'fake-serial-number-1', | ||
}, | ||
startedAt: '2022-07-27T22:26:33.875106+00:00', | ||
completedAt: '2022-07-27T22:26:33.878079+00:00', | ||
}, | ||
], | ||
}, | ||
} as any) | ||
const wrapper: React.FunctionComponent<{}> = ({ children }) => ( | ||
<Provider store={store}>{children}</Provider> | ||
) | ||
const { result } = renderHook( | ||
() => useHeaterShakerModuleIdsFromRun(RUN_ID_1), | ||
{ wrapper } | ||
) | ||
|
||
const moduleIdsFromRun = result.current | ||
expect(moduleIdsFromRun.moduleIdsFromRun).toStrictEqual(['heatershaker_id']) | ||
}) | ||
|
||
it('should return two heater shaker module ids if two modules are loaded in the protocol', () => { | ||
mockUseProtocolDetailsForRun.mockReturnValue({ | ||
protocolData: { | ||
pipettes: {}, | ||
labware: {}, | ||
modules: { | ||
heatershaker_id: { | ||
model: HEATERSHAKER_MODULE_V1, | ||
}, | ||
}, | ||
labwareDefinitions: {}, | ||
commands: [ | ||
{ | ||
id: 'mock_command_1', | ||
createdAt: '2022-07-27T22:26:33.846399+00:00', | ||
commandType: 'loadModule', | ||
key: '286d7201-bfdc-4c2c-ae67-544367dbbabe', | ||
status: 'succeeded', | ||
params: { | ||
model: HEATERSHAKER_MODULE_V1, | ||
location: { | ||
slotName: '1', | ||
}, | ||
moduleId: 'heatershaker_id_1', | ||
}, | ||
result: { | ||
moduleId: 'heatershaker_id_1', | ||
definition: {}, | ||
model: HEATERSHAKER_MODULE_V1, | ||
serialNumber: 'fake-serial-number-1', | ||
}, | ||
startedAt: '2022-07-27T22:26:33.875106+00:00', | ||
completedAt: '2022-07-27T22:26:33.878079+00:00', | ||
}, | ||
{ | ||
id: 'mock_command_2', | ||
createdAt: '2022-07-27T22:26:33.846399+00:00', | ||
commandType: 'loadModule', | ||
key: '286d7201-bfdc-4c2c-ae67-544367dbbabe', | ||
status: 'succeeded', | ||
params: { | ||
model: HEATERSHAKER_MODULE_V1, | ||
location: { | ||
slotName: '1', | ||
}, | ||
moduleId: 'heatershaker_id_2', | ||
}, | ||
result: { | ||
moduleId: 'heatershaker_id_2', | ||
definition: {}, | ||
model: 'heaterShakerModuleV1_2', | ||
serialNumber: 'fake-serial-number-2', | ||
}, | ||
startedAt: '2022-07-27T22:26:33.875106+00:00', | ||
completedAt: '2022-07-27T22:26:33.878079+00:00', | ||
}, | ||
], | ||
}, | ||
} as any) | ||
|
||
const wrapper: React.FunctionComponent<{}> = ({ children }) => ( | ||
<Provider store={store}>{children}</Provider> | ||
) | ||
const { result } = renderHook( | ||
() => useHeaterShakerModuleIdsFromRun(RUN_ID_1), | ||
{ wrapper } | ||
) | ||
|
||
const moduleIdsFromRun = result.current | ||
expect(moduleIdsFromRun.moduleIdsFromRun).toStrictEqual([ | ||
'heatershaker_id_1', | ||
'heatershaker_id_2', | ||
]) | ||
}) | ||
}) |
24 changes: 24 additions & 0 deletions
24
app/src/organisms/Devices/HeaterShakerIsRunningModal/hooks.tsx
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,24 @@ | ||
import { useProtocolDetailsForRun } from '../hooks' | ||
|
||
export interface ModuleIdsFromRun { | ||
moduleIdsFromRun: string[] | ||
} | ||
|
||
export function useHeaterShakerModuleIdsFromRun( | ||
runId: string | null | ||
): ModuleIdsFromRun { | ||
const { protocolData } = useProtocolDetailsForRun(runId) | ||
|
||
const loadModuleCommands = protocolData?.commands.filter( | ||
command => | ||
command.commandType === 'loadModule' && | ||
command.params.model === 'heaterShakerModuleV1' | ||
) | ||
|
||
const moduleIdsFromRun = | ||
loadModuleCommands != null | ||
? loadModuleCommands?.map(command => command.result.moduleId) | ||
: [] | ||
|
||
return { moduleIdsFromRun } | ||
} |
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
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.