- Introduced `.prettierrc.json` to enforce consistent code formatting across the project. - Updated unit and e2e test files to address formatting issues, improve readability, and ensure alignment with the new Prettier configuration.
124 lines
4.2 KiB
JavaScript
124 lines
4.2 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import { SYSTEM_SEARCH_ENTITY_TYPES } from "@/components/viewport/page/headers/menu/systemSearchSupport.ts";
|
|
import {
|
|
SYSTEM_SEARCH_UI_ENTITY_ORDER,
|
|
groupSystemSearchResults,
|
|
moveSystemSearchSelection,
|
|
shouldBypassTextEntryForSystemSearchKey,
|
|
sortSystemSearchResults,
|
|
sortSystemSearchGroupKeys,
|
|
syncSystemSearchKeyboardState,
|
|
} from "@/components/viewport/page/headers/menu/systemSearchUiSupport.ts";
|
|
|
|
const row = (entityType, entityId) => ({
|
|
entity_type: entityType,
|
|
entity_id: String(entityId),
|
|
title: `${entityType}-${entityId}`,
|
|
score: 100,
|
|
});
|
|
|
|
describe("system search UI ordering support", () => {
|
|
it("keeps customers, orders, and order bookings at the front of the UI order while covering every known type", () => {
|
|
expect(SYSTEM_SEARCH_UI_ENTITY_ORDER.slice(0, 3)).toEqual(["customers", "orders", "order_bookings"]);
|
|
expect(new Set(SYSTEM_SEARCH_UI_ENTITY_ORDER).size).toBe(SYSTEM_SEARCH_UI_ENTITY_ORDER.length);
|
|
expect([...SYSTEM_SEARCH_UI_ENTITY_ORDER].sort()).toEqual([...SYSTEM_SEARCH_ENTITY_TYPES].sort());
|
|
});
|
|
|
|
it("sorts flat results by UI category order while preserving order inside each category", () => {
|
|
const sorted = sortSystemSearchResults([
|
|
row("orders", 2),
|
|
row("module_config", 9),
|
|
row("customers", 7),
|
|
row("order_bookings", 4),
|
|
row("orders", 5),
|
|
row("notifications", 3),
|
|
]);
|
|
|
|
expect(sorted.map((entry) => `${entry.entity_type}:${entry.entity_id}`)).toEqual([
|
|
"customers:7",
|
|
"orders:2",
|
|
"orders:5",
|
|
"order_bookings:4",
|
|
"module_config:9",
|
|
"notifications:3",
|
|
]);
|
|
});
|
|
|
|
it("orders grouped keys with unknown values after known entity types", () => {
|
|
expect(sortSystemSearchGroupKeys(["orders", "mystery", "customers", "order_bookings"])).toEqual([
|
|
"customers",
|
|
"orders",
|
|
"order_bookings",
|
|
"mystery",
|
|
]);
|
|
});
|
|
|
|
it("builds grouped results in the same UI order as the flat list", () => {
|
|
const grouped = groupSystemSearchResults([
|
|
row("orders", 2),
|
|
row("customers", 7),
|
|
row("order_bookings", 4),
|
|
row("orders", 5),
|
|
]);
|
|
|
|
expect(Object.keys(grouped)).toEqual(["customers", "orders", "order_bookings"]);
|
|
expect(grouped.orders.map((entry) => entry.entity_id)).toEqual(["2", "5"]);
|
|
});
|
|
});
|
|
|
|
describe("system search keyboard selection support", () => {
|
|
it("defaults sidebar and result selection to the active group and first result", () => {
|
|
const synced = syncSystemSearchKeyboardState(
|
|
{
|
|
pane: "results",
|
|
selectedSidebarKey: null,
|
|
selectedResultKey: null,
|
|
},
|
|
["all", "customers", "orders"],
|
|
["customers-7", "orders-2"],
|
|
"all"
|
|
);
|
|
|
|
expect(synced).toEqual({
|
|
pane: "results",
|
|
selectedSidebarKey: "all",
|
|
selectedResultKey: "customers-7",
|
|
});
|
|
});
|
|
|
|
it("falls back to sidebar mode when the selected result disappears", () => {
|
|
const synced = syncSystemSearchKeyboardState(
|
|
{
|
|
pane: "results",
|
|
selectedSidebarKey: "customers",
|
|
selectedResultKey: "missing",
|
|
},
|
|
["all", "customers", "orders"],
|
|
[],
|
|
"customers"
|
|
);
|
|
|
|
expect(synced).toEqual({
|
|
pane: "sidebar",
|
|
selectedSidebarKey: "customers",
|
|
selectedResultKey: null,
|
|
});
|
|
});
|
|
|
|
it("moves selection up and down without wrapping past the list edges", () => {
|
|
const keys = ["customers", "orders", "order_bookings"];
|
|
|
|
expect(moveSystemSearchSelection(keys, null, 1)).toBe("customers");
|
|
expect(moveSystemSearchSelection(keys, "customers", -1)).toBe("customers");
|
|
expect(moveSystemSearchSelection(keys, "orders", 1)).toBe("order_bookings");
|
|
expect(moveSystemSearchSelection(keys, "order_bookings", 1)).toBe("order_bookings");
|
|
});
|
|
|
|
it("keeps navigation keys active when text focus lingers outside query mode", () => {
|
|
expect(shouldBypassTextEntryForSystemSearchKey("sidebar", "Enter")).toBe(true);
|
|
expect(shouldBypassTextEntryForSystemSearchKey("results", "ArrowDown")).toBe(true);
|
|
expect(shouldBypassTextEntryForSystemSearchKey("query", "Enter")).toBe(false);
|
|
expect(shouldBypassTextEntryForSystemSearchKey("results", "a")).toBe(false);
|
|
});
|
|
});
|