-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(app): Migrate error recovery utils (#15281)
Works toward EXEC-424. Split up error recovery utils into separate files.
- Loading branch information
Showing
15 changed files
with
256 additions
and
218 deletions.
There are no files selected for viewing
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
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
12 changes: 12 additions & 0 deletions
12
app/src/organisms/ErrorRecoveryFlows/utils/__tests__/getErrorKind.test.ts
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,12 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { ERROR_KINDS } from '../../constants' | ||
import { getErrorKind } from '../getErrorKind' | ||
|
||
describe('getErrorKind', () => { | ||
it(`returns ${ERROR_KINDS.GENERAL_ERROR} if the errorType isn't handled explicitly`, () => { | ||
const mockErrorType = 'NON_HANDLED_ERROR' | ||
const result = getErrorKind(mockErrorType) | ||
expect(result).toEqual(ERROR_KINDS.GENERAL_ERROR) | ||
}) | ||
}) |
100 changes: 100 additions & 0 deletions
100
app/src/organisms/ErrorRecoveryFlows/utils/__tests__/useCurrentlyRecoveringFrom.test.ts
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,100 @@ | ||
import { vi, describe, it, expect } from 'vitest' | ||
import { renderHook } from '@testing-library/react' | ||
|
||
import { useCommandQuery } from '@opentrons/react-api-client' | ||
import { | ||
RUN_STATUS_AWAITING_RECOVERY, | ||
RUN_STATUS_IDLE, | ||
} from '@opentrons/api-client' | ||
|
||
import { useNotifyAllCommandsQuery } from '../../../../resources/runs' | ||
import { useCurrentlyRecoveringFrom } from '../useCurrentlyRecoveringFrom' | ||
|
||
vi.mock('@opentrons/react-api-client') | ||
vi.mock('../../../../resources/runs') | ||
|
||
const MOCK_RUN_ID = 'runId' | ||
const MOCK_COMMAND_ID = 'commandId' | ||
|
||
describe('useCurrentlyRecoveringFrom', () => { | ||
it('disables all queries if the run is not awaiting-recovery', () => { | ||
vi.mocked(useNotifyAllCommandsQuery).mockReturnValue({ | ||
data: { | ||
links: { | ||
currentlyRecoveringFrom: { | ||
meta: { | ||
runId: MOCK_RUN_ID, | ||
commandId: MOCK_COMMAND_ID, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as any) | ||
vi.mocked(useCommandQuery).mockReturnValue({ | ||
data: { data: 'mockCommandDetails' }, | ||
} as any) | ||
|
||
const { result } = renderHook(() => | ||
useCurrentlyRecoveringFrom(MOCK_RUN_ID, RUN_STATUS_IDLE) | ||
) | ||
|
||
expect(vi.mocked(useNotifyAllCommandsQuery)).toHaveBeenCalledWith( | ||
MOCK_RUN_ID, | ||
{ cursor: null, pageLength: 0 }, | ||
{ enabled: false, refetchInterval: 5000 } | ||
) | ||
expect(vi.mocked(useCommandQuery)).toHaveBeenCalledWith( | ||
MOCK_RUN_ID, | ||
MOCK_COMMAND_ID, | ||
{ enabled: false } | ||
) | ||
expect(result.current).toStrictEqual(null) | ||
}) | ||
|
||
it('returns null if there is no currentlyRecoveringFrom command', () => { | ||
vi.mocked(useNotifyAllCommandsQuery).mockReturnValue({ | ||
data: { | ||
links: {}, | ||
}, | ||
} as any) | ||
vi.mocked(useCommandQuery).mockReturnValue({} as any) | ||
|
||
const { result } = renderHook(() => | ||
useCurrentlyRecoveringFrom(MOCK_RUN_ID, RUN_STATUS_AWAITING_RECOVERY) | ||
) | ||
|
||
expect(vi.mocked(useCommandQuery)).toHaveBeenCalledWith(null, null, { | ||
enabled: false, | ||
}) | ||
expect(result.current).toStrictEqual(null) | ||
}) | ||
|
||
it('fetches and returns the currentlyRecoveringFrom command, given that there is one', () => { | ||
vi.mocked(useNotifyAllCommandsQuery).mockReturnValue({ | ||
data: { | ||
links: { | ||
currentlyRecoveringFrom: { | ||
meta: { | ||
runId: MOCK_RUN_ID, | ||
commandId: MOCK_COMMAND_ID, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as any) | ||
vi.mocked(useCommandQuery).mockReturnValue({ | ||
data: { data: 'mockCommandDetails' }, | ||
} as any) | ||
|
||
const { result } = renderHook(() => | ||
useCurrentlyRecoveringFrom(MOCK_RUN_ID, RUN_STATUS_AWAITING_RECOVERY) | ||
) | ||
|
||
expect(vi.mocked(useCommandQuery)).toHaveBeenCalledWith( | ||
MOCK_RUN_ID, | ||
MOCK_COMMAND_ID, | ||
{ enabled: true } | ||
) | ||
expect(result.current).toStrictEqual('mockCommandDetails') | ||
}) | ||
}) |
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.