Skip to content

Commit

Permalink
fix(app): invalidate OT2 calibration queries when calibration flows c…
Browse files Browse the repository at this point in the history
…omplete (#13809)

Ensure that all queries for /calibration endpoints (OT2 only) are invalidated upon completion of any
of the three OT2 calibration flows.

Closes RQA-1814

Co-authored-by: Shlok Amin <[email protected]>
  • Loading branch information
b-cooper and shlokamin authored Oct 18, 2023
1 parent 855ec92 commit 692888c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app/src/organisms/CalibrateDeck/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Deck Calibration Orchestration Component
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useQueryClient } from 'react-query'

import { useHost } from '@opentrons/react-api-client'
import { getPipetteModelSpecs } from '@opentrons/shared-data'
import { useConditionalConfirm } from '@opentrons/components'

Expand Down Expand Up @@ -71,6 +73,9 @@ export function CalibrateDeck(
const { currentStep, instrument, labware, supportedCommands } =
session?.details || {}

const queryClient = useQueryClient()
const host = useHost()

const {
showConfirmation: showConfirmExit,
confirm: confirmExit,
Expand All @@ -97,6 +102,11 @@ export function CalibrateDeck(
}

function cleanUpAndExit(): void {
queryClient
.invalidateQueries([host, 'calibration'])
.catch((e: Error) =>
console.error(`error invalidating calibration queries: ${e.message}`)

Check warning on line 108 in app/src/organisms/CalibrateDeck/index.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/CalibrateDeck/index.tsx#L108

Added line #L108 was not covered by tests
)
if (
exitBeforeDeckConfigCompletion &&
currentStep !== Sessions.DECK_STEP_CALIBRATION_COMPLETE
Expand Down
10 changes: 10 additions & 0 deletions app/src/organisms/CalibratePipetteOffset/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Pipette Offset Calibration Orchestration Component
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useQueryClient } from 'react-query'

import { useHost } from '@opentrons/react-api-client'
import { getPipetteModelSpecs } from '@opentrons/shared-data'
import { useConditionalConfirm } from '@opentrons/components'

Expand Down Expand Up @@ -60,6 +62,9 @@ export function CalibratePipetteOffset(
const { currentStep, instrument, labware, supportedCommands } =
session?.details ?? {}

const queryClient = useQueryClient()
const host = useHost()

const {
showConfirmation: showConfirmExit,
confirm: confirmExit,
Expand Down Expand Up @@ -92,6 +97,11 @@ export function CalibratePipetteOffset(
}

function cleanUpAndExit(): void {
queryClient
.invalidateQueries([host, 'calibration'])
.catch((e: Error) =>
console.error(`error invalidating calibration queries: ${e.message}`)

Check warning on line 103 in app/src/organisms/CalibratePipetteOffset/index.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/CalibratePipetteOffset/index.tsx#L103

Added line #L103 was not covered by tests
)
if (session?.id != null) {
dispatchRequests(
Sessions.createSessionCommand(robotName, session.id, {
Expand Down
10 changes: 10 additions & 0 deletions app/src/organisms/CalibrateTipLength/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Tip Length Calibration Orchestration Component
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useQueryClient } from 'react-query'
import { css } from 'styled-components'

import { useHost } from '@opentrons/react-api-client'
import { getPipetteModelSpecs } from '@opentrons/shared-data'
import { useConditionalConfirm } from '@opentrons/components'

Expand Down Expand Up @@ -72,6 +74,9 @@ export function CalibrateTipLength(
} = props
const { currentStep, instrument, labware } = session?.details ?? {}

const queryClient = useQueryClient()
const host = useHost()

const isMulti = React.useMemo(() => {
const spec =
instrument != null ? getPipetteModelSpecs(instrument.model) : null
Expand All @@ -96,6 +101,11 @@ export function CalibrateTipLength(
}

function cleanUpAndExit(): void {
queryClient
.invalidateQueries([host, 'calibration'])
.catch((e: Error) =>
console.error(`error invalidating calibration queries: ${e.message}`)

Check warning on line 107 in app/src/organisms/CalibrateTipLength/index.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/CalibrateTipLength/index.tsx#L107

Added line #L107 was not covered by tests
)
if (session?.id != null) {
dispatchRequests(
Sessions.createSessionCommand(robotName, session.id, {
Expand Down
7 changes: 6 additions & 1 deletion components/src/testing/utils/mountWithProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'assert'
import * as React from 'react'
import { I18nextProvider } from 'react-i18next'
import { Provider } from 'react-redux'
import { QueryClient, QueryClientProvider } from 'react-query'
import { mount } from 'enzyme'

import type { Store } from 'redux'
Expand Down Expand Up @@ -33,6 +34,8 @@ export function mountWithProviders<Element, State, Action>(
dispatch: jest.fn(),
}

const queryClient = new QueryClient()

Check warning on line 37 in components/src/testing/utils/mountWithProviders.tsx

View check run for this annotation

Codecov / codecov/patch

components/src/testing/utils/mountWithProviders.tsx#L37

Added line #L37 was not covered by tests

const I18nWrapper: React.ElementType<
React.ComponentProps<typeof I18nextProvider>
> = provideI18n
Expand Down Expand Up @@ -67,7 +70,9 @@ export function mountWithProviders<Element, State, Action>(
i18n: React.ComponentProps<typeof I18nextProvider>['i18n']
}): JSX.Element => (
<StateWrapper store={store}>
<I18nWrapper i18n={i18n}>{children}</I18nWrapper>
<QueryClientProvider client={queryClient}>
<I18nWrapper i18n={i18n}>{children}</I18nWrapper>
</QueryClientProvider>
</StateWrapper>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from 'assert'
import * as React from 'react'
import { Provider } from 'react-redux'
import { QueryClient, QueryClientProvider } from 'react-query'
import { mount } from 'enzyme'

import type { ReactWrapper } from 'enzyme'
Expand Down Expand Up @@ -35,9 +36,27 @@ export function mountWithStore<Props, State = {}, Action = {}>(
dispatch: jest.fn(),
}

const queryClient = new QueryClient()

Check warning on line 39 in components/src/testing/utils/mountWithStore.tsx

View check run for this annotation

Codecov / codecov/patch

components/src/testing/utils/mountWithStore.tsx#L39

Added line #L39 was not covered by tests

const BaseProviders = ({

Check warning on line 41 in components/src/testing/utils/mountWithStore.tsx

View check run for this annotation

Codecov / codecov/patch

components/src/testing/utils/mountWithStore.tsx#L41

Added line #L41 was not covered by tests
children,
store,
queryClient,
}: {
children: React.ReactNode
store: any
queryClient: any
}): JSX.Element => {
return (

Check warning on line 50 in components/src/testing/utils/mountWithStore.tsx

View check run for this annotation

Codecov / codecov/patch

components/src/testing/utils/mountWithStore.tsx#L50

Added line #L50 was not covered by tests
<QueryClientProvider client={queryClient}>
<Provider store={store as any}>{children}</Provider>
</QueryClientProvider>
)
}

const wrapper = mount<Props>(node, {
wrappingComponent: Provider,
wrappingComponentProps: { store },
wrappingComponent: BaseProviders,
wrappingComponentProps: { store, queryClient },
})

// force a re-render by returning a new state to recalculate selectors
Expand Down
13 changes: 7 additions & 6 deletions components/src/testing/utils/renderWithProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ export function renderWithProviders<State>(
const ProviderWrapper: React.ComponentType<React.PropsWithChildren<{}>> = ({
children,
}) => {
const BaseWrapper = (
<QueryClientProvider client={queryClient}>
<Provider store={store}>{children}</Provider>
</QueryClientProvider>
)
if (i18nInstance != null) {
return (
<I18nextProvider i18n={i18nInstance}>
<QueryClientProvider client={queryClient}>
<Provider store={store}>{children}</Provider>
</QueryClientProvider>
</I18nextProvider>
<I18nextProvider i18n={i18nInstance}>{BaseWrapper}</I18nextProvider>
)
} else {
return <Provider store={store}>{children}</Provider>
return BaseWrapper
}
}

Expand Down

0 comments on commit 692888c

Please sign in to comment.