vehicleInfoExpiry.spec.js 1.02 KB
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({});
	});
});