import React from 'react' import { StoryFn, Meta } from '@storybook/react' import { expect, within, userEvent } from 'storybook/test' import Reset from '../components/decorator-reset' import { useControls } from '../../src' export default { title: 'Inputs/String', decorators: [Reset], } as Meta const Template: StoryFn = (args) => { const values = useControls({ foo: args, }) return (
{JSON.stringify(values, null, '  ')}
) } export const Simple = Template.bind({}) Simple.args = { value: 'Leva is awesome', } Simple.play = async ({ canvasElement }) => { const canvas = within(canvasElement) // Verify initial value is rendered in the JSON output await expect(canvas.getByText(/Leva is awesome/)).toBeInTheDocument() // Leva panel is rendered outside canvasElement (in document.body) // Find the input field by label (the control label is "foo") const input = within(document.body).getByLabelText(/foo/i) // Clear the input and type new text await userEvent.clear(input) await userEvent.type(input, 'New text value') // Blur the input to trigger the update (Leva updates on blur) await userEvent.tab() // Wait for the value to update in the JSON output await expect(canvas.getByText(/New text value/)).toBeInTheDocument() // Verify the old value is gone await expect(canvas.queryByText(/Leva is awesome/)).not.toBeInTheDocument() } export const DefaultRows = Template.bind({}) DefaultRows.args = { value: 'Leva also supports