fa5a190416
CI Pipeline / test (20) (pull_request) Successful in 2m30s
CI Pipeline / test (18) (pull_request) Successful in 3m51s
CI Pipeline / e2e (firefox) (pull_request) Successful in 3m22s
CI Pipeline / e2e (webkit) (pull_request) Successful in 3m45s
CI Pipeline / e2e (chromium) (pull_request) Successful in 11m49s
CI Pipeline / visual-regression (pull_request) Successful in 6m48s
CI Pipeline / storybook (pull_request) Successful in 1m35s
CI Pipeline / lint (pull_request) Successful in 1m12s
CI Pipeline / build (pull_request) Successful in 1m54s
CI Pipeline / performance (pull_request) Successful in 4m6s
125 lines
4.2 KiB
JavaScript
125 lines
4.2 KiB
JavaScript
import { expect } from "@storybook/test";
|
|
import { userEvent, within } from "@storybook/test";
|
|
|
|
export const DefaultInteraction = {
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
const radioButton = canvas.getByRole("radio");
|
|
|
|
// Should be unchecked initially
|
|
await expect(radioButton).toHaveAttribute("aria-checked", "false");
|
|
|
|
// Click to check
|
|
await userEvent.click(radioButton);
|
|
await expect(radioButton).toHaveAttribute("aria-checked", "true");
|
|
|
|
// Radio buttons can't be unchecked by clicking them again
|
|
// They stay checked until another radio button in the same group is selected
|
|
await userEvent.click(radioButton);
|
|
await expect(radioButton).toHaveAttribute("aria-checked", "true");
|
|
},
|
|
};
|
|
|
|
export const CheckedInteraction = {
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
const radioButton = canvas.getByRole("radio");
|
|
|
|
// Should be checked initially
|
|
await expect(radioButton).toHaveAttribute("aria-checked", "true");
|
|
|
|
// Radio buttons can't be unchecked by clicking them again
|
|
// They stay checked until another radio button in the same group is selected
|
|
await userEvent.click(radioButton);
|
|
await expect(radioButton).toHaveAttribute("aria-checked", "true");
|
|
},
|
|
};
|
|
|
|
export const StandardInteraction = {
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
const radioButtons = canvas.getAllByRole("radio");
|
|
|
|
// First should be unchecked
|
|
await expect(radioButtons[0]).toHaveAttribute("aria-checked", "false");
|
|
// Second should be checked
|
|
await expect(radioButtons[1]).toHaveAttribute("aria-checked", "true");
|
|
|
|
// Click first radio button
|
|
await userEvent.click(radioButtons[0]);
|
|
await expect(radioButtons[0]).toHaveAttribute("aria-checked", "true");
|
|
await expect(radioButtons[1]).toHaveAttribute("aria-checked", "false");
|
|
},
|
|
};
|
|
|
|
export const InverseInteraction = {
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
const radioButtons = canvas.getAllByRole("radio");
|
|
|
|
// First should be unchecked
|
|
await expect(radioButtons[0]).toHaveAttribute("aria-checked", "false");
|
|
// Second should be checked
|
|
await expect(radioButtons[1]).toHaveAttribute("aria-checked", "true");
|
|
|
|
// Click first radio button
|
|
await userEvent.click(radioButtons[0]);
|
|
await expect(radioButtons[0]).toHaveAttribute("aria-checked", "true");
|
|
await expect(radioButtons[1]).toHaveAttribute("aria-checked", "false");
|
|
},
|
|
};
|
|
|
|
export const KeyboardInteraction = {
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
const radioButton = canvas.getByRole("radio");
|
|
|
|
// Focus the radio button
|
|
await userEvent.click(radioButton);
|
|
await expect(radioButton).toHaveFocus();
|
|
|
|
// Test Space key
|
|
await userEvent.keyboard(" ");
|
|
await expect(radioButton).toHaveAttribute("aria-checked", "true");
|
|
|
|
// Test Enter key
|
|
await userEvent.keyboard("Enter");
|
|
await expect(radioButton).toHaveAttribute("aria-checked", "false");
|
|
},
|
|
};
|
|
|
|
export const AccessibilityInteraction = {
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
const radioButton = canvas.getByRole("radio");
|
|
|
|
// Should have proper ARIA attributes
|
|
await expect(radioButton).toHaveAttribute("role", "radio");
|
|
await expect(radioButton).toHaveAttribute("aria-checked");
|
|
await expect(radioButton).toHaveAttribute("tabIndex", "0");
|
|
|
|
// Should be keyboard accessible
|
|
await userEvent.tab();
|
|
await expect(radioButton).toHaveFocus();
|
|
|
|
// Should have accessible name
|
|
const label = canvas.getByText("Default radio button");
|
|
await expect(label).toBeVisible();
|
|
},
|
|
};
|
|
|
|
export const FormIntegration = {
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
const radioButton = canvas.getByRole("radio");
|
|
|
|
// Should have hidden input for form submission
|
|
const hiddenInput = canvas.getByRole("radio", { hidden: true });
|
|
await expect(hiddenInput).toBeInTheDocument();
|
|
|
|
// Should be included in form data
|
|
await userEvent.click(radioButton);
|
|
await expect(hiddenInput).toBeChecked();
|
|
},
|
|
};
|