www

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

quickCopyTest.js (2522B)


      1 describe("Zotero.QuickCopy", function() {
      2 	var quickCopyPref;
      3 	var prefName = "export.quickCopy.setting";
      4 	
      5 	before(function* () {
      6 		yield Zotero.QuickCopy.loadSiteSettings();
      7 		Zotero.Prefs.clear(prefName);
      8 		quickCopyPref = Zotero.Prefs.get(prefName);
      9 		quickCopyPref = JSON.stringify(Zotero.QuickCopy.unserializeSetting(quickCopyPref));
     10 	});
     11 	
     12 	afterEach(function () {
     13 		Zotero.Prefs.clear(prefName);
     14 	});
     15 	
     16 	// TODO: These should set site-specific prefs and test the actual response against it,
     17 	// but that will need to wait for 5.0. For now, just make sure they don't fail.
     18 	describe("#getFormatFromURL()", function () {
     19 		it("should handle an HTTP URL", function () {
     20 			assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com/'), quickCopyPref);
     21 		})
     22 		
     23 		it("should handle an HTTPS URL", function () {
     24 			assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('https://foo.com/'), quickCopyPref);
     25 		})
     26 		
     27 		it("should handle a domain and path", function () {
     28 			assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com/bar'), quickCopyPref);
     29 		})
     30 		
     31 		it("should handle a local host", function () {
     32 			assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo/'), quickCopyPref);
     33 		})
     34 		
     35 		it("should handle a domain with a trailing period", function () {
     36 			assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com.'), quickCopyPref);
     37 		})
     38 		
     39 		it("should handle an about: URL", function () {
     40 			assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('about:blank'), quickCopyPref);
     41 		})
     42 		
     43 		it("should handle a chrome URL", function () {
     44 			assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('chrome://zotero/content/tab.xul'), quickCopyPref);
     45 		})
     46 	})
     47 	
     48 	describe("#getContentFromItems()", function () {
     49 		it("should generate BibTeX", function* () {
     50 			var item = yield createDataObject('item');
     51 			var content = "";
     52 			var worked = false;
     53 			
     54 			yield Zotero.Translators.init();
     55 			
     56 			var translatorID = '9cb70025-a888-4a29-a210-93ec52da40d4'; // BibTeX
     57 			var format = 'export=' + translatorID;
     58 			Zotero.Prefs.set(prefName, format);
     59 			// Translator code for selected format is loaded automatically, so wait for it
     60 			var translator = Zotero.Translators.get(translatorID);
     61 			while (!translator.code) {
     62 				yield Zotero.Promise.delay(50);
     63 			}
     64 			
     65 			Zotero.QuickCopy.getContentFromItems(
     66 				[item],
     67 				format,
     68 				(obj, w) => {
     69 					content = obj.string;
     70 					worked = w;
     71 				}
     72 			);
     73 			assert.isTrue(worked);
     74 			assert.isTrue(content.trim().startsWith('@'));
     75 		});
     76 	});
     77 })