Fix saving of tags
This commit is contained in:
parent
26e1372f46
commit
3a995d64a4
|
@ -1587,8 +1587,8 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
}
|
||||
|
||||
// Tags
|
||||
if (this._changed.tags && this._previousData.tags) {
|
||||
let oldTags = this._previousData.tags;
|
||||
if (this._changed.tags) {
|
||||
let oldTags = this._previousData.tags || [];
|
||||
let newTags = this._tags;
|
||||
|
||||
// Convert to individual JSON objects, diff, and convert back
|
||||
|
|
|
@ -261,5 +261,61 @@ describe("Zotero.Item", function () {
|
|||
file.append(filename);
|
||||
assert.equal(item.getFile().path, file.path);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
describe("#setTags", function () {
|
||||
it("should save an array of tags in API JSON format", function* () {
|
||||
var tags = [
|
||||
{
|
||||
tag: "A"
|
||||
},
|
||||
{
|
||||
tag: "B"
|
||||
}
|
||||
];
|
||||
var item = new Zotero.Item('journalArticle');
|
||||
item.setTags(tags);
|
||||
var id = yield item.save();
|
||||
item = yield Zotero.Items.getAsync(id);
|
||||
yield item.loadTags();
|
||||
assert.sameDeepMembers(item.getTags(tags), tags);
|
||||
})
|
||||
|
||||
it("shouldn't mark item as changed if tags haven't changed", function* () {
|
||||
var tags = [
|
||||
{
|
||||
tag: "A"
|
||||
},
|
||||
{
|
||||
tag: "B"
|
||||
}
|
||||
];
|
||||
var item = new Zotero.Item('journalArticle');
|
||||
item.setTags(tags);
|
||||
var id = yield item.save();
|
||||
item = yield Zotero.Items.getAsync(id);
|
||||
yield item.loadTags();
|
||||
item.setTags(tags);
|
||||
assert.isFalse(item.hasChanged());
|
||||
})
|
||||
|
||||
it("should remove an existing tag", function* () {
|
||||
var tags = [
|
||||
{
|
||||
tag: "A"
|
||||
},
|
||||
{
|
||||
tag: "B"
|
||||
}
|
||||
];
|
||||
var item = new Zotero.Item('journalArticle');
|
||||
item.setTags(tags);
|
||||
var id = yield item.save();
|
||||
item = yield Zotero.Items.getAsync(id);
|
||||
yield item.loadTags();
|
||||
item.setTags(tags.slice(0));
|
||||
yield item.save();
|
||||
assert.sameDeepMembers(item.getTags(tags), tags.slice(0));
|
||||
})
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user