mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-03-31 06:05:49 +00:00
Some checks failed
Build Test / Build and Test (push) Failing after 6m1s
CI / lint (push) Failing after 1m27s
CI / build-frontend (push) Failing after 1m30s
CI / test-backend (push) Successful in 1m17s
CI / test-lang (push) Failing after 1m15s
Build and Publish Docker Image / build (push) Failing after 4m28s
Build and Publish Docker Image / build-dev (push) Failing after 5m38s
Security Scans / scan (push) Successful in 2m12s
Tests / test (push) Failing after 1m17s
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
import { mount } from "@vue/test-utils";
|
|
import { describe, it, expect } from "vitest";
|
|
import SidebarLink from "../../meshchatx/src/frontend/components/SidebarLink.vue";
|
|
|
|
const RouterLinkStub = {
|
|
name: "RouterLinkStub",
|
|
props: ["to"],
|
|
template: '<a href="#" @click.prevent><slot :href="\'#\'" :navigate="navigate" :isActive="false"/></a>',
|
|
methods: {
|
|
navigate(e) {
|
|
if (e) e.preventDefault();
|
|
},
|
|
},
|
|
};
|
|
|
|
function mountSidebarLink(props = {}, slots = {}) {
|
|
return mount(SidebarLink, {
|
|
props: { to: { name: "messages" }, ...props },
|
|
slots: {
|
|
icon: '<span class="icon-slot">I</span>',
|
|
text: "Messages",
|
|
...slots,
|
|
},
|
|
global: {
|
|
stubs: { RouterLink: RouterLinkStub },
|
|
},
|
|
});
|
|
}
|
|
|
|
describe("SidebarLink UI", () => {
|
|
it("renders link with icon and text slots", () => {
|
|
const wrapper = mountSidebarLink();
|
|
expect(wrapper.text()).toContain("Messages");
|
|
expect(wrapper.find(".icon-slot").exists()).toBe(true);
|
|
});
|
|
|
|
it("emits click when link is clicked", async () => {
|
|
const wrapper = mountSidebarLink();
|
|
const innerLink = wrapper.find("a.rounded-r-full");
|
|
if (innerLink.exists()) {
|
|
await innerLink.trigger("click");
|
|
} else {
|
|
await wrapper.find("a").trigger("click");
|
|
}
|
|
expect(wrapper.emitted("click")).toBeDefined();
|
|
expect(wrapper.emitted("click").length).toBeGreaterThanOrEqual(1);
|
|
});
|
|
|
|
it("renders text slot when not collapsed", () => {
|
|
const wrapper = mountSidebarLink({ isCollapsed: false });
|
|
expect(wrapper.text()).toContain("Messages");
|
|
});
|
|
|
|
it("renders when isCollapsed true", () => {
|
|
const wrapper = mountSidebarLink({ isCollapsed: true });
|
|
expect(wrapper.find("a").exists()).toBe(true);
|
|
expect(wrapper.vm.isCollapsed).toBe(true);
|
|
});
|
|
});
|