From 72c1df726e516941df2a672aa58d1d96a7844100 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 2 Jul 2016 13:13:30 +0200 Subject: [PATCH] Add a `getAttachments` unit-test for a PDF file that actually contains attachments --- test/unit/api_spec.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 415b527be..6205d3c14 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -497,7 +497,8 @@ describe('api', function() { done.fail(reason); }); }); - it('gets attachments', function(done) { + + it('gets non-existent attachments', function(done) { var promise = doc.getAttachments(); promise.then(function (data) { expect(data).toEqual(null); @@ -506,6 +507,25 @@ describe('api', function() { done.fail(reason); }); }); + it('gets attachments', function(done) { + var url = new URL('../pdfs/bug766138.pdf', window.location).href; + var loadingTask = PDFJS.getDocument(url); + var promise = loadingTask.promise.then(function (pdfDoc) { + return pdfDoc.getAttachments(); + }); + promise.then(function (data) { + var attachment = data['Press Quality.joboptions']; + expect(attachment.filename).toEqual('Press Quality.joboptions'); + expect(attachment.content instanceof Uint8Array).toBeTruthy(); + expect(attachment.content.length).toEqual(30098); + + loadingTask.destroy(); + done(); + }).catch(function (reason) { + done.fail(reason); + }); + }); + it('gets javascript', function(done) { var promise = doc.getJavaScript(); promise.then(function (data) {