-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol-designer): add TextAreaField component to protocol-desi…
…gner (#17487) * feat(protocol-designer): add TextAreaField component to protocol-designer
- Loading branch information
Showing
5 changed files
with
442 additions
and
18 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
protocol-designer/src/molecules/TextAreaField/TextAreaField.stories.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,46 @@ | ||
import * as React from 'react' | ||
import { | ||
DIRECTION_COLUMN, | ||
Flex, | ||
SPACING, | ||
VIEWPORT, | ||
} from '@opentrons/components' | ||
import { TextAreaField as TextAreaFieldComponent } from '.' | ||
|
||
import type { ComponentProps } from 'react' | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
const meta: Meta<typeof TextAreaFieldComponent> = { | ||
// ToDo (kk05/02/2024) this should be in Library but at this moment there is the same name component in components | ||
// The unification for this component will be done when the old component is retired completely. | ||
title: 'Protocol-Designer/Molecules/TextAreaField', | ||
component: TextAreaFieldComponent, | ||
parameters: VIEWPORT.touchScreenViewport, | ||
argTypes: {}, | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof TextAreaFieldComponent> | ||
|
||
export const TextAreaField: Story = ( | ||
args: ComponentProps<typeof TextAreaFieldComponent> | ||
) => { | ||
const [value, setValue] = React.useState(args.value) | ||
return ( | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}> | ||
<TextAreaFieldComponent | ||
{...args} | ||
value={value} | ||
onChange={e => { | ||
setValue(e.currentTarget.value) | ||
}} | ||
/> | ||
</Flex> | ||
) | ||
} | ||
|
||
TextAreaField.args = { | ||
title: 'TextAreaField', | ||
height: '6.8125rem', | ||
placeholder: 'Placeholder Text', | ||
} |
69 changes: 69 additions & 0 deletions
69
protocol-designer/src/molecules/TextAreaField/__tests__/TextAreaField.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,69 @@ | ||
import { describe, it, beforeEach, vi, expect } from 'vitest' | ||
import { screen, fireEvent } from '@testing-library/react' | ||
|
||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { TextAreaField } from '../' | ||
|
||
import type { ComponentProps } from 'react' | ||
|
||
const render = (props: ComponentProps<typeof TextAreaField>) => { | ||
return renderWithProviders(<TextAreaField {...props} />) | ||
} | ||
|
||
describe('TextAreaField', () => { | ||
let props: ComponentProps<typeof TextAreaField> | ||
|
||
beforeEach(() => { | ||
props = { | ||
title: 'TextAreaField', | ||
placeholder: 'Enter text...', | ||
value: '', | ||
onChange: vi.fn(), | ||
} | ||
}) | ||
|
||
it('renders the TextAreaField component', () => { | ||
render(props) | ||
screen.getByText('TextAreaField') | ||
expect(screen.getByTestId('TextAreaField')).toBeInTheDocument() | ||
}) | ||
|
||
it('displays the correct placeholder text', () => { | ||
render(props) | ||
expect(screen.getByPlaceholderText('Enter text...')).toBeInTheDocument() | ||
}) | ||
|
||
it('updates value when user types', () => { | ||
render(props) | ||
const textarea = screen.getByTestId('TextAreaField') | ||
|
||
fireEvent.change(textarea, { target: { value: 'Hello, world!' } }) | ||
|
||
expect(props.onChange).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('disables the textarea when disabled prop is true', () => { | ||
props.disabled = true | ||
render(props) | ||
expect(screen.getByTestId('TextAreaField')).toBeDisabled() | ||
}) | ||
|
||
it('displays an error message when error prop is provided', () => { | ||
props.error = 'Error: Invalid input' | ||
render(props) | ||
|
||
expect(screen.getByText('Error: Invalid input')).toBeInTheDocument() | ||
}) | ||
|
||
it('display an icon when tooltip prop is provided', () => { | ||
props.tooltipText = 'ot-icon-check' | ||
render(props) | ||
screen.getByTestId('tooltip-icon') | ||
}) | ||
|
||
it('display left icon when leftIcon prop is provided', () => { | ||
props.leftIcon = 'information' | ||
render(props) | ||
screen.getByTestId('left-icon') | ||
}) | ||
}) |
Oops, something went wrong.