Commit 3d9d84ff authored by Robert Knight's avatar Robert Knight

Fix canceling edits reverting to the first-loaded version of an annotation

When updating an annotation, the update is currently applied
to a copy of the domain model. AIUI the rationale for this is to ensure
that 'domainModel' always reflects what is actually stored on the
server, so it should not be updated until after the update is
successfully committed.

However, after the update is successfully commited, the view was
updated with the updated domain model, but the local domain model
instance was never replaced. Therefore when reverting changes,
the card reverted to the first-loaded text for the annotation
instead of the last-saved version.

This commit fixes the problem by replacing the domain model
reference whenever an annotation update is received.

Fixes #2875
parent dce382e2
......@@ -384,6 +384,7 @@ function AnnotationController(
function onAnnotationUpdated(event, updatedDomainModel) {
if (updatedDomainModel.id === domainModel.id) {
domainModel = updatedDomainModel;
updateView(updatedDomainModel);
}
}
......@@ -699,9 +700,9 @@ function AnnotationController(
}
onFulfilled = function() {
drafts.remove(domainModel);
$rootScope.$emit('annotationUpdated', updatedModel);
view();
drafts.remove(domainModel);
};
onRejected = function(reason) {
flash.error(
......
......@@ -1925,7 +1925,7 @@ describe('annotation', function() {
var controller = createAnnotationDirective({
annotation: {
id: 'test-annotation-id',
user: 'acct:bill@localhost'
user: 'acct:bill@localhost',
}
}).controller;
controller.edit();
......@@ -1934,5 +1934,33 @@ describe('annotation', function() {
controller.revert();
assert.equal(controller.form.text, void 0);
});
it('reverts to the most recently saved version when canceling changes',
function () {
var controller = createAnnotationDirective({
annotation: {
user: 'acct:bill@localhost',
$create: function () {
this.id = 'new-annotation-id';
return Promise.resolve();
},
$update: function () {
return Promise.resolve(this);
},
},
}).controller;
controller.edit();
controller.form.text = 'New annotation text';
return controller.save().then(function () {
controller.edit();
controller.form.text = 'Updated annotation text';
return controller.save();
}).then(function () {
controller.edit();
controller.revert();
assert.equal(controller.form.text, 'Updated annotation text');
});
});
});
});
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