export const Default: Story = {
render: () => (
-
),
+ play: async ({ canvas, canvasElement, userEvent }) => {
+ const trigger = canvas.getByRole('combobox', { name: 'City' })
+ const body = within(canvasElement.ownerDocument.body)
+
+ await expect(trigger).toHaveTextContent('Seattle')
+
+ trigger.focus()
+ await userEvent.keyboard('{ArrowDown}')
+
+ await waitFor(async () => {
+ await expect(body.getByRole('option', { name: 'Tokyo' })).toBeVisible()
+ })
+
+ await userEvent.keyboard('{ArrowDown}{ArrowDown}{Enter}')
+ await expect(trigger).toHaveTextContent('Tokyo')
+
+ await userEvent.keyboard('{Escape}')
+ await waitFor(async () => {
+ await expect(body.queryByRole('listbox', { name: 'City options' })).not.toBeInTheDocument()
+ })
+ },
}
export const WithVisibleLabel: Story = {
diff --git a/packages/dify-ui/src/switch/index.stories.tsx b/packages/dify-ui/src/switch/index.stories.tsx
index a7537b50b8..40e9ca6e51 100644
--- a/packages/dify-ui/src/switch/index.stories.tsx
+++ b/packages/dify-ui/src/switch/index.stories.tsx
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react-vite'
import * as React from 'react'
+import { expect } from 'storybook/test'
import { Switch, SwitchSkeleton } from '.'
import {
FieldDescription,
@@ -77,6 +78,17 @@ export const Default: Story = {
checked: false,
disabled: false,
},
+ play: async ({ canvas, userEvent }) => {
+ const switchControl = canvas.getByRole('switch', { name: 'Enable auto retry' })
+
+ await expect(switchControl).toHaveAttribute('aria-checked', 'false')
+ await expect(canvas.getByText('Failures require manual retry.')).toBeVisible()
+
+ await userEvent.click(switchControl)
+
+ await expect(switchControl).toHaveAttribute('aria-checked', 'true')
+ await expect(canvas.getByText('Failures will retry automatically.')).toBeVisible()
+ },
}
export const DefaultOn: Story = {