zotero/test/tests/itemFieldsTest.js
Dan Stillman 73f4273e2d Make Original Date a date field
Update the global schema to 45, resolve a field's date type through its
base-field mapping in ItemFields.isDate() (to cover priorityDate), and
convert stored values of date-type fields to multipart dates on schema
upgrade.
2026-08-20 12:57:46 -04:00

67 lines
2.2 KiB
JavaScript

"use strict";
describe("Zotero.ItemFields", function () {
describe("#getBaseIDFromTypeAndField()", function () {
it("should return the base field id for an item type and base-mapped field", async function () {
assert.equal(
Zotero.ItemFields.getBaseIDFromTypeAndField('audioRecording', 'label'),
Zotero.ItemFields.getID('publisher')
);
// Accept ids too
assert.equal(
Zotero.ItemFields.getBaseIDFromTypeAndField(
Zotero.ItemTypes.getID('audioRecording'),
Zotero.ItemFields.getID('label')
),
Zotero.ItemFields.getID('publisher')
);
})
it("should return the base field id for an item type and base field", async function () {
assert.equal(
Zotero.ItemFields.getBaseIDFromTypeAndField('book', 'publisher'),
Zotero.ItemFields.getID('publisher')
);
});
it("should return the base field id for an item type and base field when type has a base-mapped field", function () {
assert.equal(
Zotero.ItemFields.getBaseIDFromTypeAndField('hearing', 'number'),
Zotero.ItemFields.getID('number')
);
});
it("should return false for an item type and non-base-mapped field", async function () {
assert.isFalse(
Zotero.ItemFields.getBaseIDFromTypeAndField('audioRecording', 'runningTime')
);
});
it("should return false for invalid type-field combination", function () {
assert.isFalse(
Zotero.ItemFields.getBaseIDFromTypeAndField('note', 'runningTime')
);
});
});
describe("#isDate()", function () {
it("should treat base and mapped date-type fields as dates", function () {
assert.isTrue(Zotero.ItemFields.isDate('date'));
assert.isTrue(Zotero.ItemFields.isDate('dateDecided'));
assert.isTrue(Zotero.ItemFields.isDate('originalDate'));
assert.isTrue(Zotero.ItemFields.isDate('priorityDate'));
assert.isFalse(Zotero.ItemFields.isDate('title'));
});
});
describe("#getDirection()", function () {
it("should follow app locale for primary field", function () {
assert.equal(Zotero.ItemFields.getDirection('book', 'dateAdded', ''), Zotero.dir)
});
it("should use item language for non-field", function () {
assert.equal(Zotero.ItemFields.getDirection('book', 'creator-0-lastName', 'ar'), 'rtl');
});
});
})