Skip to content

Commit 731fb9e

Browse files
authored
feat(protocol-designer): add TextAreaField component to protocol-designer (#17487)
* feat(protocol-designer): add TextAreaField component to protocol-designer
1 parent 89b3f14 commit 731fb9e

File tree

5 files changed

+442
-18
lines changed

5 files changed

+442
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as React from 'react'
2+
import {
3+
DIRECTION_COLUMN,
4+
Flex,
5+
SPACING,
6+
VIEWPORT,
7+
} from '@opentrons/components'
8+
import { TextAreaField as TextAreaFieldComponent } from '.'
9+
10+
import type { ComponentProps } from 'react'
11+
import type { Meta, StoryObj } from '@storybook/react'
12+
13+
const meta: Meta<typeof TextAreaFieldComponent> = {
14+
// ToDo (kk05/02/2024) this should be in Library but at this moment there is the same name component in components
15+
// The unification for this component will be done when the old component is retired completely.
16+
title: 'Protocol-Designer/Molecules/TextAreaField',
17+
component: TextAreaFieldComponent,
18+
parameters: VIEWPORT.touchScreenViewport,
19+
argTypes: {},
20+
}
21+
22+
export default meta
23+
type Story = StoryObj<typeof TextAreaFieldComponent>
24+
25+
export const TextAreaField: Story = (
26+
args: ComponentProps<typeof TextAreaFieldComponent>
27+
) => {
28+
const [value, setValue] = React.useState(args.value)
29+
return (
30+
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}>
31+
<TextAreaFieldComponent
32+
{...args}
33+
value={value}
34+
onChange={e => {
35+
setValue(e.currentTarget.value)
36+
}}
37+
/>
38+
</Flex>
39+
)
40+
}
41+
42+
TextAreaField.args = {
43+
title: 'TextAreaField',
44+
height: '6.8125rem',
45+
placeholder: 'Placeholder Text',
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, it, beforeEach, vi, expect } from 'vitest'
2+
import { screen, fireEvent } from '@testing-library/react'
3+
4+
import { renderWithProviders } from '../../../__testing-utils__'
5+
import { TextAreaField } from '../'
6+
7+
import type { ComponentProps } from 'react'
8+
9+
const render = (props: ComponentProps<typeof TextAreaField>) => {
10+
return renderWithProviders(<TextAreaField {...props} />)
11+
}
12+
13+
describe('TextAreaField', () => {
14+
let props: ComponentProps<typeof TextAreaField>
15+
16+
beforeEach(() => {
17+
props = {
18+
title: 'TextAreaField',
19+
placeholder: 'Enter text...',
20+
value: '',
21+
onChange: vi.fn(),
22+
}
23+
})
24+
25+
it('renders the TextAreaField component', () => {
26+
render(props)
27+
screen.getByText('TextAreaField')
28+
expect(screen.getByTestId('TextAreaField')).toBeInTheDocument()
29+
})
30+
31+
it('displays the correct placeholder text', () => {
32+
render(props)
33+
expect(screen.getByPlaceholderText('Enter text...')).toBeInTheDocument()
34+
})
35+
36+
it('updates value when user types', () => {
37+
render(props)
38+
const textarea = screen.getByTestId('TextAreaField')
39+
40+
fireEvent.change(textarea, { target: { value: 'Hello, world!' } })
41+
42+
expect(props.onChange).toHaveBeenCalledTimes(1)
43+
})
44+
45+
it('disables the textarea when disabled prop is true', () => {
46+
props.disabled = true
47+
render(props)
48+
expect(screen.getByTestId('TextAreaField')).toBeDisabled()
49+
})
50+
51+
it('displays an error message when error prop is provided', () => {
52+
props.error = 'Error: Invalid input'
53+
render(props)
54+
55+
expect(screen.getByText('Error: Invalid input')).toBeInTheDocument()
56+
})
57+
58+
it('display an icon when tooltip prop is provided', () => {
59+
props.tooltipText = 'ot-icon-check'
60+
render(props)
61+
screen.getByTestId('tooltip-icon')
62+
})
63+
64+
it('display left icon when leftIcon prop is provided', () => {
65+
props.leftIcon = 'information'
66+
render(props)
67+
screen.getByTestId('left-icon')
68+
})
69+
})

0 commit comments

Comments
 (0)