orderListRouteParams.spec.js 1.89 KB
const {
	LEGACY_TAB_PANE,
	LEGACY_LABEL_TO_PANE,
	resolveTabPaneFromParams,
	computeRouteParamPatch,
} = require("@/views/orderManage/utils/orderListRouteParams");

describe("orderListRouteParams", () => {
	describe("resolveTabPaneFromParams", () => {
		it("maps tabPane 1 to pane key", () => {
			expect(resolveTabPaneFromParams({ tabPane: "1" })).toBe("1");
		});

		it("maps tabLabel order to pane 1", () => {
			expect(resolveTabPaneFromParams({ tabLabel: "order" })).toBe("1");
		});

		it("maps tabLabel integral-shopping to pane 5", () => {
			expect(resolveTabPaneFromParams({ tabLabel: "integral-shopping" })).toBe("5");
		});

		it("returns null for empty params", () => {
			expect(resolveTabPaneFromParams({})).toBeNull();
			expect(resolveTabPaneFromParams(null)).toBeNull();
		});

		it("returns null for unknown tabPane", () => {
			expect(resolveTabPaneFromParams({ tabPane: "99" })).toBe("99");
		});
	});

	describe("computeRouteParamPatch", () => {
		it("maps tabPane 1 to light category and l-1-1 leaf", () => {
			expect(computeRouteParamPatch({ tabPane: "1" })).toEqual({
				activeCategory: "light",
				pendingLegacyLeaf: "l-1-1",
				rightsFromLegacyTab4: false,
				isApplyingRoute: true,
			});
		});

		it("maps tabPane 4 with carDamage label to rights and legacyRightsAll", () => {
			expect(computeRouteParamPatch({ tabPane: "4", tabLabel: "carDamage" })).toEqual({
				activeCategory: "rights",
				pendingLegacyLeaf: "l-2-1",
				rightsFromLegacyTab4: true,
				isApplyingRoute: true,
			});
		});

		it("returns null for empty params", () => {
			expect(computeRouteParamPatch({})).toBeNull();
		});

		it("returns null for unknown tabPane mapping", () => {
			expect(computeRouteParamPatch({ tabPane: "99" })).toBeNull();
		});
	});

	it("exports legacy maps for orderList shell", () => {
		expect(LEGACY_TAB_PANE["1"].category).toBe("light");
		expect(LEGACY_LABEL_TO_PANE.order).toBe("1");
	});
});