Mendeley Import: Add more tests for the importer
Also rephrased a comment in the importer code and renamed tests file to mendeleyImportTest.js for consistency.
This commit is contained in:
parent
3b993b2af3
commit
f10649483e
4 changed files with 235 additions and 7 deletions
chrome/content/zotero/import/mendeley
test/tests
|
@ -725,7 +725,7 @@ Zotero_Import_Mendeley.prototype._getDocumentFilesAPI = async function (document
|
|||
}
|
||||
map.set(doc.id, files);
|
||||
}
|
||||
// check if enough space available totalSize
|
||||
// TODO: check if enough space available totalSize
|
||||
await caller.runAll();
|
||||
return map;
|
||||
};
|
||||
|
|
132
test/tests/data/mendeleyMock/annotations.json
Normal file
132
test/tests/data/mendeleyMock/annotations.json
Normal file
|
@ -0,0 +1,132 @@
|
|||
[
|
||||
{
|
||||
"id": "339d0202-d99f-48a2-aa0d-9b0c5631af26",
|
||||
"type": "highlight",
|
||||
"color":
|
||||
{
|
||||
"r": 255,
|
||||
"g": 181,
|
||||
"b": 182
|
||||
},
|
||||
"profile_id": "8dbf0832-8723-4c48-b532-20c0b7f6e01a",
|
||||
"positions":
|
||||
[
|
||||
{
|
||||
"top_left":
|
||||
{
|
||||
"x": 429.74257247464135,
|
||||
"y": 770.1238821199208
|
||||
},
|
||||
"bottom_right":
|
||||
{
|
||||
"x": 572.5401236420382,
|
||||
"y": 680.1292839565452
|
||||
},
|
||||
"page": 1
|
||||
}
|
||||
],
|
||||
"created": "2021-11-09T10:26:16.728Z",
|
||||
"last_modified": "2021-11-09T10:26:16.728Z",
|
||||
"privacy_level": "private",
|
||||
"filehash": "cc22c6611277df346ff8dc7386ba3880b2bafa15",
|
||||
"document_id": "c54b0c6f-c4ce-4706-8742-bc7d032df862"
|
||||
},
|
||||
{
|
||||
"id": "885615a7-170e-4613-af80-0227ea76ae55",
|
||||
"type": "highlight",
|
||||
"color":
|
||||
{
|
||||
"r": 255,
|
||||
"g": 196,
|
||||
"b": 251
|
||||
},
|
||||
"profile_id": "8dbf0832-8723-4c48-b532-20c0b7f6e01a",
|
||||
"positions":
|
||||
[
|
||||
{
|
||||
"top_left":
|
||||
{
|
||||
"x": 69.97863215,
|
||||
"y": 682.3314708379199
|
||||
},
|
||||
"bottom_right":
|
||||
{
|
||||
"x": 210.78493472000002,
|
||||
"y": 718.03235188976
|
||||
},
|
||||
"page": 1
|
||||
}
|
||||
],
|
||||
"created": "2021-11-09T10:26:16.713Z",
|
||||
"last_modified": "2021-11-09T10:26:16.713Z",
|
||||
"privacy_level": "private",
|
||||
"filehash": "cc22c6611277df346ff8dc7386ba3880b2bafa15",
|
||||
"document_id": "c54b0c6f-c4ce-4706-8742-bc7d032df862"
|
||||
},
|
||||
{
|
||||
"id": "bfbdb972-171d-4b21-8ae6-f156ac9a2b41",
|
||||
"type": "sticky_note",
|
||||
"color":
|
||||
{
|
||||
"r": 186,
|
||||
"g": 226,
|
||||
"b": 255
|
||||
},
|
||||
"profile_id": "8dbf0832-8723-4c48-b532-20c0b7f6e01a",
|
||||
"positions":
|
||||
[
|
||||
{
|
||||
"top_left":
|
||||
{
|
||||
"x": 309.44367084808835,
|
||||
"y": 662.2221955464859
|
||||
},
|
||||
"bottom_right":
|
||||
{
|
||||
"x": 309.44367084808835,
|
||||
"y": 662.2221955464859
|
||||
},
|
||||
"page": 1
|
||||
}
|
||||
],
|
||||
"text": "blue note 2\n",
|
||||
"created": "2021-11-09T10:26:16.643Z",
|
||||
"last_modified": "2021-11-09T10:26:16.643Z",
|
||||
"privacy_level": "private",
|
||||
"filehash": "cc22c6611277df346ff8dc7386ba3880b2bafa15",
|
||||
"document_id": "c54b0c6f-c4ce-4706-8742-bc7d032df862"
|
||||
},
|
||||
{
|
||||
"id": "c436932f-b14b-4580-a649-4587a5cdc2c3",
|
||||
"type": "sticky_note",
|
||||
"color":
|
||||
{
|
||||
"r": 255,
|
||||
"g": 222,
|
||||
"b": 180
|
||||
},
|
||||
"profile_id": "8dbf0832-8723-4c48-b532-20c0b7f6e01a",
|
||||
"positions":
|
||||
[
|
||||
{
|
||||
"top_left":
|
||||
{
|
||||
"x": 287.4041774203229,
|
||||
"y": 662.2221955464859
|
||||
},
|
||||
"bottom_right":
|
||||
{
|
||||
"x": 287.4041774203229,
|
||||
"y": 662.2221955464859
|
||||
},
|
||||
"page": 1
|
||||
}
|
||||
],
|
||||
"text": "orange note1",
|
||||
"created": "2021-11-09T10:26:16.640Z",
|
||||
"last_modified": "2021-11-09T10:26:16.640Z",
|
||||
"privacy_level": "private",
|
||||
"filehash": "cc22c6611277df346ff8dc7386ba3880b2bafa15",
|
||||
"document_id": "c54b0c6f-c4ce-4706-8742-bc7d032df862"
|
||||
}
|
||||
]
|
|
@ -19,6 +19,17 @@
|
|||
},
|
||||
"starred": false,
|
||||
"title": "Foo Bar",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"first_name": "Tom",
|
||||
"last_name": "Najdek"
|
||||
},
|
||||
{
|
||||
"first_name": "Lorem",
|
||||
"last_name": "Ipsum"
|
||||
}
|
||||
],
|
||||
"type": "journal",
|
||||
"folder_uuids": [
|
||||
"8d2f262d-49b3-4dfc-8968-0bb71bcd92ea"
|
||||
|
@ -39,5 +50,39 @@
|
|||
"title": "Sample Report",
|
||||
"type": "report",
|
||||
"year": 2002
|
||||
}, {
|
||||
"title": "Item with PDF",
|
||||
"type": "journal",
|
||||
"year": 2005,
|
||||
"source": "Zotero",
|
||||
"pages": "1-11",
|
||||
"websites":
|
||||
[
|
||||
"https://zotero.org"
|
||||
],
|
||||
"id": "c54b0c6f-c4ce-4706-8742-bc7d032df862",
|
||||
"created": "2021-11-09T10:26:15.201Z",
|
||||
"file_attached": true,
|
||||
"profile_id": "8dbf0832-8723-4c48-b532-20c0b7f6e01a",
|
||||
"last_modified": "2021-11-09T10:26:16.303Z",
|
||||
"read": false,
|
||||
"starred": false,
|
||||
"authored": false,
|
||||
"confirmed": true,
|
||||
"hidden": false,
|
||||
"private_publication": false,
|
||||
"abstract": "Lorem Ipsum. Nostrud elit ullamco laborum cillum.",
|
||||
"files":
|
||||
[
|
||||
{
|
||||
"id": "19fb5e5b-1a39-4851-b513-d48441a670e1",
|
||||
"document_id": "c54b0c6f-c4ce-4706-8742-bc7d032df862",
|
||||
"mime_type": "application/pdf",
|
||||
"file_name": "item.pdf",
|
||||
"size": 123456,
|
||||
"created": "2021-11-09T10:26:16.292Z",
|
||||
"filehash": "cc22c6611277df346ff8dc7386ba3880b2bafa15"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,12 +1,27 @@
|
|||
/* global setHTTPResponse:false, sinon: false, Zotero_Import_Mendeley: false */
|
||||
/* global setHTTPResponse:false, sinon: false, Zotero_Import_Mendeley: false, HttpServer: false */
|
||||
|
||||
describe('Zotero_Import_Mendeley', function () {
|
||||
var server, importer;
|
||||
var server, importer, httpd, httpdURL;
|
||||
|
||||
before(async () => {
|
||||
Components.utils.import('chrome://zotero/content/import/mendeley/mendeleyImport.js');
|
||||
importer = new Zotero_Import_Mendeley();
|
||||
importer.mendeleyCode = 'CODE';
|
||||
|
||||
// real http server is used to deliver an empty pdf so that annotations can be processed during import
|
||||
Components.utils.import("resource://zotero-unit/httpd.js");
|
||||
const port = 16213;
|
||||
httpd = new HttpServer();
|
||||
httpdURL = `http://127.0.0.1:${port}`;
|
||||
httpd.start(port);
|
||||
httpd.registerFile(
|
||||
'/file1.pdf',
|
||||
Zotero.File.pathToFile(OS.Path.join(getTestDataDirectory().path, 'empty.pdf'))
|
||||
);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await new Zotero.Promise(resolve => httpd.stop(resolve));
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
|
@ -43,7 +58,9 @@ describe('Zotero_Import_Mendeley', function () {
|
|||
url: `annotations?limit=200`,
|
||||
status: 200,
|
||||
headers: {},
|
||||
json: []
|
||||
json: JSON.parse(
|
||||
await Zotero.File.getContentsFromURLAsync('resource://zotero-unit-tests/data/mendeleyMock/annotations.json')
|
||||
)
|
||||
});
|
||||
|
||||
setHTTPResponse(server, 'https://api.mendeley.com/', {
|
||||
|
@ -73,6 +90,16 @@ describe('Zotero_Import_Mendeley', function () {
|
|||
headers: {},
|
||||
json: []
|
||||
});
|
||||
|
||||
setHTTPResponse(server, 'https://api.mendeley.com/', {
|
||||
method: 'GET',
|
||||
url: `files/19fb5e5b-1a39-4851-b513-d48441a670e1?`,
|
||||
status: 200, // ideally would be 303 but mock http doesn't like it
|
||||
headers: {
|
||||
Location: `${httpdURL}/file1.pdf`
|
||||
},
|
||||
text: ''
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -81,7 +108,6 @@ describe('Zotero_Import_Mendeley', function () {
|
|||
|
||||
describe('#import', () => {
|
||||
it("should import items & collections", async () => {
|
||||
|
||||
await importer.translate({
|
||||
libraryID: Zotero.Libraries.userLibraryID,
|
||||
collections: null,
|
||||
|
@ -98,16 +124,41 @@ describe('Zotero_Import_Mendeley', function () {
|
|||
.filter(item => item.libraryID == Zotero.Libraries.userLibraryID && !item.deleted)
|
||||
.shift();
|
||||
|
||||
const withpdf = (await Zotero.Relations
|
||||
.getByPredicateAndObject('item', 'mendeleyDB:documentUUID', 'c54b0c6f-c4ce-4706-8742-bc7d032df862'))
|
||||
.filter(item => item.libraryID == Zotero.Libraries.userLibraryID && !item.deleted)
|
||||
.shift();
|
||||
|
||||
const pdf = (await Zotero.Relations
|
||||
.getByPredicateAndObject('item', 'mendeleyDB:fileHash', 'cc22c6611277df346ff8dc7386ba3880b2bafa15'))
|
||||
.filter(item => item.libraryID == Zotero.Libraries.userLibraryID && !item.deleted)
|
||||
.shift();
|
||||
|
||||
assert.equal(journal.getField('title'), 'Foo Bar');
|
||||
assert.equal(journal.itemTypeID, Zotero.ItemTypes.getID('journalArticle'));
|
||||
assert.equal(report.getField('title'), 'Sample Report');
|
||||
assert.equal(report.itemTypeID, Zotero.ItemTypes.getID('report'));
|
||||
assert.equal(withpdf.getField('title'), 'Item with PDF');
|
||||
assert.equal(withpdf.itemTypeID, Zotero.ItemTypes.getID('journalArticle'));
|
||||
|
||||
// creators
|
||||
const creators = journal.getCreators();
|
||||
assert.lengthOf(creators, 2);
|
||||
assert.sameMembers(creators.map(c => c.firstName), ["Tom", "Lorem"]);
|
||||
assert.sameMembers(creators.map(c => c.lastName), ["Najdek", "Ipsum"]);
|
||||
|
||||
// test identifiers
|
||||
// identifiers
|
||||
assert.equal(journal.getField('DOI'), '10.1111');
|
||||
assert.include(journal.getField('extra'), 'PMID: 11111111');
|
||||
assert.include(journal.getField('extra'), 'arXiv: 1111.2222');
|
||||
|
||||
|
||||
// attachment & annotations
|
||||
assert.lengthOf(withpdf.getAttachments(), 1);
|
||||
assert.equal(pdf.parentID, withpdf.id);
|
||||
const annotations = await pdf.getAnnotations();
|
||||
assert.lengthOf(annotations, 4);
|
||||
|
||||
// collection
|
||||
const parentCollection = await Zotero.Collections.getAsync(
|
||||
journal.getCollections().pop()
|
||||
);
|
Loading…
Add table
Reference in a new issue