/* @vitest-environment happy-dom */
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { createDmsFilePrintTicket, getDmsFilePageCount, renderDmsPrintPdf } from '#/api/x/dms/print';
|
import { onlineUtils } from '#/utils/jnpf';
|
|
import { buildDmsPrintableHtml, normalizeDmsPrintOptions, parseDmsPrintPages, printDmsDocument, registerDmsPrintPageVariableHandler } from '../dmsHiprint';
|
|
const pdfMocks = vi.hoisted(() => ({ getDocument: vi.fn() }));
|
|
vi.mock('#/api/request', () => ({ defHttp: { post: vi.fn() } }));
|
vi.mock('pdfjs-dist', () => ({ GlobalWorkerOptions: {}, getDocument: pdfMocks.getDocument }));
|
vi.mock('pdfjs-dist/build/pdf.worker.min.mjs?url', () => ({ default: 'pdf.worker.mjs' }));
|
vi.mock('#/api/x/dms/print', () => ({ createDmsFilePrintTicket: vi.fn(), getDmsFilePageCount: vi.fn(), renderDmsPrintPdf: vi.fn() }));
|
vi.mock('#/utils/jnpf', () => ({ onlineUtils: { hiprint: vi.fn() } }));
|
|
describe('dms Hiprint options', () => {
|
beforeEach(() => {
|
vi.mocked(getDmsFilePageCount).mockResolvedValue({ data: { fileName: 'quality.docx', fileVersionId: 'version-1', pageCount: 200 } } as any);
|
vi.mocked(onlineUtils.hiprint).mockImplementation(async (config: any) => {
|
config.onPrint?.({ mode: 'hiprint' });
|
return { mode: 'hiprint' } as any;
|
});
|
});
|
|
it('passes every barcode entry to the PRINT ticket before requesting printable PDF bytes', async () => {
|
const customBarcode = [
|
{ page: 1, barValue: 'REC-001', barText: 'First label' },
|
{ page: 1, barValue: 'SECOND-001', barText: 'Second label' },
|
{ barValue: 'GLOBAL', barText: 'Every page' },
|
];
|
vi.mocked(createDmsFilePrintTicket).mockResolvedValue({
|
data: { accessTicket: 'print-ticket', fileName: 'quality.docx', fileVersionId: 'version-1' },
|
} as any);
|
vi.mocked(renderDmsPrintPdf).mockResolvedValue(new ArrayBuffer(1) as any);
|
let confirmDone!: () => void;
|
const onPrintSuccess = vi.fn(
|
() =>
|
new Promise<void>((resolve) => {
|
confirmDone = resolve;
|
}),
|
);
|
let active = true;
|
let hiprintConfig: any;
|
vi.mocked(onlineUtils.hiprint).mockImplementation(async (config: any) => {
|
hiprintConfig = config;
|
return { mode: 'hiprint' } as any;
|
});
|
pdfMocks.getDocument.mockReturnValue({
|
promise: Promise.resolve({
|
numPages: 1,
|
destroy: vi.fn(),
|
getPage: vi.fn(async () => ({
|
cleanup: vi.fn(),
|
getViewport: () => ({ height: 842, width: 595 }),
|
render: () => ({ promise: Promise.resolve() }),
|
})),
|
}),
|
});
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
let completed = false;
|
const printing = printDmsDocument(
|
'quality.docx',
|
{
|
fileVersionId: 'version-1',
|
copies: 2,
|
onPrintSuccess,
|
pages: '1',
|
customBarcode,
|
shifouShoukong: 'no',
|
} as any,
|
() => active,
|
).finally(() => {
|
completed = true;
|
});
|
await vi.waitFor(() => expect(hiprintConfig).toBeDefined());
|
expect(completed).toBe(false);
|
expect(onPrintSuccess).not.toHaveBeenCalled();
|
active = false;
|
hiprintConfig.onPrint({ mode: 'hiprint' });
|
hiprintConfig.onPrint({ mode: 'hiprint' });
|
await vi.waitFor(() => expect(onPrintSuccess).toHaveBeenCalledTimes(1));
|
expect(completed).toBe(false);
|
confirmDone();
|
await printing;
|
expect(createDmsFilePrintTicket).toHaveBeenCalledWith(
|
expect.objectContaining({
|
resourceId: 'version-1',
|
resourceType: 'FILE_VERSION',
|
copies: 2,
|
printPages: '1',
|
customBarcode,
|
}),
|
);
|
expect(vi.mocked(createDmsFilePrintTicket).mock.calls[0]![0]).not.toHaveProperty('shifouShoukong');
|
expect(renderDmsPrintPdf).toHaveBeenCalledWith({
|
items: [{ accessTicket: 'print-ticket', fileName: 'quality.docx', fileVersionId: 'version-1', printPages: '1' }],
|
source: { accessTicket: 'print-ticket', fileName: 'quality.docx', fileVersionId: 'version-1' },
|
});
|
expect(onlineUtils.hiprint).toHaveBeenCalledWith(
|
expect.objectContaining({ clientOptions: { copies: 2, title: 'quality.docx' }, onPrint: expect.any(Function) }),
|
);
|
expect(onPrintSuccess).toHaveBeenCalledTimes(1);
|
vi.restoreAllMocks();
|
});
|
|
it('rejects the DMS print when the client reports a send failure', async () => {
|
vi.clearAllMocks();
|
vi.mocked(getDmsFilePageCount).mockResolvedValue({ data: { fileName: 'quality.docx', fileVersionId: 'version-1', pageCount: 1 } } as any);
|
vi.mocked(createDmsFilePrintTicket).mockResolvedValue({
|
data: { accessTicket: 'print-ticket', fileName: 'quality.docx', fileVersionId: 'version-1' },
|
} as any);
|
vi.mocked(renderDmsPrintPdf).mockResolvedValue(new ArrayBuffer(1) as any);
|
vi.mocked(onlineUtils.hiprint).mockImplementation(async (config: any) => {
|
config.onError?.(new Error('printer unavailable'));
|
return { mode: 'hiprint' } as any;
|
});
|
pdfMocks.getDocument.mockReturnValue({
|
promise: Promise.resolve({
|
destroy: vi.fn(),
|
getPage: vi.fn(async () => ({
|
cleanup: vi.fn(),
|
getViewport: () => ({ height: 842, width: 595 }),
|
render: () => ({ promise: Promise.resolve() }),
|
})),
|
numPages: 1,
|
}),
|
});
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
const onPrintSuccess = vi.fn();
|
|
await expect(printDmsDocument('quality.docx', { fileVersionId: 'version-1', onPrintSuccess, pages: '1' })).rejects.toThrow('printer unavailable');
|
|
expect(onPrintSuccess).not.toHaveBeenCalled();
|
expect(onlineUtils.hiprint).toHaveBeenCalledWith(expect.objectContaining({ errorMessageMode: 'none', onError: expect.any(Function) }));
|
vi.restoreAllMocks();
|
});
|
|
it('rejects the DMS print when the client does not confirm the task in time', async () => {
|
vi.useFakeTimers();
|
try {
|
vi.clearAllMocks();
|
vi.mocked(getDmsFilePageCount).mockResolvedValue({ data: { fileName: 'quality.docx', fileVersionId: 'version-1', pageCount: 1 } } as any);
|
vi.mocked(createDmsFilePrintTicket).mockResolvedValue({
|
data: { accessTicket: 'print-ticket', fileName: 'quality.docx', fileVersionId: 'version-1' },
|
} as any);
|
vi.mocked(renderDmsPrintPdf).mockResolvedValue(new ArrayBuffer(1) as any);
|
vi.mocked(onlineUtils.hiprint).mockResolvedValue({ mode: 'hiprint' } as any);
|
pdfMocks.getDocument.mockReturnValue({
|
promise: Promise.resolve({
|
destroy: vi.fn(),
|
getPage: vi.fn(async () => ({
|
cleanup: vi.fn(),
|
getViewport: () => ({ height: 842, width: 595 }),
|
render: () => ({ promise: Promise.resolve() }),
|
})),
|
numPages: 1,
|
}),
|
});
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
|
const printing = printDmsDocument('quality.docx', { fileVersionId: 'version-1', pages: '1' });
|
const rejected = expect(printing).rejects.toThrow('打印客户端确认任务超时');
|
await vi.advanceTimersByTimeAsync(0);
|
expect(onlineUtils.hiprint).toHaveBeenCalledTimes(1);
|
await vi.advanceTimersByTimeAsync(60_000);
|
|
await rejected;
|
} finally {
|
vi.useRealTimers();
|
vi.restoreAllMocks();
|
}
|
});
|
it('parses ranges, removes duplicates and preserves original page numbers', () => {
|
expect(parseDmsPrintPages('3,1-2,2', 3)).toEqual([1, 2, 3]);
|
expect(parseDmsPrintPages(undefined, 3)).toBeUndefined();
|
});
|
|
it('filters pages beyond the converted PDF', () => {
|
expect(parseDmsPrintPages('1,4,2-5', 3)).toEqual([1, 2, 3]);
|
expect(parseDmsPrintPages('4-100000', 3)).toEqual([]);
|
});
|
|
it('does not create a print task when every selected page is out of range', async () => {
|
vi.clearAllMocks();
|
vi.mocked(getDmsFilePageCount).mockResolvedValue({ data: { fileName: 'quality.docx', fileVersionId: 'version-1', pageCount: 3 } } as any);
|
|
await expect(printDmsDocument('quality.docx', { fileVersionId: 'version-1', pages: '4-5' })).resolves.toBeUndefined();
|
|
expect(createDmsFilePrintTicket).not.toHaveBeenCalled();
|
expect(renderDmsPrintPdf).not.toHaveBeenCalled();
|
expect(onlineUtils.hiprint).not.toHaveBeenCalled();
|
});
|
|
it('normalizes defaults and validates page-variable selection', () => {
|
expect(normalizeDmsPrintOptions()).toEqual({ copies: 1, copyBarcodes: undefined, pageVariables: [], pages: undefined });
|
expect(() => normalizeDmsPrintOptions({ pages: '1-2', pageVariables: [{ pageNo: 3, variables: { code: 'A' } }] })).toThrow('页面变量引用了未选择的打印页');
|
});
|
|
it('uses each copy barcode set as authoritative without duplicating preview barcodes', async () => {
|
vi.clearAllMocks();
|
vi.mocked(createDmsFilePrintTicket)
|
.mockResolvedValueOnce({ data: { accessTicket: 'ticket-1', fileName: 'quality.docx', fileVersionId: 'version-1' } } as any)
|
.mockResolvedValueOnce({ data: { accessTicket: 'ticket-2', fileName: 'quality.docx', fileVersionId: 'version-1' } } as any);
|
vi.mocked(renderDmsPrintPdf).mockResolvedValue(new ArrayBuffer(1) as any);
|
const getPage = vi.fn(async (_pageNo: number) => ({
|
cleanup: vi.fn(),
|
getViewport: () => ({ height: 842, width: 595 }),
|
render: () => ({ promise: Promise.resolve() }),
|
}));
|
pdfMocks.getDocument.mockReturnValue({ promise: Promise.resolve({ destroy: vi.fn(), getPage, numPages: 2 }) });
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
|
await printDmsDocument('quality.docx', {
|
copies: 2,
|
copyBarcodes: [
|
{ copyNo: 1, customBarcode: [{ page: 2, barText: 'Copy 1 Page 2', barValue: 'C1-P2' }] },
|
{ copyNo: 2, customBarcode: [{ page: 2, barText: 'Copy 2 Page 2', barValue: 'C2-P2' }] },
|
],
|
customBarcode: [{ barText: 'Common', barValue: 'COMMON' }],
|
fileVersionId: 'version-1',
|
pages: '2',
|
});
|
|
expect(createDmsFilePrintTicket).toHaveBeenNthCalledWith(
|
1,
|
expect.objectContaining({
|
copies: 1,
|
customBarcode: [{ page: 2, barText: 'Copy 1 Page 2', barValue: 'C1-P2' }],
|
printPages: '2',
|
}),
|
);
|
expect(createDmsFilePrintTicket).toHaveBeenNthCalledWith(
|
2,
|
expect.objectContaining({
|
copies: 1,
|
customBarcode: [{ page: 2, barText: 'Copy 2 Page 2', barValue: 'C2-P2' }],
|
printPages: '2',
|
}),
|
);
|
expect(renderDmsPrintPdf).toHaveBeenCalledWith({
|
items: [
|
{ accessTicket: 'ticket-1', fileName: 'quality.docx', fileVersionId: 'version-1', printPages: '2' },
|
{ accessTicket: 'ticket-2', fileName: 'quality.docx', fileVersionId: 'version-1', printPages: '2' },
|
],
|
source: { accessTicket: 'ticket-1', fileName: 'quality.docx', fileVersionId: 'version-1' },
|
});
|
expect(getPage.mock.calls.map(([pageNo]) => pageNo)).toEqual([1, 2]);
|
expect(onlineUtils.hiprint).toHaveBeenCalledWith(expect.objectContaining({ clientOptions: { copies: 1, title: 'quality.docx' } }));
|
vi.restoreAllMocks();
|
});
|
|
it('splits copy-specific printing by both copy and physical-page limits', async () => {
|
vi.clearAllMocks();
|
let ticketNo = 0;
|
vi.mocked(createDmsFilePrintTicket).mockImplementation(async () => {
|
ticketNo++;
|
return { data: { accessTicket: `ticket-${ticketNo}`, fileName: 'quality.docx', fileVersionId: 'version-1' } } as any;
|
});
|
vi.mocked(renderDmsPrintPdf).mockResolvedValue(new ArrayBuffer(1) as any);
|
vi.mocked(onlineUtils.hiprint).mockImplementation(async (config: any) => {
|
config.onPrint?.({ mode: 'hiprint' });
|
return { mode: 'hiprint' } as any;
|
});
|
const getPage = vi.fn(async (_pageNo: number) => ({
|
cleanup: vi.fn(),
|
getViewport: () => ({ height: 842, width: 595 }),
|
render: () => ({ promise: Promise.resolve() }),
|
}));
|
for (const numPages of [96, 96, 12]) {
|
pdfMocks.getDocument.mockReturnValueOnce({ promise: Promise.resolve({ destroy: vi.fn(), getPage, numPages }) });
|
}
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
const onPrintSuccess = vi.fn();
|
const copyBarcodes = Array.from({ length: 34 }, (_, index) => ({
|
copyNo: index + 1,
|
customBarcode: [{ page: 1, barText: `Copy ${index + 1}`, barValue: `COPY-${index + 1}` }],
|
}));
|
|
await printDmsDocument('quality.docx', {
|
copies: 34,
|
copyBarcodes,
|
fileVersionId: 'version-1',
|
onPrintSuccess,
|
pages: '1-6',
|
});
|
|
expect(vi.mocked(renderDmsPrintPdf).mock.calls.map(([request]) => (request as any).items.length)).toEqual([16, 16, 2]);
|
expect(vi.mocked(renderDmsPrintPdf).mock.calls.map(([request]) => (request as any).source.accessTicket)).toEqual(['ticket-1', 'ticket-1', 'ticket-1']);
|
expect(vi.mocked(onlineUtils.hiprint).mock.calls.map(([config]) => config.clientOptions?.title)).toEqual([
|
'quality.docx (第 1 批)',
|
'quality.docx (第 2 批)',
|
'quality.docx (第 3 批)',
|
]);
|
expect(onPrintSuccess).toHaveBeenCalledTimes(1);
|
vi.restoreAllMocks();
|
});
|
|
it('splits more than 100 selected pages per copy without changing the copy ticket', async () => {
|
vi.clearAllMocks();
|
vi.mocked(getDmsFilePageCount).mockResolvedValue({ data: { fileName: 'quality.docx', fileVersionId: 'version-1', pageCount: 205 } } as any);
|
vi.mocked(createDmsFilePrintTicket)
|
.mockResolvedValueOnce({ data: { accessTicket: 'ticket-1', fileName: 'quality.docx', fileVersionId: 'version-1' } } as any)
|
.mockResolvedValueOnce({ data: { accessTicket: 'ticket-2', fileName: 'quality.docx', fileVersionId: 'version-1' } } as any);
|
vi.mocked(renderDmsPrintPdf).mockResolvedValue(new ArrayBuffer(1) as any);
|
for (const numPages of [100, 100, 5, 100, 100, 5]) {
|
pdfMocks.getDocument.mockReturnValueOnce({
|
promise: Promise.resolve({
|
destroy: vi.fn(),
|
getPage: vi.fn(async () => ({ cleanup: vi.fn(), getViewport: () => ({ height: 842, width: 595 }), render: () => ({ promise: Promise.resolve() }) })),
|
numPages,
|
}),
|
});
|
}
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
|
await printDmsDocument('quality.docx', {
|
copies: 2,
|
copyBarcodes: [
|
{ copyNo: 1, customBarcode: [{ page: 1, barText: 'Copy 1', barValue: 'COPY-1' }] },
|
{ copyNo: 2, customBarcode: [{ page: 1, barText: 'Copy 2', barValue: 'COPY-2' }] },
|
],
|
fileVersionId: 'version-1',
|
pages: '1-205',
|
});
|
|
expect(vi.mocked(renderDmsPrintPdf).mock.calls.map(([request]) => (request as any).items[0])).toEqual([
|
expect.objectContaining({ accessTicket: 'ticket-1', printPages: '1-100' }),
|
expect.objectContaining({ accessTicket: 'ticket-1', printPages: '101-200' }),
|
expect.objectContaining({ accessTicket: 'ticket-1', printPages: '201-205' }),
|
expect.objectContaining({ accessTicket: 'ticket-2', printPages: '1-100' }),
|
expect.objectContaining({ accessTicket: 'ticket-2', printPages: '101-200' }),
|
expect.objectContaining({ accessTicket: 'ticket-2', printPages: '201-205' }),
|
]);
|
vi.restoreAllMocks();
|
});
|
|
it('halves an oversized PDF batch and prints the smaller batches in order', async () => {
|
vi.clearAllMocks();
|
vi.mocked(getDmsFilePageCount).mockResolvedValue({ data: { fileName: 'quality.docx', fileVersionId: 'version-1', pageCount: 2 } } as any);
|
vi.mocked(createDmsFilePrintTicket)
|
.mockResolvedValueOnce({ data: { accessTicket: 'ticket-1', fileName: 'quality.docx', fileVersionId: 'version-1' } } as any)
|
.mockResolvedValueOnce({ data: { accessTicket: 'ticket-2', fileName: 'quality.docx', fileVersionId: 'version-1' } } as any);
|
vi.mocked(renderDmsPrintPdf)
|
.mockRejectedValueOnce(new Error('单批打印 PDF 超过系统大小限制'))
|
.mockResolvedValue(new ArrayBuffer(1) as any);
|
for (let index = 0; index < 2; index++) {
|
pdfMocks.getDocument.mockReturnValueOnce({
|
promise: Promise.resolve({
|
destroy: vi.fn(),
|
getPage: vi.fn(async () => ({ cleanup: vi.fn(), getViewport: () => ({ height: 842, width: 595 }), render: () => ({ promise: Promise.resolve() }) })),
|
numPages: 2,
|
}),
|
});
|
}
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
|
await printDmsDocument('quality.docx', {
|
copies: 2,
|
copyBarcodes: [
|
{ copyNo: 1, customBarcode: [{ page: 1, barText: 'Copy 1', barValue: 'COPY-1' }] },
|
{ copyNo: 2, customBarcode: [{ page: 1, barText: 'Copy 2', barValue: 'COPY-2' }] },
|
],
|
fileVersionId: 'version-1',
|
pages: '1-2',
|
});
|
|
expect(vi.mocked(renderDmsPrintPdf).mock.calls.map(([request]) => (request as any).items.length)).toEqual([2, 1, 1]);
|
expect(onlineUtils.hiprint).toHaveBeenCalledTimes(2);
|
vi.restoreAllMocks();
|
});
|
|
it('rejects non-contiguous copy numbers and conflicting copy counts', () => {
|
const copyBarcodes = [{ copyNo: 2, customBarcode: [{ page: 1, barText: 'Copy 2', barValue: 'C2' }] }];
|
expect(() => normalizeDmsPrintOptions({ copyBarcodes })).toThrow('打印份序必须从 1 开始连续且不可重复');
|
expect(() => normalizeDmsPrintOptions({ copies: 2, copyBarcodes: [{ ...copyBarcodes[0]!, copyNo: 1 }] })).toThrow('打印份数必须与逐份条码配置数量一致');
|
});
|
|
it('rejects duplicate page variables and nested objects', () => {
|
expect(() =>
|
normalizeDmsPrintOptions({
|
pageVariables: [
|
{ pageNo: 1, variables: { code: 'A' } },
|
{ pageNo: 1, variables: { code: 'B' } },
|
],
|
}),
|
).toThrow('页面打印参数无效');
|
expect(() => normalizeDmsPrintOptions({ pageVariables: [{ pageNo: 1, variables: { unsafe: { nested: true } } }] })).toThrow('页面打印参数无效');
|
});
|
|
it('matches page variables by original page number after filtering', async () => {
|
const destroy = vi.fn();
|
const getPage = vi.fn(async (_pageNo: number) => ({
|
cleanup: vi.fn(),
|
getViewport: () => ({ height: 1684, width: 1190 }),
|
render: () => ({ promise: Promise.resolve() }),
|
}));
|
pdfMocks.getDocument.mockReturnValue({ promise: Promise.resolve({ destroy, getPage, numPages: 3 }) });
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
const handler = vi.fn();
|
const unregister = registerDmsPrintPageVariableHandler(handler);
|
|
const html = await buildDmsPrintableHtml(new ArrayBuffer(1), {
|
pages: '3',
|
pageVariables: [{ pageNo: 3, variables: { code: 'PAGE-3' } }],
|
});
|
|
expect(getPage).toHaveBeenCalledWith(3);
|
expect(handler).toHaveBeenCalledWith(expect.objectContaining({ pageNo: 3, variables: { code: 'PAGE-3' } }));
|
expect(html).toContain('data:image/png;base64,page');
|
expect(destroy).toHaveBeenCalled();
|
unregister();
|
vi.restoreAllMocks();
|
});
|
|
it('ignores page variables belonging to filtered out-of-range pages', async () => {
|
const getPage = vi.fn(async (_pageNo: number) => ({
|
cleanup: vi.fn(),
|
getViewport: () => ({ height: 1684, width: 1190 }),
|
render: () => ({ promise: Promise.resolve() }),
|
}));
|
pdfMocks.getDocument.mockReturnValue({ promise: Promise.resolve({ destroy: vi.fn(), getPage, numPages: 2 }) });
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({} as CanvasRenderingContext2D);
|
vi.spyOn(HTMLCanvasElement.prototype, 'toDataURL').mockReturnValue('data:image/png;base64,page');
|
const handler = vi.fn();
|
const unregister = registerDmsPrintPageVariableHandler(handler);
|
|
await buildDmsPrintableHtml(new ArrayBuffer(1), {
|
pages: '1,3',
|
pageVariables: [
|
{ pageNo: 1, variables: { code: 'PAGE-1' } },
|
{ pageNo: 3, variables: { code: 'PAGE-3' } },
|
],
|
});
|
|
expect(getPage).toHaveBeenCalledTimes(1);
|
expect(getPage).toHaveBeenCalledWith(1);
|
expect(handler).toHaveBeenCalledWith(expect.objectContaining({ pageNo: 1, variables: { code: 'PAGE-1' } }));
|
expect(handler).not.toHaveBeenCalledWith(expect.objectContaining({ pageNo: 3 }));
|
unregister();
|
vi.restoreAllMocks();
|
});
|
});
|