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 @@ -27,17 +27,19 @@ export const Default: Story = {
const canvas = within(canvasElement);
const input = canvas.getByRole('button');

await step('AltRadio handles focus event', async () => {
await step('Click tile', 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).toHaveBeenCalledWith(true);
await expect(args.onInput).toHaveBeenCalledOnce();
await expect(args.onInput).toHaveBeenCalledWith(true);
});

await step('AltRadio handles blur event', async () => {
await step('Click outside tile', 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 { AltRadiosListFieldStateful } from '.';

const meta: Meta<typeof AltRadiosListFieldStateful> = {
component: AltRadiosListFieldStateful,
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 AltRadiosListFieldStateful>;

export const Default: Story = {
name: 'Default',
play: async ({ canvasElement, step, args }) => {
const canvas = within(canvasElement);
const input2 = canvas.getByText('Item 2');
const input3 = canvas.getByText('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).toHaveClass('ids-alt-radio__tile--checked');
});

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

await expect(args.onChange).toHaveBeenCalledTimes(2); // eslint-disable-line no-magic-numbers
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 magic number 2 should be extracted to a descriptive constant like EXPECTED_CALL_COUNT to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.

await expect(args.onChange).toHaveBeenLastCalledWith('item2');
await expect(input2).toHaveClass('ids-alt-radio__tile--checked');
await expect(input3).not.toHaveClass('ids-alt-radio__tile--checked');
});

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

await expect(args.onChange).toHaveBeenCalledTimes(2); // eslint-disable-line no-magic-numbers
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 magic number 2 should be extracted to a descriptive constant like EXPECTED_CALL_COUNT to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.

});
},
};