M0.4: frontend with Vue 3, Pinia, ESLint, vue-tsc and Vitest
Empty workbench (main area and status bar) themed only through --lt-* tokens. ipc.ts wraps Tauri invoke so engine calls never reject; the app store loads app.about. Type-aware ESLint bans floating promises, any and inline comments. Requires Node 22.12+ for Vite 8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
acc055c063
commit
50bcc95006
15 changed files with 456 additions and 2 deletions
36
ui/tests/App.test.ts
Normal file
36
ui/tests/App.test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Tests for the root component: it loads product information on mount and
|
||||
* shows it, or the error, in the status bar.
|
||||
*/
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const invoke = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||
|
||||
import App from "../src/App.vue";
|
||||
|
||||
describe("App", () => {
|
||||
beforeEach(() => {
|
||||
invoke.mockReset();
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
it("shows name and version in the status bar", async () => {
|
||||
invoke.mockResolvedValue({ name: "Lutra", version: "0.0.0", slogan: "An otterly perfect IDE" });
|
||||
const wrapper = mount(App);
|
||||
await flushPromises();
|
||||
expect(wrapper.get("[data-test=status-bar]").text()).toBe("Lutra 0.0.0");
|
||||
expect(wrapper.get("[data-test=main]").text()).toBe("An otterly perfect IDE");
|
||||
});
|
||||
|
||||
it("shows the engine error when the call fails", async () => {
|
||||
invoke.mockRejectedValue({ code: "internal", message: "engine unavailable" });
|
||||
const wrapper = mount(App);
|
||||
await flushPromises();
|
||||
const bar = wrapper.get("[data-test=status-bar]");
|
||||
expect(bar.text()).toBe("engine unavailable");
|
||||
expect(bar.classes()).toContain("status-bar--error");
|
||||
});
|
||||
});
|
||||
55
ui/tests/ipc.test.ts
Normal file
55
ui/tests/ipc.test.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Tests for the engine bridge: results and every kind of rejection map to
|
||||
* a `RunResult` instead of a rejected promise.
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const invoke = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||
|
||||
import { listCommands, run, toEngineError } from "../src/ipc";
|
||||
|
||||
describe("run", () => {
|
||||
beforeEach(() => {
|
||||
invoke.mockReset();
|
||||
});
|
||||
|
||||
it("passes command and params to the shell", async () => {
|
||||
invoke.mockResolvedValue({ name: "Lutra" });
|
||||
const result = await run("app.about", { verbose: true });
|
||||
expect(invoke).toHaveBeenCalledWith("engine_execute", {
|
||||
command: "app.about",
|
||||
params: { verbose: true },
|
||||
});
|
||||
expect(result).toEqual({ ok: true, value: { name: "Lutra" } });
|
||||
});
|
||||
|
||||
it("returns engine errors instead of rejecting", async () => {
|
||||
invoke.mockRejectedValue({ code: "unknown_command", message: "no such command: x" });
|
||||
const result = await run("x");
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: { code: "unknown_command", message: "no such command: x" },
|
||||
});
|
||||
});
|
||||
|
||||
it("wraps unexpected rejections", async () => {
|
||||
invoke.mockRejectedValue(new Error("window.__TAURI_INTERNALS__ is undefined"));
|
||||
const result = await run("app.about");
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.ok ? null : result.error.code).toBe("ipc");
|
||||
});
|
||||
|
||||
it("lists commands", async () => {
|
||||
invoke.mockResolvedValue([]);
|
||||
expect(await listCommands()).toEqual({ ok: true, value: [] });
|
||||
expect(invoke).toHaveBeenCalledWith("engine_list_commands");
|
||||
});
|
||||
});
|
||||
|
||||
describe("toEngineError", () => {
|
||||
it("handles strings and malformed objects", () => {
|
||||
expect(toEngineError("boom")).toEqual({ code: "ipc", message: "boom" });
|
||||
expect(toEngineError({ code: 1, message: "x" }).code).toBe("ipc");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue