Files
Ewald 85a82f130a test: migrate ui/tests from .mjs to .ts
- Rename 132 *.vitest.mjs -> *.vitest.ts
- Rename vitest.setup.mjs -> vitest.setup.ts
- Rename helpers/vitestEnvironment.mjs -> vitestEnvironment.ts
- Delete settings_store.test.mjs (Node test runner, superseded by .vitest.ts)
- Fix .mjs imports in vitest.setup.ts and grid_loader_adaptive_paging.vitest.ts

Config updates:
- vitest.config.mjs: setupFiles, include, coverage.include -> .ts
- tsconfig.test.json: new dedicated config for test files (strict:false)
- knip.json: update project pattern for tests
- package.json: add typecheck:tests script (audit-only)
2026-05-26 13:04:05 +02:00

71 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { normalizeQuery } from "../features/panel/controllers/query.js";
describe("normalizeQuery", () => {
it('returns "*" for null input', () => {
expect(normalizeQuery(null)).toBe("*");
});
it('returns "*" for undefined input', () => {
expect(normalizeQuery(undefined)).toBe("*");
});
it('returns "*" for empty string value', () => {
expect(normalizeQuery({ value: "" })).toBe("*");
});
it('returns "*" for whitespace-only value', () => {
expect(normalizeQuery({ value: " " })).toBe("*");
});
it("trims and returns non-empty string value", () => {
expect(normalizeQuery({ value: " flowers " })).toBe("flowers");
});
it("handles an input element-like object with tagName INPUT", () => {
const input = { tagName: "INPUT", value: "cats" };
expect(normalizeQuery(input)).toBe("cats");
});
it("handles nested .value wrapping (Vue ref-like)", () => {
const ref = { value: { value: { tagName: "INPUT", value: "dogs" } } };
expect(normalizeQuery(ref)).toBe("dogs");
});
it("handles an object with querySelector returning an input", () => {
const container = {
tagName: "DIV",
querySelector(sel) {
if (sel === "#mjr-search-input") {
return { tagName: "INPUT", value: "landscapes" };
}
return null;
},
};
expect(normalizeQuery(container)).toBe("landscapes");
});
it("falls back to mjr-input class when #mjr-search-input is not found", () => {
const container = {
tagName: "DIV",
querySelector(sel) {
if (sel === "input.mjr-input") {
return { tagName: "INPUT", value: "portraits" };
}
return null;
},
};
expect(normalizeQuery(container)).toBe("portraits");
});
it('returns "*" for a completely empty object', () => {
expect(normalizeQuery({})).toBe("*");
});
it("handles a textarea element", () => {
const textarea = { tagName: "TEXTAREA", value: "prompt text" };
expect(normalizeQuery(textarea)).toBe("prompt text");
});
});