Merge pull request #16835 from Snuffleupagus/improve-Annotation-compression-test

Improve the "write a new annotation, save the pdf and check that the text content is correct" unit-test (PR 16559 follow-up)
This commit is contained in:
Jonas Jenwald 2023-08-15 16:44:18 +02:00 committed by GitHub
commit c72cb5436d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2203,8 +2203,14 @@ describe("api", function () {
We have learned that we should more explicitly set out our aspirations for the human experience of the internet. We have learned that we should more explicitly set out our aspirations for the human experience of the internet.
We do so now. We do so now.
`.repeat(100); `.repeat(100);
expect(manifesto.length).toEqual(80500);
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf")); let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
let pdfDoc = await loadingTask.promise; let pdfDoc = await loadingTask.promise;
// The initial document size (indirectly) affects the length check below.
let typedArray = await pdfDoc.getData();
expect(typedArray.length).toBeLessThan(5000);
pdfDoc.annotationStorage.setValue("pdfjs_internal_editor_0", { pdfDoc.annotationStorage.setValue("pdfjs_internal_editor_0", {
annotationType: AnnotationEditorType.FREETEXT, annotationType: AnnotationEditorType.FREETEXT,
rect: [10, 10, 500, 500], rect: [10, 10, 500, 500],
@ -2214,12 +2220,15 @@ describe("api", function () {
value: manifesto, value: manifesto,
pageIndex: 0, pageIndex: 0,
}); });
const data = await pdfDoc.saveDocument(); const data = await pdfDoc.saveDocument();
await loadingTask.destroy(); await loadingTask.destroy();
loadingTask = getDocument(data); loadingTask = getDocument(data);
pdfDoc = await loadingTask.promise; pdfDoc = await loadingTask.promise;
// Ensure that the Annotation text-content was actually compressed.
typedArray = await pdfDoc.getData();
expect(typedArray.length).toBeLessThan(90000);
const page = await pdfDoc.getPage(1); const page = await pdfDoc.getPage(1);
const annotations = await page.getAnnotations(); const annotations = await page.getAnnotations();