logos-storage-installer/src/ui/mainMenu.test.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2025-03-07 13:14:32 +01:00
import { describe, beforeEach, it, expect, vi } from "vitest";
import { MainMenu } from "./mainmenu.js";
2025-04-01 14:09:20 +02:00
import { mockUiService } from "../__mocks__/service.mocks.js";
import { mockInstallMenu, mockConfigMenu } from "../__mocks__/ui.mocks.js";
import { mockMenuLoop } from "../__mocks__/utils.mocks.js";
2025-03-07 13:14:32 +01:00
describe("mainmenu", () => {
let mainmenu;
2025-03-31 15:02:37 +02:00
2025-03-07 13:14:32 +01:00
beforeEach(() => {
vi.resetAllMocks();
2025-04-01 14:33:44 +02:00
mainmenu = new MainMenu(
mockUiService,
mockMenuLoop,
mockInstallMenu,
mockConfigMenu,
);
2025-04-01 14:09:20 +02:00
});
2025-03-07 13:14:32 +01:00
2025-04-01 14:09:20 +02:00
it("initializes the menu loop with the promptMainMenu function", () => {
2025-04-01 14:33:44 +02:00
expect(mockMenuLoop.initialize).toHaveBeenCalledWith(
mainmenu.promptMainMenu,
);
2025-03-07 13:14:32 +01:00
});
2025-04-01 14:09:20 +02:00
it("shows the logo", async () => {
2025-03-07 13:14:32 +01:00
await mainmenu.show();
expect(mockUiService.showLogo).toHaveBeenCalled();
2025-04-01 14:09:20 +02:00
});
it("starts the menu loop", async () => {
await mainmenu.show();
expect(mockMenuLoop.showLoop).toHaveBeenCalled();
});
it("shows the exit message after the menu loop", async () => {
await mainmenu.show();
expect(mockUiService.showInfoMessage).toHaveBeenCalledWith("K-THX-BYE");
});
2025-03-07 13:14:32 +01:00
2025-04-01 14:09:20 +02:00
it("prompts the main menu with multiple choices", async () => {
await mainmenu.promptMainMenu();
2025-03-07 13:14:32 +01:00
expect(mockUiService.askMultipleChoice).toHaveBeenCalledWith(
"Select an option",
[
{ label: "Install Codex", action: mockInstallMenu.show },
2025-03-31 15:02:37 +02:00
{ label: "Configure Codex", action: mockConfigMenu.show },
2025-04-01 14:09:20 +02:00
{ label: "Exit", action: mockMenuLoop.stopLoop },
2025-03-07 13:14:32 +01:00
],
);
});
});