|
@@ -3,6 +3,8 @@
|
|
|
import { describe, it, expect } from "vitest";
|
|
import { describe, it, expect } from "vitest";
|
|
|
import {
|
|
import {
|
|
|
SEARCH_SCOPE,
|
|
SEARCH_SCOPE,
|
|
|
|
|
+ SEARCH_LIMITS,
|
|
|
|
|
+ DEFAULT_SEARCH_LIMIT,
|
|
|
parseBranchesCsv,
|
|
parseBranchesCsv,
|
|
|
serializeBranchesCsv,
|
|
serializeBranchesCsv,
|
|
|
parseSearchUrlState,
|
|
parseSearchUrlState,
|
|
@@ -40,6 +42,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
scope: SEARCH_SCOPE.SINGLE,
|
|
scope: SEARCH_SCOPE.SINGLE,
|
|
|
branch: "NL01",
|
|
branch: "NL01",
|
|
|
branches: [],
|
|
branches: [],
|
|
|
|
|
+ limit: DEFAULT_SEARCH_LIMIT,
|
|
|
from: null,
|
|
from: null,
|
|
|
to: null,
|
|
to: null,
|
|
|
});
|
|
});
|
|
@@ -53,6 +56,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
expect(state.q).toBe("test");
|
|
expect(state.q).toBe("test");
|
|
|
expect(state.branch).toBe("NL02");
|
|
expect(state.branch).toBe("NL02");
|
|
|
expect(state.branches).toEqual([]);
|
|
expect(state.branches).toEqual([]);
|
|
|
|
|
+ expect(SEARCH_LIMITS.includes(state.limit)).toBe(true);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it("parses ALL when scope=all is set (highest precedence)", () => {
|
|
it("parses ALL when scope=all is set (highest precedence)", () => {
|
|
@@ -61,6 +65,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
scope: "all",
|
|
scope: "all",
|
|
|
branch: "NL01",
|
|
branch: "NL01",
|
|
|
branches: "NL06,NL20",
|
|
branches: "NL06,NL20",
|
|
|
|
|
+ limit: "200",
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const state = parseSearchUrlState(sp, { routeBranch: "NL99" });
|
|
const state = parseSearchUrlState(sp, { routeBranch: "NL99" });
|
|
@@ -70,6 +75,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
scope: SEARCH_SCOPE.ALL,
|
|
scope: SEARCH_SCOPE.ALL,
|
|
|
branch: null,
|
|
branch: null,
|
|
|
branches: [],
|
|
branches: [],
|
|
|
|
|
+ limit: 200,
|
|
|
from: null,
|
|
from: null,
|
|
|
to: null,
|
|
to: null,
|
|
|
});
|
|
});
|
|
@@ -80,6 +86,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
q: " reifen ",
|
|
q: " reifen ",
|
|
|
scope: "multi",
|
|
scope: "multi",
|
|
|
branches: "NL06, NL20, NL06",
|
|
branches: "NL06, NL20, NL06",
|
|
|
|
|
+ limit: "50",
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const state = parseSearchUrlState(sp, { routeBranch: "NL01" });
|
|
const state = parseSearchUrlState(sp, { routeBranch: "NL01" });
|
|
@@ -88,6 +95,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
expect(state.q).toBe("reifen");
|
|
expect(state.q).toBe("reifen");
|
|
|
expect(state.branch).toBe(null);
|
|
expect(state.branch).toBe(null);
|
|
|
expect(state.branches).toEqual(["NL06", "NL20"]);
|
|
expect(state.branches).toEqual(["NL06", "NL20"]);
|
|
|
|
|
+ expect(state.limit).toBe(50);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it("parses MULTI when branches=... is present even without scope", () => {
|
|
it("parses MULTI when branches=... is present even without scope", () => {
|
|
@@ -100,6 +108,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
|
|
|
|
|
expect(state.scope).toBe(SEARCH_SCOPE.MULTI);
|
|
expect(state.scope).toBe(SEARCH_SCOPE.MULTI);
|
|
|
expect(state.branches).toEqual(["NL06", "NL20"]);
|
|
expect(state.branches).toEqual(["NL06", "NL20"]);
|
|
|
|
|
+ expect(state.limit).toBe(DEFAULT_SEARCH_LIMIT);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it("keeps from/to when provided", () => {
|
|
it("keeps from/to when provided", () => {
|
|
@@ -108,12 +117,20 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
branch: "NL01",
|
|
branch: "NL01",
|
|
|
from: "2025-12-01",
|
|
from: "2025-12-01",
|
|
|
to: "2025-12-31",
|
|
to: "2025-12-31",
|
|
|
|
|
+ limit: "200",
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const state = parseSearchUrlState(sp, { routeBranch: "NL01" });
|
|
const state = parseSearchUrlState(sp, { routeBranch: "NL01" });
|
|
|
|
|
|
|
|
expect(state.from).toBe("2025-12-01");
|
|
expect(state.from).toBe("2025-12-01");
|
|
|
expect(state.to).toBe("2025-12-31");
|
|
expect(state.to).toBe("2025-12-31");
|
|
|
|
|
+ expect(state.limit).toBe(200);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it("falls back to default limit for invalid values", () => {
|
|
|
|
|
+ const sp = new URLSearchParams({ q: "x", branch: "NL01", limit: "999" });
|
|
|
|
|
+ const state = parseSearchUrlState(sp, { routeBranch: "NL01" });
|
|
|
|
|
+ expect(state.limit).toBe(DEFAULT_SEARCH_LIMIT);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -123,6 +140,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
q: "bridgestone",
|
|
q: "bridgestone",
|
|
|
scope: SEARCH_SCOPE.SINGLE,
|
|
scope: SEARCH_SCOPE.SINGLE,
|
|
|
branch: "NL01",
|
|
branch: "NL01",
|
|
|
|
|
+ limit: DEFAULT_SEARCH_LIMIT,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(qs).toBe("q=bridgestone&branch=NL01");
|
|
expect(qs).toBe("q=bridgestone&branch=NL01");
|
|
@@ -133,6 +151,7 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
q: "reifen",
|
|
q: "reifen",
|
|
|
scope: SEARCH_SCOPE.MULTI,
|
|
scope: SEARCH_SCOPE.MULTI,
|
|
|
branches: ["NL06", "NL20"],
|
|
branches: ["NL06", "NL20"],
|
|
|
|
|
+ limit: DEFAULT_SEARCH_LIMIT,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(qs).toBe("q=reifen&scope=multi&branches=NL06%2CNL20");
|
|
expect(qs).toBe("q=reifen&scope=multi&branches=NL06%2CNL20");
|
|
@@ -142,21 +161,36 @@ describe("lib/frontend/search/urlState", () => {
|
|
|
const qs = serializeSearchUrlState({
|
|
const qs = serializeSearchUrlState({
|
|
|
q: "x",
|
|
q: "x",
|
|
|
scope: SEARCH_SCOPE.ALL,
|
|
scope: SEARCH_SCOPE.ALL,
|
|
|
|
|
+ limit: DEFAULT_SEARCH_LIMIT,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(qs).toBe("q=x&scope=all");
|
|
expect(qs).toBe("q=x&scope=all");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ it("includes limit when non-default", () => {
|
|
|
|
|
+ const qs = serializeSearchUrlState({
|
|
|
|
|
+ q: "x",
|
|
|
|
|
+ scope: SEARCH_SCOPE.SINGLE,
|
|
|
|
|
+ branch: "NL01",
|
|
|
|
|
+ limit: 200,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(qs).toBe("q=x&branch=NL01&limit=200");
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
it("includes from/to when present (future-proof for RHL-025)", () => {
|
|
it("includes from/to when present (future-proof for RHL-025)", () => {
|
|
|
const qs = serializeSearchUrlState({
|
|
const qs = serializeSearchUrlState({
|
|
|
q: "x",
|
|
q: "x",
|
|
|
scope: SEARCH_SCOPE.SINGLE,
|
|
scope: SEARCH_SCOPE.SINGLE,
|
|
|
branch: "NL01",
|
|
branch: "NL01",
|
|
|
|
|
+ limit: 200,
|
|
|
from: "2025-12-01",
|
|
from: "2025-12-01",
|
|
|
to: "2025-12-31",
|
|
to: "2025-12-31",
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- expect(qs).toBe("q=x&branch=NL01&from=2025-12-01&to=2025-12-31");
|
|
|
|
|
|
|
+ expect(qs).toBe(
|
|
|
|
|
+ "q=x&branch=NL01&limit=200&from=2025-12-01&to=2025-12-31"
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|