2022-10-10 13:51:07 +00:00
|
|
|
"use strict";
|
|
|
|
|
2023-08-07 20:27:12 +00:00
|
|
|
describe.skip("PDF Reader", function () {
|
2022-10-10 13:51:07 +00:00
|
|
|
var win, zp;
|
|
|
|
|
|
|
|
before(function* () {
|
|
|
|
win = yield loadZoteroPane();
|
|
|
|
zp = win.ZoteroPane;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
win.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Reader', function () {
|
2022-10-11 15:06:10 +00:00
|
|
|
it('should create/update annotations', async function () {
|
2022-10-10 13:51:07 +00:00
|
|
|
var attachment = await importFileAttachment('test.pdf');
|
2022-10-11 15:06:10 +00:00
|
|
|
|
|
|
|
// Existing highlight annotation
|
|
|
|
await Zotero.Annotations.saveFromJSON(attachment, {
|
|
|
|
key: 'AAAAAAAA',
|
|
|
|
type: 'highlight',
|
|
|
|
color: '#ffd400',
|
|
|
|
sortIndex: '00000|003305|00000',
|
|
|
|
position: {
|
|
|
|
pageIndex: 0,
|
|
|
|
rects: [[0, 0, 100, 100]]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Existing note annotation
|
|
|
|
await Zotero.Annotations.saveFromJSON(attachment, {
|
|
|
|
key: 'BBBBBBBB',
|
|
|
|
type: 'note',
|
|
|
|
color: '#ffd400',
|
|
|
|
sortIndex: '00000|003305|00000',
|
|
|
|
position: {
|
|
|
|
pageIndex: 0,
|
|
|
|
rects: [[0, 0, 100, 100]]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Existing image annotation
|
|
|
|
await Zotero.Annotations.saveFromJSON(attachment, {
|
|
|
|
key: 'CCCCCCCC',
|
|
|
|
type: 'image',
|
|
|
|
color: '#ffd400',
|
|
|
|
sortIndex: '00000|003305|00000',
|
|
|
|
comment: 'asdf',
|
|
|
|
position: {
|
|
|
|
pageIndex: 0,
|
|
|
|
rects: [[0, 0, 100, 100]]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Existing ink annotation
|
|
|
|
await Zotero.Annotations.saveFromJSON(attachment, {
|
|
|
|
key: 'DDDDDDDD',
|
|
|
|
type: 'ink',
|
|
|
|
color: '#ffd400',
|
|
|
|
sortIndex: '00000|003305|00000',
|
|
|
|
position: {
|
|
|
|
pageIndex: 0,
|
|
|
|
paths: [[517.759, 760.229]],
|
|
|
|
width: 2,
|
|
|
|
unknownField: 'test'
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-10-10 13:51:07 +00:00
|
|
|
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;
|
2022-10-10 14:06:00 +00:00
|
|
|
while ((!reader._iframeWindow || !reader._iframeWindow.wrappedJSObject.PDFViewerApplication.pdfDocument) && n++ < 50) {
|
2022-10-10 13:51:07 +00:00
|
|
|
await Zotero.Promise.delay(100);
|
|
|
|
}
|
|
|
|
await reader._iframeWindow.wrappedJSObject.viewerInstance._viewer._pdfjsPromise;
|
2022-10-11 15:06:10 +00:00
|
|
|
|
|
|
|
// Create highlight annotation
|
2022-10-10 13:51:07 +00:00
|
|
|
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)
|
|
|
|
);
|
2022-10-11 15:06:10 +00:00
|
|
|
|
|
|
|
// Create note annotation
|
2022-10-10 13:51:07 +00:00
|
|
|
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)
|
|
|
|
);
|
2022-10-11 15:06:10 +00:00
|
|
|
|
|
|
|
// Create image annotation
|
2022-10-10 13:51:07 +00:00
|
|
|
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)
|
|
|
|
);
|
2022-10-11 15:06:10 +00:00
|
|
|
|
|
|
|
// Update 4 items
|
|
|
|
await reader._iframeWindow.wrappedJSObject.viewerInstance._viewer._annotationsStore.updateAnnotations(
|
|
|
|
Components.utils.cloneInto([
|
|
|
|
{
|
|
|
|
id: 'AAAAAAAA',
|
|
|
|
text: 'test'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'BBBBBBBB',
|
|
|
|
color: '#aabbcc'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'CCCCCCCC',
|
|
|
|
comment: 'test'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'DDDDDDDD',
|
|
|
|
position: { pageIndex: 2 }
|
|
|
|
},
|
|
|
|
], reader._iframeWindow)
|
|
|
|
);
|
|
|
|
|
2022-10-10 13:51:07 +00:00
|
|
|
// TODO: Try to avoid pdf-reader annotation saving debounce which is now 1000ms
|
|
|
|
await Zotero.Promise.delay(1500);
|
|
|
|
var annotations = attachment.getAnnotations();
|
|
|
|
|
2022-10-11 15:06:10 +00:00
|
|
|
// 4 existing + 3 created
|
|
|
|
assert.equal(annotations.length, 7);
|
|
|
|
|
|
|
|
// Test 4 updated annotations
|
|
|
|
assert.equal(annotations.find(x => x.key === 'AAAAAAAA').annotationText, 'test');
|
|
|
|
assert.equal(annotations.find(x => x.key === 'BBBBBBBB').annotationColor, '#aabbcc');
|
|
|
|
assert.equal(annotations.find(x => x.key === 'CCCCCCCC').annotationComment, 'test');
|
|
|
|
// Test updated position pageIndex, and make sure unknownField is preserved
|
|
|
|
assert.equal(JSON.parse(annotations.find(x => x.key === 'DDDDDDDD').annotationPosition).pageIndex, 2);
|
|
|
|
assert.equal(JSON.parse(annotations.find(x => x.key === 'DDDDDDDD').annotationPosition).unknownField, 'test');
|
|
|
|
reader.close();
|
|
|
|
});
|
2022-10-10 13:51:07 +00:00
|
|
|
});
|
|
|
|
});
|