Files
redis-gui-foundation/apps/desktop/src/lib/key-browser-search.test.ts
Senior Frontend Engineer bf6f8bc0bf feat(desktop): clarify key browser search states
Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-31 08:02:18 +00:00

84 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
buildInspectorEmptyStateMessage,
buildKeyBrowserEmptyStateMessage,
buildKeyBrowserStatusMessage,
resolveKeyBrowserSearchState,
} from "./key-browser-search";
describe("key browser search helpers", () => {
it("classifies blank, contains, and wildcard search input", () => {
expect(resolveKeyBrowserSearchState(" ")).toEqual({
trimmedQuery: "",
requestPattern: null,
mode: "all",
});
expect(resolveKeyBrowserSearchState(" smoke ")).toEqual({
trimmedQuery: "smoke",
requestPattern: "*smoke*",
mode: "contains",
});
expect(resolveKeyBrowserSearchState("smoke:*")).toEqual({
trimmedQuery: "smoke:*",
requestPattern: "smoke:*",
mode: "pattern",
});
});
it("builds a stable status message for visible counts and load state", () => {
expect(
buildKeyBrowserStatusMessage({
databaseLabel: "db0",
visibleCount: 7,
hasMore: true,
isLoading: false,
search: resolveKeyBrowserSearchState("smoke"),
}),
).toBe('7+ keys visible for contains search "smoke" in db0.');
expect(
buildKeyBrowserStatusMessage({
databaseLabel: "db3",
visibleCount: 0,
hasMore: false,
isLoading: true,
search: resolveKeyBrowserSearchState("smoke:*"),
}),
).toBe('Searching db3 for "smoke:*".');
});
it("builds browser empty-state copy for blank and filtered results", () => {
expect(
buildKeyBrowserEmptyStateMessage({
databaseLabel: "db0",
isLoading: false,
search: resolveKeyBrowserSearchState(""),
}),
).toBe("No keys are visible in db0 yet.");
expect(
buildKeyBrowserEmptyStateMessage({
databaseLabel: "db2",
isLoading: false,
search: resolveKeyBrowserSearchState("audit:*"),
}),
).toBe('No keys match "audit:*" in db2.');
});
it("keeps inspector empty-state guidance aligned with browser search state", () => {
expect(
buildInspectorEmptyStateMessage("db1", resolveKeyBrowserSearchState("")),
).toBe(
"No keys are visible in db1 yet. Browse another database or refresh after data arrives.",
);
expect(
buildInspectorEmptyStateMessage("db4", resolveKeyBrowserSearchState("jobs")),
).toBe(
'No keys match "jobs" in db4. Clear or adjust the search to restore an inspector target.',
);
});
});