Commit 1ce4b37f by 前端

Merge branch 'SAAS+V5.8.3.2' into 'develop'

上线合并

See merge request !834
2 parents c4cda7d8 20d11e27
const expiryKeys = [
"compulsoryInsuranceExpiry",
"annualInspectionExpiry",
"commercialInsuranceExpiry",
];
function getLocalDate(value) {
if (!value) {
return null;
}
if (value instanceof Date) {
return new Date(value.getFullYear(), value.getMonth(), value.getDate());
}
const matched = String(value).match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})/);
if (matched) {
return new Date(
Number(matched[1]),
Number(matched[2]) - 1,
Number(matched[3]),
);
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return null;
}
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
}
export function getExpiryTextStyle(item, row) {
if (!item || !expiryKeys.includes(item.key) || !row) {
return {};
}
const expiryDate = getLocalDate(row[item.key]);
if (!expiryDate) {
return {};
}
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const diffDays = Math.ceil((expiryDate.getTime() - today.getTime()) / 86400000);
if (diffDays < 0) {
return { color: "#EB4E4E" };
}
if (diffDays <= 30) {
return { color: "#FF8D1A" };
}
return {};
}
import { getExpiryTextStyle } from "./vehicleInfoExpiry";
describe("vehicleInfo expiry date colors", () => {
beforeEach(() => {
jest.useFakeTimers("modern");
jest.setSystemTime(new Date(2026, 6, 6));
});
afterEach(() => {
jest.useRealTimers();
});
it("marks expired expiry fields red", () => {
const style = getExpiryTextStyle(
{ key: "annualInspectionExpiry" },
{ annualInspectionExpiry: "2026-07-05" },
);
expect(style).toEqual({ color: "#EB4E4E" });
});
it("marks expiry fields within thirty days orange", () => {
const style = getExpiryTextStyle(
{ key: "commercialInsuranceExpiry" },
{ commercialInsuranceExpiry: "2026-08-05" },
);
expect(style).toEqual({ color: "#FF8D1A" });
});
it("keeps non-expiry fields and later dates default", () => {
expect(getExpiryTextStyle(
{ key: "licensePlate" },
{ licensePlate: "A12345" },
)).toEqual({});
expect(getExpiryTextStyle(
{ key: "compulsoryInsuranceExpiry" },
{ compulsoryInsuranceExpiry: "2026-08-06" },
)).toEqual({});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!