-
-
Notifications
You must be signed in to change notification settings - Fork 589
Expand file tree
/
Copy pathRRating.stories.ts
More file actions
102 lines (93 loc) · 2.86 KB
/
Copy pathRRating.stories.ts
File metadata and controls
102 lines (93 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import type { Meta, StoryObj } from "@storybook/vue3-vite";
import { expect, userEvent, within } from "storybook/test";
import { ref } from "vue";
import RRating from "./RRating.vue";
const meta: Meta<typeof RRating> = {
title: "Forms/RRating",
component: RRating,
argTypes: {
length: { control: "number" },
size: { control: "text" },
color: { control: "text" },
activeColor: { control: "text" },
emptyIcon: { control: "text" },
fullIcon: { control: "text" },
density: {
control: "select",
options: ["default", "comfortable", "compact"],
},
readonly: { control: "boolean" },
halfIncrements: { control: "boolean" },
hover: { control: "boolean" },
clearable: { control: "boolean" },
},
render: (args) => ({
components: { RRating },
setup: () => {
const value = ref(3.5);
return { args, value };
},
template: `<RRating v-bind="args" v-model="value" />`,
}),
};
export default meta;
type Story = StoryObj<typeof RRating>;
export const Default: Story = { args: { halfIncrements: true, hover: true } };
export const Readonly: Story = { args: { readonly: true } };
export const Large: Story = { args: { size: "large" } };
// Keyboard: Tab across the star buttons, Enter/Space commits the rating.
export const KeyboardNav: Story = {
name: "Keyboard navigation (play)",
args: { ariaLabel: "Rating" },
render: (args) => ({
components: { RRating },
setup: () => {
const value = ref(0);
return { args, value };
},
template: `<RRating v-bind="args" v-model="value" />`,
}),
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
const stars = canvas.getAllByRole("radio");
await step("Tab focuses the stars in order", async () => {
await userEvent.tab();
expect(stars[0]).toHaveFocus();
await userEvent.tab();
await userEvent.tab();
expect(stars[2]).toHaveFocus();
});
await step("Enter commits the focused star as the rating", async () => {
await userEvent.keyboard("{Enter}");
expect(stars[2]).toHaveAttribute("aria-checked", "true");
expect(stars[0]).toHaveAttribute("aria-checked", "false");
});
},
};
// Difficulty preset — same primitive driven by props. Exercises the
// new emptyIcon/fullIcon/activeColor pass-through used by the
// score-picker on GameDetails.
export const Difficulty: Story = {
args: {
length: 10,
hover: true,
clearable: true,
emptyIcon: "mdi-chili-mild-outline",
fullIcon: "mdi-chili-mild",
color: "danger",
activeColor: "danger",
size: "small",
},
};
// Rating preset — 10 stars, gold accent, the shape consumed by the
// score-picker for "Your Rating".
export const RatingTen: Story = {
args: {
length: 10,
hover: true,
clearable: true,
color: "warning",
activeColor: "warning",
size: "small",
},
};