Files
MeshChatX/tests/frontend/Toast.test.js
Sudo-Ivan 7d7cd7d487
Some checks failed
CI / test-backend (push) Successful in 3s
CI / build-frontend (push) Successful in 1m48s
CI / test-backend (pull_request) Successful in 18s
CI / test-lang (push) Successful in 2m5s
Build and Publish Docker Image / build (pull_request) Has been skipped
CI / test-lang (pull_request) Successful in 1m14s
OSV-Scanner PR Scan / scan-pr (pull_request) Successful in 29s
CI / build-frontend (pull_request) Successful in 9m43s
CI / lint (push) Successful in 9m53s
CI / lint (pull_request) Successful in 9m49s
Build Test / Build and Test (pull_request) Successful in 12m57s
Tests / test (push) Successful in 14m2s
Benchmarks / benchmark (push) Successful in 14m29s
Build and Publish Docker Image / build-dev (pull_request) Successful in 19m25s
Tests / test (pull_request) Failing after 23m6s
Benchmarks / benchmark (pull_request) Successful in 29m13s
Build Test / Build and Test (push) Successful in 45m58s
feat(ui): enhance user experience with new features including QR code display, improved toast messages, and localized strings for various components
2026-01-05 19:22:25 -06:00

80 lines
2.6 KiB
JavaScript

import { mount } from "@vue/test-utils";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import Toast from "@/components/Toast.vue";
import GlobalEmitter from "@/js/GlobalEmitter";
describe("Toast.vue", () => {
let wrapper;
beforeEach(() => {
vi.useFakeTimers();
wrapper = mount(Toast, {
global: {
mocks: {
$t: (msg) => msg,
},
stubs: {
TransitionGroup: { template: "<div><slot /></div>" },
MaterialDesignIcon: {
name: "MaterialDesignIcon",
template: '<div class="mdi-stub"></div>',
props: ["iconName"],
},
},
},
});
});
afterEach(() => {
if (wrapper) {
wrapper.unmount();
}
vi.useRealTimers();
});
it("adds a toast when GlobalEmitter emits 'toast'", async () => {
GlobalEmitter.emit("toast", { message: "Test Message", type: "success" });
await wrapper.vm.$nextTick();
expect(wrapper.text()).toContain("Test Message");
const icon = wrapper.findComponent({ name: "MaterialDesignIcon" });
expect(icon.exists()).toBe(true);
expect(icon.props("iconName")).toBe("check-circle");
});
it("removes a toast after duration", async () => {
GlobalEmitter.emit("toast", { message: "Test Message", duration: 1000 });
await wrapper.vm.$nextTick();
expect(wrapper.text()).toContain("Test Message");
vi.advanceTimersByTime(1001);
await wrapper.vm.$nextTick();
expect(wrapper.text()).not.toContain("Test Message");
});
it("removes a toast when clicking the close button", async () => {
GlobalEmitter.emit("toast", { message: "Test Message", duration: 0 });
await wrapper.vm.$nextTick();
expect(wrapper.text()).toContain("Test Message");
const closeButton = wrapper.find("button");
await closeButton.trigger("click");
await wrapper.vm.$nextTick();
expect(wrapper.text()).not.toContain("Test Message");
});
it("assigns correct classes for different toast types", async () => {
GlobalEmitter.emit("toast", { message: "Success", type: "success" });
GlobalEmitter.emit("toast", { message: "Error", type: "error" });
await wrapper.vm.$nextTick();
const toasts = wrapper.findAll(".pointer-events-auto");
expect(toasts[0].classes()).toContain("border-green-500/30");
expect(toasts[1].classes()).toContain("border-red-500/30");
});
});