You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { describe, expect, it } from "vitest";
import {
convertDimInputValue,
convertWeightInputValue,
describeDimEquivalent,
describeWeightEquivalent,
displayUnitToCargoUnits,
} from "@/lib/frontend/cargo-form-units";
import {
buildDimDisplayForUnit,
inferDimUnitFromFieldHint,
} from "@/workers/rpa/cargo-dimensions";
import { kgToLb } from "@/modules/quote/unit-converter";
describe("cargo-form-units", () => {
it("500 lb 切 kg 应约为 226.8", () => {
const kg = convertWeightInputValue(500, "lb", "kg");
expect(kg).toBeCloseTo(226.8, 1);
expect(kgToLb(kg)).toBeCloseTo(500, 0);
});
it("500 kg 询价提示为 1103 lb", () => {
expect(describeWeightEquivalent(500, "kg")).toBe(
"询价将按 1103 lb500 kg 换算,小数进一)",
);
});
it("48 cm 询价提示为 19 in", () => {
expect(describeDimEquivalent(48, 40, 48, "cm")).toBe(
"询价将按 19 × 16 × 19 in厘米换算小数进一",
);
});
it("48 in 切 cm 应约为 121.92", () => {
const cm = convertDimInputValue(48, "in", "cm");
expect(cm).toBeCloseTo(121.92, 1);
});
it("公制显示同步 kg/cm", () => {
expect(displayUnitToCargoUnits("metric")).toEqual({
weight: "kg",
dim: "cm",
});
});
});
describe("cargo-dimensions", () => {
it("cm 字段填入换算值", () => {
expect(inferDimUnitFromFieldHint("Length (cm)")).toBe("cm");
expect(buildDimDisplayForUnit(48, "cm")).toBe("121.92");
});
it("in 字段填入整英寸", () => {
expect(buildDimDisplayForUnit(47.24, "in")).toBe("48");
});
});