import React from "react"; import { screen, userEvent } from "@storybook/testing-library"; import { expect } from "@storybook/jest"; import { InputPassword as Component } from "./"; import { styled, theme } from "../theme"; import type { Meta, StoryFn } from "@storybook/react"; export default { title: "InputPassword", component: Component, } as Meta; export const InputPassword = { parameters: { chromatic: { disableSnapshot: true }, }, }; const Column = styled("div", { display: "flex", flexDirection: "column", gap: "$100", }); const Heading = styled("h2", { color: theme.colors.primary, fontSize: theme.fontSizes["100"], marginBlock: 0, }); const ChromaticTemplate = () => ( Standard password Behaviors ); export const Chromatic = { render: ChromaticTemplate, }; const InteractionsTemplate: StoryFn = () => ( ); export const Interactions = { render: InteractionsTemplate, parameters: { chromatic: { disableSnapshot: true }, }, play: async () => { // radix Label needs a tick to associate labels with inputs await sleep(0); const input = screen.getByLabelText("Password"); await userEvent.type(input, "123456", { delay: 100, }); const toggle = screen.getByRole("button"); await userEvent.click(toggle); await expect(input).toHaveAttribute("type", "text"); await sleep(500); await userEvent.click(toggle); await expect(input).toHaveAttribute("type", "password"); }, }; // Function to emulate pausing between interactions function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }