lookup vehicle-kinds added

This commit is contained in:
2026-09-28 17:09:45 +03:30
parent efef48d824
commit 7a8d96ab52
10 changed files with 614 additions and 10 deletions

View File

@@ -0,0 +1,49 @@
import {
asVehicleKindRows,
isVehicleKindsSyncStale,
normalizeVehicleKindCaptionSearch,
VEHICLE_KINDS_REFRESH_MS,
} from "./vehicle-kind-search";
describe("vehicle-kind-search", () => {
it("normalizes Arabic yeh/keheh so كاميون matches کامیون", () => {
expect(normalizeVehicleKindCaptionSearch("كاميون")).toBe(
normalizeVehicleKindCaptionSearch("کامیون"),
);
expect(normalizeVehicleKindCaptionSearch("ولوو")).toContain("ولوو");
});
it("treats missing or old syncedAt as stale after one week", () => {
expect(isVehicleKindsSyncStale(null)).toBe(true);
const now = new Date("2026-09-28T12:00:00Z");
expect(
isVehicleKindsSyncStale(
new Date("2026-09-20T12:00:00Z"),
now,
VEHICLE_KINDS_REFRESH_MS,
),
).toBe(true);
expect(
isVehicleKindsSyncStale(
new Date("2026-09-25T12:00:00Z"),
now,
VEHICLE_KINDS_REFRESH_MS,
),
).toBe(false);
});
it("maps Fanavaran rows and drops invalid Ids", () => {
const rows = asVehicleKindRows([
{ Id: 6645, Caption: "کاميون کشنده ولوو FH12 4*2", IsActive: 1 },
{ Id: "bad", Caption: "x", IsActive: 1 },
{ Id: 1, Caption: "سایر", IsActive: 0 },
]);
expect(rows).toHaveLength(2);
expect(rows[0]).toMatchObject({
Id: 6645,
Caption: "کاميون کشنده ولوو FH12 4*2",
IsActive: 1,
});
expect(rows[1].IsActive).toBe(0);
});
});