feat: initialize Vue component library and aligned documentation
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { h } from "vue";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
CardFooter,
|
||||
Switch,
|
||||
SwitchContent,
|
||||
SwitchControl,
|
||||
SwitchThumb,
|
||||
Description,
|
||||
} from "../packages/vue/src";
|
||||
describe("compound components", () => {
|
||||
it("preserves Card parts, heading semantics and custom elements", () => {
|
||||
const w = mount(Card, {
|
||||
props: { variant: "tertiary", as: "article" },
|
||||
slots: {
|
||||
default: () => [
|
||||
h(CardHeader, () => [
|
||||
h(CardTitle, () => "成为 Acme 创作者!"),
|
||||
h(CardDescription, () => "描述"),
|
||||
]),
|
||||
h(CardContent, () => "内容"),
|
||||
h(CardFooter, () => "操作"),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(w.element.tagName).toBe("ARTICLE");
|
||||
expect(w.get("h3").text()).toBe("成为 Acme 创作者!");
|
||||
for (const part of ["header", "title", "description", "content", "footer"])
|
||||
expect(w.find(`[data-slot=card-${part}]`).exists()).toBe(true);
|
||||
});
|
||||
it("names a composed Switch and associates its Description", async () => {
|
||||
const w = mount(Switch, {
|
||||
props: { defaultSelected: true },
|
||||
slots: {
|
||||
default: () => [
|
||||
h(SwitchContent, () => [
|
||||
h(SwitchControl, () => h(SwitchThumb)),
|
||||
"公开资料",
|
||||
]),
|
||||
h(Description, () => "允许他人查看你的资料信息"),
|
||||
],
|
||||
},
|
||||
});
|
||||
await w.vm.$nextTick();
|
||||
const control = w.get("[role=switch]");
|
||||
expect(control.text()).toBe("公开资料");
|
||||
expect(control.attributes("aria-describedby")).toBe(
|
||||
w.get("[data-slot=description]").attributes("id"),
|
||||
);
|
||||
await control.trigger("click");
|
||||
expect(w.emitted("change")).toEqual([[false]]);
|
||||
});
|
||||
it("submits the selected Switch form value through the underlying native field", async () => {
|
||||
const form = document.createElement("form");
|
||||
document.body.append(form);
|
||||
const w = mount(Switch, {
|
||||
attachTo: form,
|
||||
props: { name: "notifications", value: "enabled", defaultSelected: true },
|
||||
});
|
||||
await w.vm.$nextTick();
|
||||
expect(new FormData(form).get("notifications")).toBe("enabled");
|
||||
await w.get("[role=switch]").trigger("click");
|
||||
expect(new FormData(form).get("notifications")).toBeNull();
|
||||
w.unmount();
|
||||
form.remove();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user