www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

recognizePDFTest.js (7413B)


      1 describe("PDF Recognition", function() {
      2 	var win;
      3 	
      4 	before(function* () {
      5 		if (Zotero.automatedTest) this.skip(); // TODO: Mock services
      6 		
      7 		this.timeout(60000);
      8 		// Load Zotero pane and install PDF tools
      9 		yield Zotero.Promise.all([
     10 			loadZoteroPane().then(w => win = w)
     11 		]);
     12 	});
     13 	
     14 	beforeEach(function* () {
     15 		yield selectLibrary(win);
     16 	});
     17 	
     18 	afterEach(function() {
     19 		for(let win of getWindows("chrome://zotero/content/recognizePDFDialog.xul")) {
     20 			win.close();
     21 		}
     22 		Zotero.RecognizePDF.cancel();
     23 	});
     24 	
     25 	after(function() {
     26 		if (win) {
     27 			win.close();
     28 		}
     29 	});
     30 	
     31 	it("should recognize a PDF by DOI", async function () {
     32 		this.timeout(30000);
     33 		// Import the PDF
     34 		var testdir = getTestDataDirectory();
     35 		testdir.append("recognizePDF_test_DOI.pdf");
     36 		var collection = await createDataObject('collection');
     37 		var attachment = await Zotero.Attachments.importFromFile({
     38 			file: testdir,
     39 			collections: [collection.id]
     40 		});
     41 		
     42 		win.ZoteroPane.recognizeSelected();
     43 		
     44 		var addedIDs = await waitForItemEvent("add");
     45 		var modifiedIDs = await waitForItemEvent("modify");
     46 		assert.lengthOf(addedIDs, 1);
     47 		var item = Zotero.Items.get(addedIDs[0]);
     48 		assert.equal(item.getField("title"), "Shaping the Research Agenda");
     49 		assert.equal(item.getField("libraryCatalog"), "Crossref");
     50 		assert.lengthOf(modifiedIDs, 2);
     51 		
     52 		// Wait for status to show as complete
     53 		var progressWindow = getWindows("chrome://zotero/content/recognizePDFDialog.xul")[0];
     54 		var completeStr = Zotero.getString("recognizePDF.complete.label");
     55 		while (progressWindow.document.getElementById("label").value != completeStr) {
     56 			await Zotero.Promise.delay(20);
     57 		}
     58 		
     59 		// The file should have been renamed
     60 		assert.equal(
     61 			attachment.attachmentFilename,
     62 			Zotero.Attachments.getFileBaseNameFromItem(item) + '.pdf'
     63 		);
     64 	});
     65 	
     66 	it("should recognize a PDF by arXiv ID", async function () {
     67 		this.timeout(30000);
     68 		// Import the PDF
     69 		var testdir = getTestDataDirectory();
     70 		testdir.append("recognizePDF_test_arXiv.pdf");
     71 		var attachment = await Zotero.Attachments.importFromFile({
     72 			file: testdir
     73 		});
     74 		
     75 		// Recognize the PDF
     76 		win.ZoteroPane.recognizeSelected();
     77 		
     78 		var addedIDs = await waitForItemEvent("add");
     79 		var modifiedIDs = await waitForItemEvent("modify");
     80 		// Item and note
     81 		assert.lengthOf(addedIDs, 2);
     82 		var item = Zotero.Items.get(addedIDs[0]);
     83 		assert.equal(item.getField("title"), "Scaling study of an improved fermion action on quenched lattices");
     84 		assert.lengthOf(modifiedIDs, 1);
     85 		
     86 		// Wait for status to show as complete
     87 		var progressWindow = getWindows("chrome://zotero/content/recognizePDFDialog.xul")[0];
     88 		var completeStr = Zotero.getString("recognizePDF.complete.label");
     89 		while (progressWindow.document.getElementById("label").value != completeStr) {
     90 			await Zotero.Promise.delay(20);
     91 		}
     92 		
     93 		// The file should have been renamed
     94 		assert.equal(
     95 			attachment.attachmentFilename,
     96 			Zotero.Attachments.getFileBaseNameFromItem(item) + '.pdf'
     97 		);
     98 	});
     99 	
    100 	it("should put new item in same collection", async function () {
    101 		this.timeout(30000);
    102 		// Import the PDF
    103 		var testdir = getTestDataDirectory();
    104 		testdir.append("recognizePDF_test_arXiv.pdf");
    105 		var collection = await createDataObject('collection');
    106 		var attachment = await Zotero.Attachments.importFromFile({
    107 			file: testdir,
    108 			collections: [collection.id]
    109 		});
    110 		
    111 		win.ZoteroPane.recognizeSelected();
    112 		
    113 		var addedIDs = await waitForItemEvent("add");
    114 		var modifiedIDs = await waitForItemEvent("modify");
    115 		// Item and note
    116 		assert.lengthOf(addedIDs, 2);
    117 		var item = Zotero.Items.get(addedIDs[0]);
    118 		assert.lengthOf(modifiedIDs, 1);
    119 		
    120 		// Wait for status to show as complete
    121 		var progressWindow = getWindows("chrome://zotero/content/recognizePDFDialog.xul")[0];
    122 		var completeStr = Zotero.getString("recognizePDF.complete.label");
    123 		while (progressWindow.document.getElementById("label").value != completeStr) {
    124 			await Zotero.Promise.delay(20);
    125 		}
    126 		
    127 		assert.isTrue(collection.hasItem(item.id));
    128 	});
    129 	
    130 	it("should recognize PDF by arXiv ID and put new item in same collection in group library", async function () {
    131 		this.timeout(30000);
    132 		var testdir = getTestDataDirectory();
    133 		testdir.append("recognizePDF_test_arXiv.pdf");
    134 		var group = await getGroup();
    135 		var collection = await createDataObject('collection', { libraryID: group.libraryID });
    136 		var attachment = await Zotero.Attachments.importFromFile({
    137 			libraryID: group.libraryID,
    138 			file: testdir,
    139 			collections: [collection.id],
    140 		});
    141 		
    142 		win.ZoteroPane.recognizeSelected();
    143 		
    144 		var addedIDs = await waitForItemEvent("add");
    145 		var modifiedIDs = await waitForItemEvent("modify");
    146 		// Item and note
    147 		assert.lengthOf(addedIDs, 2);
    148 		var item = Zotero.Items.get(addedIDs[0]);
    149 		assert.lengthOf(modifiedIDs, 1);
    150 		
    151 		// Wait for status to show as complete
    152 		var progressWindow = getWindows("chrome://zotero/content/recognizePDFDialog.xul")[0];
    153 		var completeStr = Zotero.getString("recognizePDF.complete.label");
    154 		while (progressWindow.document.getElementById("label").value != completeStr) {
    155 			await Zotero.Promise.delay(20);
    156 		}
    157 		
    158 		assert.isTrue(collection.hasItem(item.id));
    159 	});
    160 	
    161 	it.skip("should recognize PDF by ISBN and put new item in same collection in group library", async function () {
    162 		this.timeout(30000);
    163 		var testdir = getTestDataDirectory();
    164 		testdir.append("recognizePDF_test_ISBN.pdf");
    165 		var group = await getGroup();
    166 		var collection = await createDataObject('collection', { libraryID: group.libraryID });
    167 		var attachment = await Zotero.Attachments.importFromFile({
    168 			libraryID: group.libraryID,
    169 			file: testdir,
    170 			collections: [collection.id],
    171 		});
    172 		
    173 		win.ZoteroPane.recognizeSelected();
    174 		
    175 		var addedIDs = await waitForItemEvent("add");
    176 		var modifiedIDs = await waitForItemEvent("modify");
    177 		assert.lengthOf(addedIDs, 1);
    178 		var item = Zotero.Items.get(addedIDs[0]);
    179 		assert.lengthOf(modifiedIDs, 2);
    180 		
    181 		// Wait for status to show as complete
    182 		var progressWindow = getWindows("chrome://zotero/content/recognizePDFDialog.xul")[0];
    183 		var completeStr = Zotero.getString("recognizePDF.complete.label");
    184 		while (progressWindow.document.getElementById("label").value != completeStr) {
    185 			await Zotero.Promise.delay(20);
    186 		}
    187 		
    188 		assert.isTrue(collection.hasItem(item.id));
    189 	});
    190 	
    191 	it("should recognize PDF by title and put new item in same collection in group library", async function () {
    192 		this.timeout(30000);
    193 		var testdir = getTestDataDirectory();
    194 		testdir.append("recognizePDF_test_title.pdf");
    195 		var group = await getGroup();
    196 		var collection = await createDataObject('collection', { libraryID: group.libraryID });
    197 		var attachment = await Zotero.Attachments.importFromFile({
    198 			libraryID: group.libraryID,
    199 			file: testdir,
    200 			collections: [collection.id],
    201 		});
    202 		
    203 		win.ZoteroPane.recognizeSelected();
    204 		
    205 		var addedIDs = await waitForItemEvent("add");
    206 		var modifiedIDs = await waitForItemEvent("modify");
    207 		assert.lengthOf(addedIDs, 1);
    208 		var item = Zotero.Items.get(addedIDs[0]);
    209 		assert.lengthOf(modifiedIDs, 2);
    210 		
    211 		// Wait for status to show as complete
    212 		var progressWindow = getWindows("chrome://zotero/content/recognizePDFDialog.xul")[0];
    213 		var completeStr = Zotero.getString("recognizePDF.complete.label");
    214 		while (progressWindow.document.getElementById("label").value != completeStr) {
    215 			await Zotero.Promise.delay(20);
    216 		}
    217 		
    218 		assert.isTrue(collection.hasItem(item.id));
    219 	});
    220 });