Add pdf-reader annotation creation test
(cherry picked from commit af436d34a8
)
This commit is contained in:
parent
8db82c1022
commit
3a26f6eb6f
2 changed files with 71 additions and 0 deletions
|
@ -1684,6 +1684,7 @@ class Reader {
|
||||||
if (!openInBackground) {
|
if (!openInBackground) {
|
||||||
reader._window.focus();
|
reader._window.focus();
|
||||||
}
|
}
|
||||||
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
70
test/tests/pdfReaderTest.js
Normal file
70
test/tests/pdfReaderTest.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("PDF Reader", function () {
|
||||||
|
var win, zp;
|
||||||
|
|
||||||
|
before(function* () {
|
||||||
|
win = yield loadZoteroPane();
|
||||||
|
zp = win.ZoteroPane;
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function () {
|
||||||
|
win.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Reader', function () {
|
||||||
|
it('should create annotations', async function () {
|
||||||
|
var attachment = await importFileAttachment('test.pdf');
|
||||||
|
var reader = await Zotero.Reader.open(attachment.itemID);
|
||||||
|
// TODO: Implement a promise that would be resolved when pdf-reader is completely loaded
|
||||||
|
var n = 0;
|
||||||
|
while (!reader._iframeWindow.wrappedJSObject.PDFViewerApplication.pdfDocument && n++ < 50) {
|
||||||
|
await Zotero.Promise.delay(100);
|
||||||
|
}
|
||||||
|
await reader._iframeWindow.wrappedJSObject.viewerInstance._viewer._pdfjsPromise;
|
||||||
|
await reader._iframeWindow.wrappedJSObject.viewerInstance._viewer._annotationsStore.addAnnotation(
|
||||||
|
Components.utils.cloneInto({
|
||||||
|
type: 'highlight',
|
||||||
|
color: '#ffd400',
|
||||||
|
sortIndex: '00000|003305|00000',
|
||||||
|
position: {
|
||||||
|
pageIndex: 0,
|
||||||
|
rects: [[0, 0, 100, 100]]
|
||||||
|
},
|
||||||
|
text: 'test'
|
||||||
|
}, reader._iframeWindow)
|
||||||
|
);
|
||||||
|
await reader._iframeWindow.wrappedJSObject.viewerInstance._viewer._annotationsStore.addAnnotation(
|
||||||
|
Components.utils.cloneInto({
|
||||||
|
type: 'note',
|
||||||
|
color: '#ffd400',
|
||||||
|
sortIndex: '00000|003305|00000',
|
||||||
|
comment: 'test',
|
||||||
|
position: {
|
||||||
|
pageIndex: 0,
|
||||||
|
rects: [[0, 0, 100, 100]]
|
||||||
|
},
|
||||||
|
text: 'test'
|
||||||
|
}, reader._iframeWindow)
|
||||||
|
);
|
||||||
|
await reader._iframeWindow.wrappedJSObject.viewerInstance._viewer._annotationsStore.addAnnotation(
|
||||||
|
Components.utils.cloneInto({
|
||||||
|
type: 'image',
|
||||||
|
color: '#ffd400',
|
||||||
|
sortIndex: '00000|003305|00000',
|
||||||
|
comment: 'test',
|
||||||
|
position: {
|
||||||
|
pageIndex: 0,
|
||||||
|
rects: [[0, 0, 100, 100]]
|
||||||
|
}
|
||||||
|
}, reader._iframeWindow)
|
||||||
|
);
|
||||||
|
// TODO: Try to avoid pdf-reader annotation saving debounce which is now 1000ms
|
||||||
|
await Zotero.Promise.delay(1500);
|
||||||
|
var annotations = attachment.getAnnotations();
|
||||||
|
assert.equal(annotations.length, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Add annotation update and deletion tests
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue