carDamagePerfMetrics.spec.js 2.22 KB
/**
 * 权益列表表格性能相关静态指标(用于回归对比,非运行时 benchmark)
 */
const fs = require("fs");
const path = require("path");

const CAR_DAMAGE_VUE = fs.readFileSync(
	path.resolve(__dirname, "../../../../src/views/orderManage/carDamage.vue"),
	"utf8",
);

function countMatches(source, pattern) {
	const matches = source.match(pattern);
	return matches ? matches.length : 0;
}

describe("carDamagePerfMetrics", () => {
	it("operation column should keep fixed right per product requirement", () => {
		expect(CAR_DAMAGE_VUE).toMatch(
			/<el-table-column[^>]*fixed="right"[^>]*label="操作"/,
		);
	});

	it("operation buttons should remain separate auth-button entries", () => {
		const operationSection = CAR_DAMAGE_VUE.match(
			/<el-table-column[^>]*label="操作"[\s\S]*?<\/el-table-column>/,
		);
		expect(operationSection).toBeTruthy();
		expect(operationSection[0]).toContain("auth-button");
		expect(operationSection[0]).not.toContain("el-dropdown");
	});

	it("sub-order columns should be in expand row not main v-for columns", () => {
		const mainSubOrderVFor = CAR_DAMAGE_VUE.match(
			/<el-table-column[^>]*label="商品名称"[\s\S]*?v-for="\(item, index\) in scope\.row\.subOrderList"/,
		);
		expect(mainSubOrderVFor).toBeNull();
	});

	it("should use row display mapper in getList", () => {
		expect(CAR_DAMAGE_VUE).toContain("mapCarDamageListRow");
	});

	it("page size max should be 20", () => {
		expect(CAR_DAMAGE_VUE).toMatch(/:page-sizes="\[10,\s*20\]/);
	});

	it("expand area should use native table instead of nested el-table", () => {
		expect(CAR_DAMAGE_VUE).not.toMatch(/<el-table :data="row\.subOrderDisplayList"/);
		expect(CAR_DAMAGE_VUE).toContain("order-sub-goods-table");
	});

	it("should use accordion expand-row-keys", () => {
		expect(CAR_DAMAGE_VUE).toContain(":expand-row-keys=\"expandedOrderCodes\"");
		expect(CAR_DAMAGE_VUE).toContain("@expand-change=\"handleExpandChange\"");
		expect(CAR_DAMAGE_VUE).toContain("handleExpandChange(row, expandedRows)");
	});

	it("main table has fewer columns than legacy ~50", () => {
		const mainColumnCount = countMatches(CAR_DAMAGE_VUE, /<el-table-column/g);
		expect(mainColumnCount).toBeLessThan(40);
		expect(mainColumnCount).toBeGreaterThan(25);
	});
});