fix(intake): enable Gujia 2026 certificate template

This commit is contained in:
WuYongJie 2026-10-09 10:03:34 +08:00
parent afe9b806d5
commit ee95abd0b0
5 changed files with 37 additions and 16 deletions

View File

@ -1,12 +1,13 @@
import { fireEvent, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { BarcodePrintTemplateDialog } from './BarcodePrintTemplateDialog'
import { CERTIFICATE_PRINT_TEMPLATE_OPTIONS } from './barcodePrintCertificate'
describe('BarcodePrintTemplateDialog', () => {
it('marks a disabled certificate unavailable, skips a stale default and prevents submission', async () => {
const actor = userEvent.setup()
const onSubmit = jest.fn()
const disabledTitle = '顾家合格证卡片2026新版(11cm*13cm)'
const disabledTitle = '测试停用模板'
const legacyTitle = '顾家合格证卡片(11cm*13cm)'
render(
<BarcodePrintTemplateDialog
@ -30,6 +31,30 @@ describe('BarcodePrintTemplateDialog', () => {
expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ templateTitle: legacyTitle }))
})
it('selects and submits the available 2026 Gujia certificate from the actual template options', async () => {
const actor = userEvent.setup()
const onSubmit = jest.fn()
const title = '顾家合格证卡片2026新版(11cm*13cm)'
render(
<BarcodePrintTemplateDialog
isOpen mode="certificate"
templates={CERTIFICATE_PRINT_TEMPLATE_OPTIONS}
defaultTemplateTitle={title}
rowSummary="顾家合格证"
onClose={jest.fn()} onSubmit={onSubmit}
/>,
)
const select = screen.getByLabelText('打印模板')
expect(screen.getByRole('option', { name: title })).toBeEnabled()
expect(select).toHaveValue(title)
expect(screen.queryByRole('option', { name: `${title}(暂时不可用)` })).not.toBeInTheDocument()
await actor.selectOptions(select, '顾家合格证卡片(11cm*13cm)')
await actor.selectOptions(select, title)
await actor.click(screen.getByRole('button', { name: '确定' }))
expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ templateTitle: title }))
})
it('submits the selected barcode template', async () => {
const actor = userEvent.setup()
const onSubmit = jest.fn()

View File

@ -1,10 +1,7 @@
import {
__barcodePrintCertificateTestUtils,
CERTIFICATE_PRINT_TEMPLATE_OPTIONS,
createCertificatePrintPreview,
printCertificatePreview,
} from "./barcodePrintCertificate";
import type { BarcodePrintRow } from "./barcodePrintRows";
import { applyGujiaCertificate2026Content } from "./barcodePrintGujiaCertificate2026";
import { SOFIA_CARTON_BARCODE_QR_LAYOUT } from "./barcodePrintSofiaCartonLayout";
import {
@ -13,7 +10,7 @@ import {
} from "./barcodePrintSofiaCertificateLayout";
describe("Gujia certificate availability and calibration", () => {
const disabledTitle = "顾家合格证卡片2026新版(11cm*13cm)";
const newCardTitle = "顾家合格证卡片2026新版(11cm*13cm)";
const record = {
barcode: "GBGJ-TEST", productCategory: "电脑桌", color: "经典北美黑胡桃色+黑架",
procode: "DS5147BG", brandProcode: "DS5147BG-C4", size: "120*60*75",
@ -21,13 +18,13 @@ describe("Gujia certificate availability and calibration", () => {
qualifiedCertMainMaterial: "", executionStandard: "T/CZFA 0002-2025",
};
it("disables only the new card and rejects generation and previously generated previews", async () => {
expect(CERTIFICATE_PRINT_TEMPLATE_OPTIONS.filter((option) => option.disabled).map((option) => option.title))
.toEqual([disabledTitle]);
await expect(createCertificatePrintPreview({} as BarcodePrintRow, disabledTitle))
.rejects.toThrow("暂时不可用");
await expect(printCertificatePreview({ title: disabledTitle, pageSize: "110mm 130mm", imageDataUrl: "data:image/png;base64,old" }))
.rejects.toThrow("暂时不可用");
it("offers both Gujia cards as available certificate templates", () => {
const newCard = CERTIFICATE_PRINT_TEMPLATE_OPTIONS.find((option) => option.title === newCardTitle);
const legacyCard = CERTIFICATE_PRINT_TEMPLATE_OPTIONS.find((option) => option.title === "顾家合格证卡片(11cm*13cm)");
expect(newCard).toBeDefined();
expect(legacyCard).toBeDefined();
expect(newCard?.disabled).toBeFalsy();
expect(legacyCard?.disabled).toBeFalsy();
});
it("applies one calibrated offset to the legacy card while retaining all original printed values", () => {
@ -41,7 +38,7 @@ describe("Gujia certificate availability and calibration", () => {
expect(values.every((value) => value.style.left === "474px" && value.style.fontSize === "42px")).toBe(true);
});
it("retains the disabled new card content and coordinates for future use", () => {
it("retains the new card content and coordinates", () => {
const base = __barcodePrintCertificateTestUtils.renderGujiaCertificate(record, "", {}, "background", -72);
const card = applyGujiaCertificate2026Content(base, record.executionStandard);
const values = Array.from(card.querySelectorAll<HTMLElement>(".item"));

View File

@ -750,7 +750,6 @@ const CERTIFICATE_TEMPLATES: CertificateTemplate[] = [
},
{
title: GUJIA_CERTIFICATE_2026_TITLE,
disabled: true,
pageSize: "110mm 130mm",
background: "hgz_gj.jpg",
render: (record, qrCodeBase64, options, backgroundDataUrl) =>

View File

@ -20,7 +20,7 @@ describe("Gujia certificate layout", () => {
}
});
it("preserves the disabled 2026 template coordinates", () => {
it("preserves the 2026 template coordinates", () => {
expect(GUJIA_FIELD_PRINT_VERTICAL_OFFSET).toBe(-72);
expect(getGujiaCertificateFieldStyle(0).top).toBe("436px");
expect(getGujiaCertificateFieldStyle(1).top).toBe("554.5px");

View File

@ -4,7 +4,7 @@ export const GUJIA_CERTIFICATE_CANVAS = {
} as const;
const GUJIA_FIELD_LEFT = 474;
// 保留已停用2026新版的现有坐标,旧版校准单独传入下方偏移量。
// 2026新版使用现有坐标,旧版校准单独传入下方偏移量。
export const GUJIA_FIELD_PRINT_VERTICAL_OFFSET = -72;
// 最新实物与正确样张按红线行距对比,在已上线-20px基础上再整体上移20px。
// 累计偏移-40px,待同一打印机试打确认;这不是物理毫米换算。