2017-03-31 11:27:22 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("Zotero.Styles", function() {
|
|
|
|
var styleID = "http://www.zotero.org/styles/cell";
|
|
|
|
var stylePath = OS.Path.join(getTestDataDirectory().path, 'cell.csl');
|
|
|
|
var styleFile = Zotero.File.pathToFile(stylePath);
|
|
|
|
var style;
|
|
|
|
|
|
|
|
before(function* () {
|
|
|
|
yield Zotero.Styles.init();
|
|
|
|
style = yield Zotero.File.getContentsAsync(stylePath);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Zotero.Styles.install", function() {
|
2017-04-06 11:19:25 +00:00
|
|
|
afterEach(`${styleID} style should be installed`, function* (){
|
2017-03-31 11:27:22 +00:00
|
|
|
assert.isOk(Zotero.Styles.get(styleID));
|
|
|
|
yield Zotero.Styles.get(styleID).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should install the style from string", function* () {
|
|
|
|
yield Zotero.Styles.install(style, styleID, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should install the style from nsIFile", function* () {
|
|
|
|
yield Zotero.Styles.install(styleFile, styleID, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should install the style from url", function* () {
|
|
|
|
var getContentsFromURLAsync = Zotero.File.getContentsFromURLAsync;
|
2018-08-03 11:42:15 +00:00
|
|
|
sinon.stub(Zotero.File, 'getContentsFromURLAsync').callsFake(function(url) {
|
|
|
|
if (url === styleID) {
|
2017-03-31 11:27:22 +00:00
|
|
|
return Zotero.Promise.resolve(style);
|
|
|
|
} else {
|
|
|
|
return getContentsFromURLAsync.apply(Zotero.File, arguments);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
yield Zotero.Styles.install({url: styleID}, styleID, true);
|
|
|
|
Zotero.File.getContentsFromURLAsync.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should install the style from file path", function* () {
|
|
|
|
yield Zotero.Styles.install({file: stylePath}, styleID, true);
|
|
|
|
})
|
|
|
|
});
|
2019-07-01 08:30:47 +00:00
|
|
|
|
|
|
|
describe("subtitle capitalization", function () {
|
|
|
|
var item;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
item = createUnsavedDataObject(
|
|
|
|
'item',
|
|
|
|
{
|
|
|
|
itemType: 'journalArticle',
|
|
|
|
title: 'Foo bar: baz qux'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
item.setField('shortTitle', 'Foo bar');
|
|
|
|
item.setField('date', '2019');
|
|
|
|
await item.saveTx();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should capitalize subtitles in APA", async function () {
|
|
|
|
var o = Zotero.QuickCopy.getContentFromItems(
|
|
|
|
[item],
|
|
|
|
'bibliography=http://www.zotero.org/styles/apa'
|
|
|
|
);
|
|
|
|
assert.equal(o.text, 'Foo bar: Baz qux. (2019).\n');
|
|
|
|
});
|
|
|
|
|
2019-08-01 21:32:56 +00:00
|
|
|
it("shouldn't capitalize subtitles in AMA", async function () {
|
2019-07-01 08:30:47 +00:00
|
|
|
var o = Zotero.QuickCopy.getContentFromItems(
|
|
|
|
[item],
|
|
|
|
'bibliography=http://www.zotero.org/styles/american-medical-association'
|
|
|
|
);
|
2020-05-09 23:30:41 +00:00
|
|
|
assert.equal(o.text, '1. Foo bar: baz qux. Published online 2019.\n');
|
2019-07-01 08:30:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't capitalize subtitles in Vancouver", async function () {
|
|
|
|
var o = Zotero.QuickCopy.getContentFromItems(
|
|
|
|
[item],
|
|
|
|
'bibliography=http://www.zotero.org/styles/vancouver'
|
|
|
|
);
|
|
|
|
assert.equal(o.text, '1. Foo bar: baz qux. 2019; \n');
|
|
|
|
});
|
|
|
|
});
|
2022-08-10 04:52:16 +00:00
|
|
|
|
|
|
|
describe("event-title replacement", function () {
|
|
|
|
var item;
|
|
|
|
var eventStyleXML = `<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0">
|
|
|
|
<info>
|
|
|
|
<title>Test</title>
|
|
|
|
<id>http://www.zotero.org/styles/test</id>
|
|
|
|
<link href="http://www.zotero.org/styles/test" rel="self"/>
|
|
|
|
<updated>2022-04-14T13:48:43+00:00</updated>
|
|
|
|
</info>
|
|
|
|
<bibliography>
|
|
|
|
<layout>
|
|
|
|
<text variable="event"/>
|
|
|
|
<text value=" - "/>
|
2022-08-10 05:33:13 +00:00
|
|
|
<text variable="event foo"/>
|
|
|
|
<text value=" - "/>
|
|
|
|
<text variable="event-place"/>
|
2022-08-10 04:52:16 +00:00
|
|
|
</layout>
|
|
|
|
</bibliography>
|
|
|
|
</style>
|
|
|
|
`;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
item = createUnsavedDataObject(
|
|
|
|
'item',
|
|
|
|
{
|
|
|
|
itemType: 'conferencePaper',
|
|
|
|
title: 'Conference Paper'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
item.setField('conferenceName', 'Conference');
|
2022-08-10 05:33:13 +00:00
|
|
|
item.setField('place', 'Place');
|
2022-08-10 04:52:16 +00:00
|
|
|
await item.saveTx();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should substitute `event-title` in style using `event`", function () {
|
|
|
|
var style = new Zotero.Style(eventStyleXML);
|
|
|
|
var cslEngine = style.getCiteProc('en-US', 'text');
|
|
|
|
var text = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, [item], "text");
|
|
|
|
cslEngine.free();
|
2022-08-10 05:33:13 +00:00
|
|
|
assert.equal(text, 'Conference - Conference - Place\n');
|
2022-08-10 04:52:16 +00:00
|
|
|
});
|
|
|
|
});
|
2017-03-31 11:27:22 +00:00
|
|
|
});
|