Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,33 @@ export const Default: Story = {
name: 'Default',
play: async ({ canvasElement, step, args }) => {
const canvas = within(canvasElement);
const input = canvas.getByRole('radio');
const input = canvas.getByRole<HTMLInputElement>('radio');

await step('Radio Button handles focus event', async () => {
await step('Click radio button', async () => {
await expect(args.onFocus).not.toHaveBeenCalled();

await userEvent.click(input);

await expect(args.onFocus).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenLastCalledWith(true, expect.anything());
await expect(args.onInput).toHaveBeenCalledOnce();
await expect(args.onInput).toHaveBeenLastCalledWith(true, expect.anything());
await expect(input.checked).toBe(true);
});

await step('Click radio button again', async () => {
await userEvent.click(input);

await expect(args.onFocus).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenLastCalledWith(true, expect.anything());
await expect(args.onInput).toHaveBeenCalledOnce();
await expect(args.onInput).toHaveBeenLastCalledWith(true, expect.anything());
Comment on lines 46 to +50
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertions expect onFocus, onChange, and onInput to be called only once each, but this is the second click on the radio button. Radio buttons typically don't trigger onChange/onInput events when clicked again if already selected, so these call counts should reflect the cumulative calls from both steps.

Copilot uses AI. Check for mistakes.

await expect(input.checked).toBe(true);
});

await step('Radio Button handles blur event', async () => {
await step('Click outside checkbox', async () => {
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The step description mentions 'checkbox' but this is testing a radio button component. It should be 'Click outside radio button'.

Suggested change
await step('Click outside checkbox', async () => {
await step('Click outside radio button', async () => {

Copilot uses AI. Check for mistakes.

await expect(args.onBlur).not.toHaveBeenCalled();

await userEvent.click(canvasElement);
Expand All @@ -50,3 +60,35 @@ export const Default: Story = {
});
},
};

export const UsingLabel: Story = {
name: 'Using Label',
play: async ({ canvasElement, step, args }) => {
const canvas = within(canvasElement);
const input = canvas.getByRole<HTMLInputElement>('radio');
const label = canvas.getByText('Radio Button Label');

await step('Click radio button label', async () => {
await expect(args.onFocus).not.toHaveBeenCalled();

await userEvent.click(label);

await expect(args.onFocus).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenLastCalledWith(true, expect.anything());
await expect(args.onInput).toHaveBeenCalledOnce();
await expect(args.onInput).toHaveBeenLastCalledWith(true, expect.anything());
await expect(input.checked).toBe(true);
});

await step('Click radio button label again', async () => {
await userEvent.click(label);

await expect(args.onChange).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenLastCalledWith(true, expect.anything());
await expect(args.onInput).toHaveBeenCalledOnce();
await expect(args.onInput).toHaveBeenLastCalledWith(true, expect.anything());
Comment on lines +87 to +90
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous issue, these assertions expect onChange and onInput to be called only once total, but this is the second interaction (clicking the label again). The call counts should reflect cumulative calls or be adjusted based on expected radio button behavior.

Copilot uses AI. Check for mistakes.

await expect(input.checked).toBe(true);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const Default: Story = {
name: 'Default',
play: async ({ canvasElement, step, args }) => {
const canvas = within(canvasElement);
const input = canvas.getByRole('radio');
const input = canvas.getByRole<HTMLInputElement>('radio');

await step('Radio Button handles focus event', async () => {
await step('Click radio button', async () => {
await expect(args.onFocus).not.toHaveBeenCalled();

await userEvent.click(input);
Expand All @@ -36,10 +36,12 @@ export const Default: Story = {

await expect(args.onFocus).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenCalledWith(true, expect.anything());
await expect(args.onInput).toHaveBeenCalledOnce();
await expect(args.onInput).toHaveBeenCalledWith(true, expect.anything());
});

await step('Radio Button handles blur event', async () => {
await step('Click outside radio button', async () => {
await expect(args.onBlur).not.toHaveBeenCalled();

await userEvent.click(canvasElement);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, within } from 'storybook/test';

import { RadioButtonsListFieldStateful } from '.';

const meta: Meta<typeof RadioButtonsListFieldStateful> = {
component: RadioButtonsListFieldStateful,
tags: ['!dev'],
args: {
label: 'Choice Inputs List Label',
helperText: 'This is a helper text',
value: 'item1',
items: [
{ id: 'item1', label: 'Item 1', value: 'item1' },
{ id: 'item2', label: 'Item 2', value: 'item2' },
{ id: 'item3', label: 'Item 3', value: 'item3' },
],
onChange: fn(),
},
};

export default meta;

type Story = StoryObj<typeof RadioButtonsListFieldStateful>;

export const Default: Story = {
name: 'Default',
play: async ({ canvasElement, step, args }) => {
const canvas = within(canvasElement);
const input2 = canvas.getByRole<HTMLInputElement>('radio', { name: 'Item 2' });
const input3 = canvas.getByRole<HTMLInputElement>('radio', { name: 'Item 3' });

await step('Click last item', async () => {
await userEvent.click(input3);

await expect(args.onChange).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenLastCalledWith('item3');
await expect(input3.checked).toBe(true);
});

await step('Click second item', async () => {
await userEvent.click(input2);

await expect(args.onChange).toHaveBeenCalledTimes(2); // eslint-disable-line no-magic-numbers
await expect(args.onChange).toHaveBeenLastCalledWith('item2');
await expect(input2.checked).toBe(true);
await expect(input3.checked).toBe(false);
});

await step('Click second item once more', async () => {
await userEvent.click(input2);

await expect(args.onChange).toHaveBeenCalledTimes(2); // eslint-disable-line no-magic-numbers
});
},
};