Skip to content

Commit

Permalink
test(react): textfield test
Browse files Browse the repository at this point in the history
added cypress test and react storybook for autofocus attribute
  • Loading branch information
gd2910 committed Dec 17, 2024
1 parent b85d410 commit 0cc2c76
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "../utils/constants";
import {
CustomSizeTextField,
AutofocusTextField,
DisabledTextField,
FullWidthTextField,
HiddenLabelTextField,
Expand Down Expand Up @@ -333,6 +334,14 @@ describe("IcTextField end-to-end tests", () => {

input.should(HAVE_ATTR, "title", "new-input-title");
});

it.only("should autofocus when autofocus attribute is set", () => {
mount(<AutofocusTextField />);

const input = cy.findShadowEl(IC_TEXTFIELD, TEXTFIELD_INPUT);

input.should(HAVE_FOCUS);
}
});

describe("IcTextField visual regression tests", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ export const HiddenLabelTextField = (): ReactElement => (
</div>
);

export const AutofocusTextField = (): ReactElement => (
<div style={style}>
<IcTextField
maxCharacters={25}
label="What is your favourite coffee?"
placeholder="Please enter…"
helperText="Such as Arabica, Robusta or Liberica"
autofocus
>
<ReusableSlottedIcon />
</IcTextField>
</div>
);

export const TextFieldWithMinMaxCharacters = (): ReactElement => (
<>
<div style={style}>
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/stories/ic-text-field.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export const ControlledExample = () => {
</Story>
</Canvas>

### Autofocus

<Canvas>
<Story name="Autofocus">
<IcTextField label="What is your favourite coffee?" autofocus/>
</Story>
</Canvas>

### Placeholder and required

<Canvas>
Expand Down

0 comments on commit 0cc2c76

Please sign in to comment.