productId.integration.spec.js 2.25 KB
const fs = require("fs");
const path = require("path");

const SOURCE_ROOT = path.resolve(__dirname, "../../../../src");

function readSource(file) {
	return fs.readFileSync(path.resolve(SOURCE_ROOT, file), "utf8");
}

describe("purchase and transfer approval product ID coverage", () => {
	it.each([
		"views/purchase/procurementReview.vue",
		"views/purchase/managerReview.vue",
		"views/purchase/directorReview.vue",
		"views/purchase/procurementBusiness.vue",
		"views/stockManage/transferOperationsReview/index.vue",
		"views/stockManage/transferCommercialReview/index.vue",
	])("adds the product ID filter to %s", (file) => {
		const source = readSource(file);

		expect(source).toContain("commodityCode: \"");
		expect(source).toContain("createProductIdFilter()");
	});

	it.each([
		"views/purchase/components/orderDetailDialog.vue",
		"views/purchase/components/CheckDialog.vue",
		"views/purchase/components/rejectDialog.vue",
		"views/purchase/singleReview.vue",
		"views/purchase/singleBusinessReview.vue",
		"views/stockManage/components/transferDetailDialog.vue",
		"views/stockManage/transferOperationsReview/handleReview.vue",
		"views/stockManage/transferOperationsReview/handleReject.vue",
	])("adds the product ID column to %s", (file) => {
		const source = readSource(file);
		const tableConfig = source.slice(source.indexOf("tableColumns:"));
		const productNameIndex = Math.max(
			tableConfig.indexOf("label: \"产品名称\""),
			tableConfig.indexOf("label: '产品名称'"),
		);
		const productIdIndex = tableConfig.indexOf("createProductIdColumn()");

		expect(productNameIndex).toBeGreaterThanOrEqual(0);
		expect(productIdIndex).toBeGreaterThan(productNameIndex);
	});

	it.each([
		"views/stockManage/transferOperationsReview/index.vue",
		"views/stockManage/transferCommercialReview/index.vue",
	])("keeps product ID in the reset model for %s", (file) => {
		const source = readSource(file);

		expect(source.match(/commodityCode: ""/g)).toHaveLength(2);
	});

	it("keeps the film-roll column anchored before the car column", () => {
		const detailSource = readSource("views/purchase/components/orderDetailDialog.vue");

		expect(detailSource).toContain("item => item.prop === \"carName\"");
		expect(detailSource).not.toContain("tableColumns.splice(5, 0");
	});
});