|
| 1 | +import { describe, it, expect, vi, beforeEach } from 'vitest' |
| 2 | +import { fireEvent, screen } from '@testing-library/react' |
| 3 | +import { i18n } from '../../../../../../../assets/localization' |
| 4 | +import { renderWithProviders } from '../../../../../../../__testing-utils__' |
| 5 | +import { MultiInputField } from '../MultiInputField' |
| 6 | + |
| 7 | +import type { ComponentProps } from 'react' |
| 8 | +import { COLORS } from '@opentrons/components' |
| 9 | + |
| 10 | +const render = (props: ComponentProps<typeof MultiInputField>) => { |
| 11 | + return renderWithProviders(<MultiInputField {...props} />, { |
| 12 | + i18nInstance: i18n, |
| 13 | + }) |
| 14 | +} |
| 15 | + |
| 16 | +describe('MultiInputField', () => { |
| 17 | + let props: ComponentProps<typeof MultiInputField> |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + props = { |
| 21 | + name: 'Submerge', |
| 22 | + tab: 'aspirate', |
| 23 | + tooltipContent: 'some tooltip content', |
| 24 | + fields: [ |
| 25 | + { |
| 26 | + fieldTitle: 'submerge speed', |
| 27 | + fieldKey: 'submerge_speed', |
| 28 | + units: 'mm/s', |
| 29 | + }, |
| 30 | + { |
| 31 | + fieldTitle: 'submerge delay seconds', |
| 32 | + fieldKey: 'submerge_delay_seconds', |
| 33 | + units: 'mm', |
| 34 | + }, |
| 35 | + ], |
| 36 | + propsForFields: { |
| 37 | + aspirate_submerge_speed: { |
| 38 | + onFieldFocus: vi.fn(), |
| 39 | + onFieldBlur: vi.fn(), |
| 40 | + errorToShow: null, |
| 41 | + disabled: false, |
| 42 | + name: 'aspirate_submerge_speed', |
| 43 | + updateValue: vi.fn(), |
| 44 | + value: null, |
| 45 | + }, |
| 46 | + }, |
| 47 | + } |
| 48 | + }) |
| 49 | + |
| 50 | + it('should render input fields with caption and units wrapped by ListItem', () => { |
| 51 | + render(props) |
| 52 | + screen.getByText('Submerge') |
| 53 | + screen.getByTestId('information_icon') |
| 54 | + const listItem = screen.getByTestId('ListItem_noActive') |
| 55 | + expect(listItem).toHaveStyle(`backgroundColor: ${COLORS.grey20}`) |
| 56 | + screen.getByText('submerge speed') |
| 57 | + screen.getByText('mm/s') |
| 58 | + screen.getByText('submerge delay seconds') |
| 59 | + screen.getByText('mm') |
| 60 | + const inputs = screen.getAllByRole('textbox', { name: '' }) |
| 61 | + expect(inputs).toHaveLength(2) |
| 62 | + fireEvent.change(inputs[0], { target: { value: ['5'] } }) |
| 63 | + expect( |
| 64 | + props.propsForFields.aspirate_submerge_speed.updateValue |
| 65 | + ).toHaveBeenCalled() |
| 66 | + }) |
| 67 | + |
| 68 | + it('should render a well position listbutton when isWellPosition is true', () => { |
| 69 | + props.isWellPosition = true |
| 70 | + render(props) |
| 71 | + }) |
| 72 | +}) |
0 commit comments