51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
// @vitest-environment jsdom
|
|
import { mount } from "@vue/test-utils";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import i18n from "@/i18n";
|
|
import FrontendMaintenanceMenu from "@/components/global/FrontendMaintenanceMenu.vue";
|
|
import { forceFrontendUpdateAndClearLocal } from "@/services/frontendMaintenance.js";
|
|
|
|
vi.mock("@/services/frontendMaintenance.js", () => ({
|
|
forceFrontendUpdateAndClearLocal: vi.fn(async () => true),
|
|
}));
|
|
|
|
const flushMicrotasks = async () => {
|
|
await Promise.resolve();
|
|
await Promise.resolve();
|
|
};
|
|
|
|
const pressShift = () => {
|
|
window.dispatchEvent(new KeyboardEvent("keydown", { key: "Shift" }));
|
|
};
|
|
|
|
describe("FrontendMaintenanceMenu", () => {
|
|
it("opens after three Shift presses and runs the force update cleanup after in-app confirmation", async () => {
|
|
const confirmSpy = vi.spyOn(window, "confirm");
|
|
mount(FrontendMaintenanceMenu, {
|
|
global: {
|
|
plugins: [i18n],
|
|
},
|
|
});
|
|
|
|
expect(document.body.querySelector("[data-testid='frontend-maintenance-menu']")).toBeNull();
|
|
|
|
pressShift();
|
|
pressShift();
|
|
pressShift();
|
|
await flushMicrotasks();
|
|
|
|
expect(document.body.querySelector("[data-testid='frontend-maintenance-menu']")).not.toBeNull();
|
|
|
|
document.body.querySelector("[data-testid='frontend-maintenance-force-clear']").click();
|
|
await flushMicrotasks();
|
|
|
|
expect(document.body.querySelector("[data-testid='local-data-reset-dialog']")).not.toBeNull();
|
|
|
|
document.body.querySelector("[data-testid='local-data-reset-confirm']").click();
|
|
await flushMicrotasks();
|
|
|
|
expect(confirmSpy).not.toHaveBeenCalled();
|
|
expect(forceFrontendUpdateAndClearLocal).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|