Files
MeshChatX/tests/frontend/DropDownMenu.test.js
T
Sudo-Ivan f776bad9c4 Add unit tests for various frontend components
- Introduced new test files for BlockedPage, DropDownMenu, and Interface components to ensure proper rendering and functionality.
- Enhanced existing tests for ConfirmDialog, MessagesSidebar, and NotificationBell, improving coverage and verifying UI behavior.
- Added performance tests for LoadTimePerformance to measure loading times for large datasets in the PropagationNodesPage and MessagesSidebar.
- Removed the deprecated InterfacesPage test file to streamline the test suite.
2026-02-17 17:48:40 -06:00

47 lines
1.7 KiB
JavaScript

import { mount } from "@vue/test-utils";
import { describe, it, expect, vi } from "vitest";
import DropDownMenu from "../../meshchatx/src/frontend/components/DropDownMenu.vue";
function mountDropDown(slots = {}) {
return mount(DropDownMenu, {
slots: {
button: "<button type=\"button\">Menu</button>",
items: "<div class=\"menu-item\">Item 1</div>",
...slots,
},
global: {
directives: { "click-outside": { mounted: () => {}, unmounted: () => {} } },
},
});
}
describe("DropDownMenu UI", () => {
it("renders button slot", () => {
const wrapper = mountDropDown();
expect(wrapper.text()).toContain("Menu");
});
it("shows menu when button clicked", async () => {
const wrapper = mountDropDown();
expect(wrapper.vm.isShowingMenu).toBe(false);
await wrapper.find("button").trigger("click");
expect(wrapper.vm.isShowingMenu).toBe(true);
expect(wrapper.text()).toContain("Item 1");
});
it("hides menu when button clicked again", async () => {
const wrapper = mountDropDown();
await wrapper.find("button").trigger("click");
expect(wrapper.vm.isShowingMenu).toBe(true);
await wrapper.find("button").trigger("click");
expect(wrapper.vm.isShowingMenu).toBe(false);
});
it("renders items slot when open", async () => {
const wrapper = mountDropDown({ items: "<div class=\"custom-item\">Custom</div>" });
await wrapper.find("button").trigger("click");
expect(wrapper.find(".custom-item").exists()).toBe(true);
expect(wrapper.text()).toContain("Custom");
});
});