-
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.
test(protocol-designer): add tests for InitializationSettings and for…
…mToArgs (#17319) Adds a few unit tests for `InitializationSettings` component and `absorbanceReaderFormToArgs` ahead of step generation. Closes AUTH-1316
- Loading branch information
Showing
2 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...lSteps/StepForm/StepTools/AbsorbanceReaderTools/__tests__/InitializationSettings.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,83 @@ | ||
import { screen } from '@testing-library/react' | ||
import { describe, it, expect } from 'vitest' | ||
import { i18n } from '../../../../../../../assets/localization' | ||
import { renderWithProviders } from '../../../../../../../__testing-utils__' | ||
import { InitializationSettings } from '../InitializationSettings' | ||
import type { ComponentProps } from 'react' | ||
import type { Initialization } from '@opentrons/step-generation' | ||
|
||
// Mocking constants | ||
const INITIALIZATION_SINGLE_NO_REFERENCE: Initialization = { | ||
mode: 'single', | ||
wavelengths: [450], | ||
} | ||
const INITIALIZATION_SINGLE_REFERENCE: Initialization = { | ||
mode: 'single', | ||
wavelengths: [450], | ||
referenceWavelength: 600, | ||
} | ||
const INITIALIZATION_MULTI: Initialization = { | ||
mode: 'multi', | ||
wavelengths: [450, 600], | ||
} | ||
const INITIALIZATION_MULTI_UNKOWN_COLOR: Initialization = { | ||
mode: 'multi', | ||
wavelengths: [450, 700], | ||
} | ||
|
||
const render = (props: ComponentProps<typeof InitializationSettings>) => { | ||
return renderWithProviders(<InitializationSettings {...props} />, { | ||
i18nInstance: i18n, | ||
})[0] | ||
} | ||
|
||
describe('InitializationSettings', () => { | ||
let props: ComponentProps<typeof InitializationSettings> | ||
it('renders no settings message when initialization is null', () => { | ||
props = { initialization: null } | ||
render(props) | ||
|
||
expect( | ||
screen.getByText('Current initialization settings') | ||
).toBeInTheDocument() | ||
expect(screen.getByText('No settings defined')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders single mode wavelength and its color correctly', () => { | ||
props = { initialization: INITIALIZATION_SINGLE_NO_REFERENCE } | ||
render(props) | ||
expect( | ||
screen.getByText('Current initialization settings') | ||
).toBeInTheDocument() | ||
expect(screen.getByText('450 nm (Blue)')).toBeInTheDocument() | ||
}) | ||
it('renders single mode wavelength with reference and their respective colors correctly', () => { | ||
props = { initialization: INITIALIZATION_SINGLE_REFERENCE } | ||
render(props) | ||
expect( | ||
screen.getByText('Current initialization settings') | ||
).toBeInTheDocument() | ||
expect(screen.getByText('450 nm (Blue)')).toBeInTheDocument() | ||
expect( | ||
screen.getByText('600 nm (Orange, reference wavelength)') | ||
).toBeInTheDocument() | ||
}) | ||
it('renders multi mode wavelength and their respective colors correctly', () => { | ||
props = { initialization: INITIALIZATION_MULTI } | ||
render(props) | ||
expect( | ||
screen.getByText('Current initialization settings') | ||
).toBeInTheDocument() | ||
expect(screen.getByText('450 nm (Blue)')).toBeInTheDocument() | ||
expect(screen.getByText('600 nm (Orange)')).toBeInTheDocument() | ||
}) | ||
it('renders multi mode wavelength and their respective colors correctly with unkown color', () => { | ||
props = { initialization: INITIALIZATION_MULTI_UNKOWN_COLOR } | ||
render(props) | ||
expect( | ||
screen.getByText('Current initialization settings') | ||
).toBeInTheDocument() | ||
expect(screen.getByText('450 nm (Blue)')).toBeInTheDocument() | ||
expect(screen.getByText('700 nm')).toBeInTheDocument() | ||
}) | ||
}) |
185 changes: 185 additions & 0 deletions
185
...ol-designer/src/steplist/formLevel/stepFormToArgs/test/absorbanceReaderFormToArgs.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,185 @@ | ||
import { it, describe, expect } from 'vitest' | ||
import { absorbanceReaderFormToArgs } from '../absorbanceReaderFormToArgs' | ||
import type { HydratedAbsorbanceReaderFormData } from '../../../../form-types' | ||
|
||
describe('absorbanceReaderFormToArgs', () => { | ||
it('returns absorbance reader initialize command creator for single mode with reference', () => { | ||
const formData: HydratedAbsorbanceReaderFormData = { | ||
absorbanceReaderFormType: 'absorbanceReaderInitialize', | ||
fileName: null, | ||
id: 'stepId', | ||
lidOpen: null, | ||
mode: 'single', | ||
moduleId: 'absorbanceReaderId', | ||
referenceWavelength: '500', | ||
referenceWavelengthActive: true, | ||
stepName: 'absorbance reader step', | ||
stepDetails: '', | ||
stepType: 'absorbanceReader', | ||
wavelengths: ['450'], | ||
} | ||
|
||
const expected = { | ||
moduleId: 'absorbanceReaderId', | ||
commandCreatorFnName: 'absorbanceReaderInitialize', | ||
measureMode: 'single', | ||
sampleWavelengths: [450], | ||
referenceWavelength: 500, | ||
description: '', | ||
name: 'absorbance reader step', | ||
} | ||
expect(absorbanceReaderFormToArgs(formData)).toEqual(expected) | ||
}) | ||
it('returns absorbance reader initialize command creator for single mode with reference, ignorning wavelengths for i > 0', () => { | ||
const formData: HydratedAbsorbanceReaderFormData = { | ||
absorbanceReaderFormType: 'absorbanceReaderInitialize', | ||
fileName: null, | ||
id: 'stepId', | ||
lidOpen: null, | ||
mode: 'single', | ||
moduleId: 'absorbanceReaderId', | ||
referenceWavelength: '500', | ||
referenceWavelengthActive: true, | ||
stepName: 'absorbance reader step', | ||
stepDetails: '', | ||
stepType: 'absorbanceReader', | ||
wavelengths: ['450', '600'], | ||
} | ||
|
||
const expected = { | ||
moduleId: 'absorbanceReaderId', | ||
commandCreatorFnName: 'absorbanceReaderInitialize', | ||
measureMode: 'single', | ||
sampleWavelengths: [450], | ||
referenceWavelength: 500, | ||
description: '', | ||
name: 'absorbance reader step', | ||
} | ||
expect(absorbanceReaderFormToArgs(formData)).toEqual(expected) | ||
}) | ||
it('returns absorbance reader initialize command creator for single mode without reference active', () => { | ||
const formData: HydratedAbsorbanceReaderFormData = { | ||
absorbanceReaderFormType: 'absorbanceReaderInitialize', | ||
fileName: null, | ||
id: 'stepId', | ||
lidOpen: null, | ||
mode: 'single', | ||
moduleId: 'absorbanceReaderId', | ||
referenceWavelength: '500', | ||
referenceWavelengthActive: false, | ||
stepName: 'absorbance reader step', | ||
stepDetails: '', | ||
stepType: 'absorbanceReader', | ||
wavelengths: ['450'], | ||
} | ||
|
||
const expected = { | ||
moduleId: 'absorbanceReaderId', | ||
commandCreatorFnName: 'absorbanceReaderInitialize', | ||
measureMode: 'single', | ||
sampleWavelengths: [450], | ||
description: '', | ||
name: 'absorbance reader step', | ||
} | ||
expect(absorbanceReaderFormToArgs(formData)).toEqual(expected) | ||
}) | ||
it('returns absorbance reader initialize command creator for multi mode', () => { | ||
const formData: HydratedAbsorbanceReaderFormData = { | ||
absorbanceReaderFormType: 'absorbanceReaderInitialize', | ||
fileName: null, | ||
id: 'stepId', | ||
lidOpen: null, | ||
mode: 'multi', | ||
moduleId: 'absorbanceReaderId', | ||
referenceWavelength: null, | ||
referenceWavelengthActive: false, | ||
stepName: 'absorbance reader step', | ||
stepDetails: '', | ||
stepType: 'absorbanceReader', | ||
wavelengths: ['450', '600'], | ||
} | ||
|
||
const expected = { | ||
moduleId: 'absorbanceReaderId', | ||
commandCreatorFnName: 'absorbanceReaderInitialize', | ||
measureMode: 'multi', | ||
sampleWavelengths: [450, 600], | ||
description: '', | ||
name: 'absorbance reader step', | ||
} | ||
expect(absorbanceReaderFormToArgs(formData)).toEqual(expected) | ||
}) | ||
it('returns absorbance reader read command creator', () => { | ||
const formData: HydratedAbsorbanceReaderFormData = { | ||
absorbanceReaderFormType: 'absorbanceReaderRead', | ||
fileName: 'output_path.csv', | ||
id: 'stepId', | ||
lidOpen: null, | ||
mode: 'multi', | ||
moduleId: 'absorbanceReaderId', | ||
referenceWavelength: null, | ||
referenceWavelengthActive: false, | ||
stepName: 'absorbance reader step', | ||
stepDetails: '', | ||
stepType: 'absorbanceReader', | ||
wavelengths: [], | ||
} | ||
|
||
const expected = { | ||
moduleId: 'absorbanceReaderId', | ||
commandCreatorFnName: 'absorbanceReaderRead', | ||
fileName: 'output_path.csv', | ||
description: '', | ||
name: 'absorbance reader step', | ||
} | ||
expect(absorbanceReaderFormToArgs(formData)).toEqual(expected) | ||
}) | ||
it('returns absorbance reader lid command creator to open lid', () => { | ||
const formData: HydratedAbsorbanceReaderFormData = { | ||
absorbanceReaderFormType: 'absorbanceReaderLid', | ||
fileName: null, | ||
id: 'stepId', | ||
lidOpen: true, | ||
mode: 'single', | ||
moduleId: 'absorbanceReaderId', | ||
referenceWavelength: null, | ||
referenceWavelengthActive: false, | ||
stepName: 'absorbance reader step', | ||
stepDetails: '', | ||
stepType: 'absorbanceReader', | ||
wavelengths: [], | ||
} | ||
|
||
const expected = { | ||
moduleId: 'absorbanceReaderId', | ||
commandCreatorFnName: 'absorbanceReaderOpenLid', | ||
description: '', | ||
name: 'absorbance reader step', | ||
} | ||
expect(absorbanceReaderFormToArgs(formData)).toEqual(expected) | ||
}) | ||
it('returns absorbance reader lid command creator to close lid', () => { | ||
const formData: HydratedAbsorbanceReaderFormData = { | ||
absorbanceReaderFormType: 'absorbanceReaderLid', | ||
fileName: null, | ||
id: 'stepId', | ||
lidOpen: false, | ||
mode: 'single', | ||
moduleId: 'absorbanceReaderId', | ||
referenceWavelength: null, | ||
referenceWavelengthActive: false, | ||
stepName: 'absorbance reader step', | ||
stepDetails: '', | ||
stepType: 'absorbanceReader', | ||
wavelengths: [], | ||
} | ||
|
||
const expected = { | ||
moduleId: 'absorbanceReaderId', | ||
commandCreatorFnName: 'absorbanceReaderCloseLid', | ||
description: '', | ||
name: 'absorbance reader step', | ||
} | ||
expect(absorbanceReaderFormToArgs(formData)).toEqual(expected) | ||
}) | ||
}) |