Skip to content

Commit

Permalink
add useFeatureFlag and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Jun 26, 2024
1 parent 03d4b1e commit 2a6a8da
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import { renderWithProviders } from '../../../__testing-utils__'
import { ProtocolSetupParameters } from '..'
import { ChooseEnum } from '../ChooseEnum'
import { mockRunTimeParameterData } from '../../../pages/ProtocolDetails/fixtures'
import { useFeatureFlag } from '../../../redux/config'

import type * as ReactRouterDom from 'react-router-dom'
import type { HostConfig } from '@opentrons/api-client'
import type {
CompletedProtocolAnalysis,
RunTimeParameter,
} from '@opentrons/shared-data'

const mockGoBack = vi.fn()

Expand All @@ -27,16 +33,24 @@ vi.mock('react-router-dom', async importOriginal => {
useHistory: () => ({ goBack: mockGoBack } as any),
}
})
vi.mock('../../../redux/config')

const MOCK_HOST_CONFIG: HostConfig = { hostname: 'MOCK_HOST' }
const mockCreateProtocolAnalysis = vi.fn()
const mockCreateRun = vi.fn()
const mockMostRecentAnalysis = ({
commands: [],
labware: [],
} as unknown) as CompletedProtocolAnalysis

const render = (
props: React.ComponentProps<typeof ProtocolSetupParameters>
) => {
return renderWithProviders(<ProtocolSetupParameters {...props} />, {
i18nInstance: i18n,
})
}

describe('ProtocolSetupParameters', () => {
let props: React.ComponentProps<typeof ProtocolSetupParameters>

Expand All @@ -45,6 +59,7 @@ describe('ProtocolSetupParameters', () => {
protocolId: 'mockId',
labwareOffsets: [],
runTimeParameters: mockRunTimeParameterData,
mostRecentAnalysis: mockMostRecentAnalysis,
}
vi.mocked(ChooseEnum).mockReturnValue(<div>mock ChooseEnum</div>)
vi.mocked(useHost).mockReturnValue(MOCK_HOST_CONFIG)
Expand All @@ -54,6 +69,9 @@ describe('ProtocolSetupParameters', () => {
when(vi.mocked(useCreateRunMutation))
.calledWith(expect.anything())
.thenReturn({ createRun: mockCreateRun } as any)
when(vi.mocked(useFeatureFlag))
.calledWith('enableCsvFile')
.thenReturn(false)
})

it('renders the parameters labels and mock data', () => {
Expand Down Expand Up @@ -109,4 +127,36 @@ describe('ProtocolSetupParameters', () => {
fireEvent.click(screen.getByRole('button', { name: 'Go back' }))
expect(title).not.toBeInTheDocument()
})

it('render csv file when a protocol requires a csv file', () => {
when(vi.mocked(useFeatureFlag)).calledWith('enableCsvFile').thenReturn(true)
const mockMostRecentAnalysisForCsv = ({
commands: [],
labware: [],
result: 'parameter-value-required',
} as unknown) as CompletedProtocolAnalysis
const mockCSVData = {
file: { id: 'test', file: { name: 'mock.csv' } as File },
displayName: 'My CSV File',
variableName: 'CSVFILE',
description: 'CSV File for a protocol',
type: 'csv_file' as const,
} as RunTimeParameter
const mockRunTimeParameterDataForCsv = [
...mockRunTimeParameterData,
mockCSVData,
]

render({
...props,
runTimeParameters: mockRunTimeParameterDataForCsv,
mostRecentAnalysis: mockMostRecentAnalysisForCsv,
})
screen.getByText('CSV File')
screen.getByText('Required')
})

it.todo(
'render csv file name when a protocol analysis result is not parameter-value-required'
)
})
13 changes: 11 additions & 2 deletions app/src/organisms/ProtocolSetupParameters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import { ChildNavigation } from '../ChildNavigation'
import { ResetValuesModal } from './ResetValuesModal'
import { ChooseEnum } from './ChooseEnum'
import { ChooseNumber } from './ChooseNumber'
import { useFeatureFlag } from '../../redux/config'

import type {
CompletedProtocolAnalysis,
ChoiceParameter,
NumberParameter,
RunTimeParameter,
Expand All @@ -37,14 +39,17 @@ interface ProtocolSetupParametersProps {
protocolId: string
runTimeParameters: RunTimeParameter[]
labwareOffsets?: LabwareOffsetCreateData[]
mostRecentAnalysis?: CompletedProtocolAnalysis | null
}

export function ProtocolSetupParameters({
protocolId,
labwareOffsets,
runTimeParameters,
mostRecentAnalysis,
}: ProtocolSetupParametersProps): JSX.Element {
const { t } = useTranslation('protocol_setup')
const enableCsvFile = useFeatureFlag('enableCsvFile')
const history = useHistory()
const host = useHost()
const queryClient = useQueryClient()
Expand Down Expand Up @@ -184,7 +189,9 @@ export function ProtocolSetupParameters({
hasRightIcon={!(parameter.type === 'bool')}
hasLeftIcon={false}
status={
parameter.type === 'csv_file' ? 'not ready' : 'inform'
enableCsvFile && parameter.type === 'csv_file'
? 'not ready'
: 'inform'
}
title={
parameter.type === 'csv_file'
Expand All @@ -195,7 +202,9 @@ export function ProtocolSetupParameters({
handleSetParameter(parameter)
}}
detail={
parameter.type === 'csv_file'
enableCsvFile && // ToDo this line will be removed
parameter.type === 'csv_file' &&
mostRecentAnalysis?.result === 'parameter-value-required'
? t('required')
: formatRunTimeParameterValue(parameter, t)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/pages/ProtocolDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ export function ProtocolDetails(): JSX.Element | null {
protocolId={protocolId}
labwareOffsets={labwareOffsets}
runTimeParameters={runTimeParameters}
mostRecentAnalysis={mostRecentAnalysis}
/>
) : (
<>
Expand Down

0 comments on commit 2a6a8da

Please sign in to comment.