feat: add ProgressBar ProgressCircle and Meter
This commit is contained in:
@@ -234,3 +234,64 @@ it("renders typography, empty state and breadcrumbs without browser globals", as
|
||||
expect(html).toContain("hv-breadcrumbs__separator");
|
||||
expect(html).toContain("富文本段落");
|
||||
});
|
||||
|
||||
it("renders progress and meter indicators without browser globals", async () => {
|
||||
const {
|
||||
Label,
|
||||
Meter,
|
||||
MeterFill,
|
||||
MeterOutput,
|
||||
MeterTrack,
|
||||
ProgressBar,
|
||||
ProgressBarFill,
|
||||
ProgressBarOutput,
|
||||
ProgressBarTrack,
|
||||
ProgressCircle,
|
||||
ProgressCircleFillCircle,
|
||||
ProgressCircleTrack,
|
||||
ProgressCircleTrackCircle,
|
||||
} = await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h("div", {}, [
|
||||
h(ProgressBar, { value: 60 }, () => [
|
||||
h(Label, null, () => "加载中"),
|
||||
h(ProgressBarOutput),
|
||||
h(ProgressBarTrack, null, () => h(ProgressBarFill)),
|
||||
]),
|
||||
h(
|
||||
ProgressCircle,
|
||||
{ isIndeterminate: true, "aria-label": "加载中" },
|
||||
() => [
|
||||
h(ProgressCircleTrack, null, () => [
|
||||
h(ProgressCircleTrackCircle),
|
||||
h(ProgressCircleFillCircle),
|
||||
]),
|
||||
],
|
||||
),
|
||||
h(Meter, { value: 40, "aria-label": "存储空间" }, () => [
|
||||
h(MeterOutput),
|
||||
h(MeterTrack, null, () => h(MeterFill)),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(html).toContain('role="progressbar"');
|
||||
expect(html).toContain('aria-valuenow="60"');
|
||||
expect(html).toContain('aria-valuetext="60%"');
|
||||
expect(html).toContain("hv-progress-bar__fill");
|
||||
expect(html).toContain("hv-progress-circle__fill-circle");
|
||||
// Indeterminate progress must not expose aria-valuenow.
|
||||
expect(html.match(/aria-valuenow/g)).toHaveLength(2);
|
||||
expect(html).toContain('role="meter progressbar"');
|
||||
expect(html).toContain('aria-valuenow="40"');
|
||||
expect(html).toContain('data-slot="meter-output"');
|
||||
// Label association ids are present in the server HTML and resolve to labels.
|
||||
const labelledby = html.match(/aria-labelledby="([^"]+)"/)?.[1];
|
||||
expect(labelledby).toBeTruthy();
|
||||
for (const id of labelledby!.split(/\s+/)) {
|
||||
expect(html).toMatch(new RegExp(`id="${id}"[^>]*data-slot="label"`));
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user