2015-07-04 02:06:12 +00:00
|
|
|
describe("Zotero.QuickCopy", function() {
|
2016-11-23 01:02:13 +00:00
|
|
|
var quickCopyPref;
|
|
|
|
var prefName = "export.quickCopy.setting";
|
|
|
|
|
2017-07-19 08:36:45 +00:00
|
|
|
before(function* () {
|
|
|
|
yield Zotero.QuickCopy.loadSiteSettings();
|
2016-11-23 01:02:13 +00:00
|
|
|
Zotero.Prefs.clear(prefName);
|
|
|
|
quickCopyPref = Zotero.Prefs.get(prefName);
|
|
|
|
quickCopyPref = JSON.stringify(Zotero.QuickCopy.unserializeSetting(quickCopyPref));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
Zotero.Prefs.clear(prefName);
|
|
|
|
});
|
2015-07-04 02:06:12 +00:00
|
|
|
|
|
|
|
// TODO: These should set site-specific prefs and test the actual response against it,
|
|
|
|
// but that will need to wait for 5.0. For now, just make sure they don't fail.
|
|
|
|
describe("#getFormatFromURL()", function () {
|
2015-07-04 02:14:08 +00:00
|
|
|
it("should handle an HTTP URL", function () {
|
2015-07-04 02:06:12 +00:00
|
|
|
assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com/'), quickCopyPref);
|
|
|
|
})
|
|
|
|
|
2015-07-04 02:14:08 +00:00
|
|
|
it("should handle an HTTPS URL", function () {
|
|
|
|
assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('https://foo.com/'), quickCopyPref);
|
|
|
|
})
|
|
|
|
|
2015-07-04 02:06:12 +00:00
|
|
|
it("should handle a domain and path", function () {
|
|
|
|
assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com/bar'), quickCopyPref);
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle a local host", function () {
|
|
|
|
assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo/'), quickCopyPref);
|
|
|
|
})
|
|
|
|
|
2015-07-04 03:46:39 +00:00
|
|
|
it("should handle a domain with a trailing period", function () {
|
|
|
|
assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com.'), quickCopyPref);
|
|
|
|
})
|
|
|
|
|
2015-07-04 02:06:12 +00:00
|
|
|
it("should handle an about: URL", function () {
|
|
|
|
assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('about:blank'), quickCopyPref);
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle a chrome URL", function () {
|
2018-08-17 06:18:35 +00:00
|
|
|
assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('chrome://zotero/content/foo.xul'), quickCopyPref);
|
2015-07-04 02:06:12 +00:00
|
|
|
})
|
|
|
|
})
|
2016-06-23 05:30:14 +00:00
|
|
|
|
|
|
|
describe("#getContentFromItems()", function () {
|
|
|
|
it("should generate BibTeX", function* () {
|
|
|
|
var item = yield createDataObject('item');
|
|
|
|
var content = "";
|
|
|
|
var worked = false;
|
|
|
|
|
2016-06-23 09:36:38 +00:00
|
|
|
yield Zotero.Translators.init();
|
|
|
|
|
|
|
|
var translatorID = '9cb70025-a888-4a29-a210-93ec52da40d4'; // BibTeX
|
|
|
|
var format = 'export=' + translatorID;
|
2016-11-23 01:02:13 +00:00
|
|
|
Zotero.Prefs.set(prefName, format);
|
2016-06-23 09:36:38 +00:00
|
|
|
// Translator code for selected format is loaded automatically, so wait for it
|
|
|
|
var translator = Zotero.Translators.get(translatorID);
|
|
|
|
while (!translator.code) {
|
|
|
|
yield Zotero.Promise.delay(50);
|
|
|
|
}
|
2016-06-23 05:30:14 +00:00
|
|
|
|
|
|
|
Zotero.QuickCopy.getContentFromItems(
|
|
|
|
[item],
|
|
|
|
format,
|
|
|
|
(obj, w) => {
|
|
|
|
content = obj.string;
|
|
|
|
worked = w;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
assert.isTrue(worked);
|
|
|
|
assert.isTrue(content.trim().startsWith('@'));
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 21:06:29 +00:00
|
|
|
|
|
|
|
it("should generate bibliography in default locale if Quick Copy locale not set", async function () {
|
|
|
|
var item = createUnsavedDataObject('item', { itemType: 'webpage', title: 'Foo' });
|
|
|
|
item.setField('date', '2020-03-11');
|
|
|
|
await item.saveTx();
|
|
|
|
var content = "";
|
|
|
|
var worked = false;
|
|
|
|
|
|
|
|
// Quick Copy locale not set
|
|
|
|
Zotero.Prefs.clear('export.quickCopy.locale');
|
|
|
|
// This shouldn't be used
|
|
|
|
Zotero.Prefs.set('export.lastLocale', 'fr-FR');
|
|
|
|
await Zotero.Styles.init();
|
|
|
|
|
|
|
|
var format = 'bibliography=http://www.zotero.org/styles/apa';
|
|
|
|
Zotero.Prefs.set(prefName, format);
|
|
|
|
|
|
|
|
var { text, html } = Zotero.QuickCopy.getContentFromItems([item], format);
|
|
|
|
Zotero.debug(text);
|
|
|
|
Zotero.debug(html);
|
|
|
|
assert.isTrue(text.startsWith('Foo'));
|
|
|
|
assert.include(text, 'March');
|
|
|
|
assert.isTrue(html.startsWith('<div'));
|
|
|
|
assert.include(html, '<i>Foo</i>');
|
|
|
|
assert.include(html, 'March');
|
|
|
|
});
|
2015-07-04 02:06:12 +00:00
|
|
|
})
|