Commit 8a39bb77 authored by Sean Hammond's avatar Sean Hammond

Tweak the drafts.update() API

parent 0b7c3122
......@@ -137,8 +137,12 @@ function restoreFromDrafts(drafts, permissions, domainModel, vm) {
*/
function saveToDrafts(drafts, domainModel, vm) {
drafts.update(
domainModel, vm.isPrivate(),
domainModelTagsFromViewModelTags(vm.form.tags), vm.form.text);
domainModel,
{
isPrivate:vm.isPrivate(),
tags:domainModelTagsFromViewModelTags(vm.form.tags),
text:vm.form.text,
});
}
/** Update domainModel from vm.
......
......@@ -1323,7 +1323,7 @@ describe('annotation.js', function() {
assert.calledWith(
fakeDrafts.update,
parts.annotation, true, [], 'unsaved-text');
parts.annotation, {isPrivate:true, tags:[], text:'unsaved-text'});
});
it('should not create a new draft', function() {
......
......@@ -63,12 +63,12 @@ function DraftStore() {
* Update the draft version for a given annotation, replacing any
* existing draft.
*/
this.update = function update(model, isPrivate, tags, text) {
this.update = function update(model, changes) {
var newDraft = {
model: model,
isPrivate: isPrivate,
tags: tags,
text: text
isPrivate: changes.isPrivate,
tags: changes.tags,
text: changes.text
};
this.remove(model);
this._drafts.push(newDraft);
......
......@@ -11,7 +11,7 @@ describe('drafts', function () {
it('should save changes', function () {
var model = {id: 'foo'};
assert.notOk(drafts.get(model));
drafts.update(model, true, ['foo'], 'edit');
drafts.update(model, {isPrivate:true, tags:['foo'], text:'edit'});
assert.deepEqual(
drafts.get(model),
{isPrivate: true, tags: ['foo'], text: 'edit'});
......@@ -19,16 +19,16 @@ describe('drafts', function () {
it('should replace existing drafts', function () {
var model = {id: 'foo'};
drafts.update(model, true, ['foo'], 'foo');
drafts.update(model, true, ['foo'], 'bar');
drafts.update(model, {isPrivate:true, tags:['foo'], text:'foo'});
drafts.update(model, {isPrivate:true, tags:['foo'], text:'bar'});
assert.equal(drafts.get(model).text, 'bar');
});
it('should replace existing drafts with the same ID', function () {
var modelA = {id: 'foo'};
var modelB = {id: 'foo'};
drafts.update(modelA, true, ['foo'], 'foo');
drafts.update(modelB, true, ['foo'], 'bar');
drafts.update(modelA, {isPrivate:true, tags:['foo'], text:'foo'});
drafts.update(modelB, {isPrivate:true, tags:['foo'], text:'bar'});
assert.equal(drafts.get(modelA).text, 'bar');
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment