Files
lucia-frontend/tests/stores/pageAdmin.test.js

101 lines
3.2 KiB
JavaScript

// The Lucia project.
// Copyright 2026-2026 DSP, inc. All rights reserved.
// Authors:
// imacat.yang@dsp.im (imacat), 2026/03/05
import { describe, it, expect, beforeEach } from "vitest";
import { setActivePinia, createPinia } from "pinia";
import { usePageAdminStore } from "@/stores/pageAdmin";
describe("pageAdminStore", () => {
let store;
beforeEach(() => {
setActivePinia(createPinia());
store = usePageAdminStore();
});
it("has correct default state", () => {
expect(store.activePage).toBe("MAP");
expect(store.previousPage).toBe("MAP");
expect(store.pendingActivePage).toBe("FILES");
expect(store.isPagePending).toBe(false);
expect(store.shouldKeepPreviousPage).toBe(false);
expect(store.currentMapFile).toBe("");
});
it("setActivePage converts page name", () => {
store.setActivePage("CheckConformance");
expect(store.activePage).toBe("CONFORMANCE");
});
it("setPreviousPage converts page name", () => {
store.setPreviousPage("CheckPerformance");
expect(store.previousPage).toBe("PERFORMANCE");
});
it("setPreviousPageUsingActivePage copies activePage to previousPage", () => {
store.setActivePage("CONFORMANCE");
store.setPreviousPageUsingActivePage();
expect(store.previousPage).toBe("CONFORMANCE");
});
it("setIsPagePendingBoolean sets boolean", () => {
store.setIsPagePendingBoolean(true);
expect(store.isPagePending).toBe(true);
});
it("setPendingActivePage converts and sets page", () => {
store.setPendingActivePage("CheckMap");
expect(store.pendingActivePage).toBe("MAP");
});
it("setPendingActivePage maps CompareDashboard to PERFORMANCE", () => {
store.setPendingActivePage("CompareDashboard");
expect(store.pendingActivePage).toBe("PERFORMANCE");
});
it("copyPendingPageToActivePage transfers value", () => {
store.setPendingActivePage("CheckConformance");
store.copyPendingPageToActivePage();
expect(store.activePage).toBe("CONFORMANCE");
});
it("clearPendingActivePage resets to empty", () => {
store.setPendingActivePage("CheckMap");
store.clearPendingActivePage();
expect(store.pendingActivePage).toBe("");
});
it("keepPreviousPage restores previous page", () => {
store.setPreviousPage("CONFORMANCE");
store.setActivePage("PERFORMANCE");
store.keepPreviousPage();
expect(store.activePage).toBe("CONFORMANCE");
expect(store.shouldKeepPreviousPage).toBe(true);
});
it("clearShouldKeepPreviousPageBoolean resets flag", () => {
store.keepPreviousPage();
store.clearShouldKeepPreviousPageBoolean();
expect(store.shouldKeepPreviousPage).toBe(false);
});
it("setCurrentMapFile sets file name", () => {
store.setCurrentMapFile("test.csv");
expect(store.currentMapFile).toBe("test.csv");
});
it("setActivePageComputedByRoute extracts route name", () => {
const routeMatched = [{ name: "CheckMap" }];
store.setActivePageComputedByRoute(routeMatched);
expect(store.activePageComputedByRoute).toBe("MAP");
});
it("setActivePageComputedByRoute handles empty array", () => {
store.setActivePageComputedByRoute([]);
// Should not change default value
expect(store.activePageComputedByRoute).toBe("MAP");
});
});