Files
MeshChatX/tests/frontend/BanishedPage.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

130 lines
4.5 KiB
JavaScript

import { mount } from "@vue/test-utils";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import BlockedPage from "@/components/blocked/BlockedPage.vue";
import GlobalState from "@/js/GlobalState";
describe("BlockedPage.vue (Banished UI)", () => {
let axiosMock;
beforeEach(() => {
axiosMock = {
get: vi.fn(),
post: vi.fn(),
delete: vi.fn(),
};
window.axios = axiosMock;
// Mock localization
const t = (key) => {
const translations = {
"common.save": "Save",
"common.cancel": "Cancel",
};
return translations[key] || key;
};
axiosMock.get.mockImplementation((url) => {
if (url === "/api/v1/blocked-destinations") {
return Promise.resolve({
data: {
blocked_destinations: [
{ destination_hash: "a".repeat(32), created_at: "2026-01-04T12:00:00Z" },
],
},
});
}
if (url === "/api/v1/reticulum/blackhole") {
return Promise.resolve({
data: {
blackholed_identities: {
["b".repeat(32)]: {
source: "c".repeat(32),
reason: "Spam",
until: null,
},
},
},
});
}
if (url === "/api/v1/announces") {
return Promise.resolve({ data: { announces: [] } });
}
return Promise.resolve({ data: {} });
});
});
afterEach(() => {
delete window.axios;
});
const mountBlockedPage = () => {
return mount(BlockedPage, {
global: {
mocks: {
$t: (key) => {
const translations = {
"banishment.title": "Banished",
"banishment.description": "Manage Banished users and nodes",
"banishment.lift_banishment": "Lift Banishment",
"banishment.user": "User",
"banishment.node": "Node",
"banishment.banished_at": "Banished at",
};
return translations[key] || key;
},
},
stubs: {
MaterialDesignIcon: {
template: '<div class="mdi-stub" :data-icon-name="iconName"></div>',
props: ["iconName"],
},
},
},
});
};
it("displays 'Banished' title and subtext", async () => {
const wrapper = mountBlockedPage();
// Wait for isLoading to become false
await vi.waitFor(() => expect(wrapper.vm.isLoading).toBe(false));
expect(wrapper.text()).toContain("Banished");
expect(wrapper.text()).toContain("Manage Banished users and nodes");
});
it("combines local blocked and RNS blackholed items", async () => {
const wrapper = mountBlockedPage();
await vi.waitFor(() => expect(wrapper.vm.isLoading).toBe(false));
expect(wrapper.vm.allBlockedItems.length).toBe(2);
const rnsItem = wrapper.vm.allBlockedItems.find((i) => i.is_rns_blackholed);
expect(rnsItem).toBeDefined();
expect(rnsItem.destination_hash).toBe("b".repeat(32));
expect(rnsItem.rns_reason).toBe("Spam");
});
it("displays RNS Blackhole badge for blackholed items", async () => {
const wrapper = mountBlockedPage();
await vi.waitFor(() => expect(wrapper.vm.isLoading).toBe(false));
expect(wrapper.text()).toContain("RNS Blackhole");
});
it("calls delete API when lifting banishment", async () => {
// Mock DialogUtils.confirm
const DialogUtils = await import("@/js/DialogUtils");
vi.spyOn(DialogUtils.default, "confirm").mockResolvedValue(true);
const wrapper = mountBlockedPage();
await vi.waitFor(() => expect(wrapper.vm.isLoading).toBe(false));
const unblockButtons = wrapper.findAll("button").filter((b) => b.text().includes("Lift Banishment"));
expect(unblockButtons.length).toBeGreaterThan(0);
await unblockButtons[0].trigger("click");
expect(axiosMock.delete).toHaveBeenCalled();
});
});