Skip to content

Commit 284c2a9

Browse files
committed
add: test for Addon component #2
1 parent 149f9ea commit 284c2a9

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/components/tests/Addon.test.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { describe, it, expect } from "vitest";
2+
3+
import { mount } from "@vue/test-utils";
4+
import AddonVue from "../Addon.vue";
5+
import { Addon } from "@/services/addon.service";
6+
7+
describe("Addon Component", () => {
8+
const addon = new Addon("TEST");
9+
addon.description = "A DESCRIPTION";
10+
addon.size = 54321;
11+
12+
const wrapper = mount(AddonVue, {
13+
props: { addon },
14+
slots: {
15+
badges: ["<span>Badge!</span>", "<span>Another one!</span>"],
16+
"quick-actions": ["<button>Click me</button>"],
17+
controls: ["<button>Action 1</button>", "<button>Action 2</button>"],
18+
},
19+
});
20+
21+
it("renders basic info", () => {
22+
expect(wrapper.exists());
23+
// Name
24+
expect(wrapper.get("h1").text()).toBe("TEST");
25+
// Description
26+
expect(wrapper.get("p.description").text()).toBe("A DESCRIPTION");
27+
// Size
28+
expect(wrapper.get("div.bottom").text()).toBe("53.05 KB");
29+
});
30+
31+
it("renders badges", () => {
32+
const badges = wrapper.findAll(".badges span");
33+
expect(badges[0].exists());
34+
expect(badges[0].text()).toBe("Badge!");
35+
36+
expect(badges[1].exists());
37+
expect(badges[1].text()).toBe("Another one!");
38+
});
39+
40+
it("renders quick actions", () => {
41+
const quickActions = wrapper.get(".quick-actions");
42+
43+
expect(quickActions.get("button").text()).toBe("Click me");
44+
45+
const githubLink = wrapper.get(".quick-actions .github-link");
46+
const attributes = githubLink.attributes();
47+
expect(attributes.href).toBe(
48+
"https://github.com/carsakiller/LLS-Addons/tree/main/addons/TEST"
49+
);
50+
expect(attributes.target).toBe("_blank");
51+
expect(attributes.title).toBe("View on GitHub");
52+
expect(attributes.rel).toBe("nofollow noreferrer noopener external");
53+
});
54+
55+
it("renders controls", () => {
56+
const controls = wrapper.findAll(".controls button");
57+
58+
expect(controls[0].exists());
59+
expect(controls[0].text()).toBe("Action 1");
60+
61+
expect(controls[1].exists());
62+
expect(controls[1].text()).toBe("Action 2");
63+
});
64+
});

0 commit comments

Comments
 (0)