Show "content restored" message more selectively

With this change, we only show the "content restored" message if the
local content differs from the remote content.

Bug: Issue 8928
Change-Id: Ic0a3ca33998c7c3e4235d4676c435ad5face8ad3
This commit is contained in:
Kasper Nilsson
2018-06-14 10:52:56 -07:00
parent 20f001cd15
commit 304d18a171
2 changed files with 25 additions and 1 deletions

View File

@@ -155,7 +155,8 @@
return this.$.restAPI.getFileContent(changeNum, path, patchNum)
.then(res => {
if (storedContent && storedContent.message) {
if (storedContent && storedContent.message &&
storedContent.message !== res.content) {
this.dispatchEvent(new CustomEvent('show-alert',
{detail: {message: RESTORED_MESSAGE}, bubbles: true}));

View File

@@ -376,6 +376,29 @@ suite('gr-editor-view tests', () => {
});
});
test('local edit exists, is same as remote edit', () => {
sandbox.stub(element.$.storage, 'getEditableContentItem')
.returns({message: 'pending edit'});
sandbox.stub(element.$.restAPI, 'getFileContent')
.returns(Promise.resolve({
ok: true,
type: 'text/javascript',
content: 'pending edit',
}));
const alertStub = sandbox.stub();
element.addEventListener('show-alert', alertStub);
return element._getFileData(1, 'test', 1).then(() => {
flushAsynchronousOperations();
assert.isFalse(alertStub.called);
assert.equal(element._newContent, 'pending edit');
assert.equal(element._content, 'pending edit');
assert.equal(element._type, 'text/javascript');
});
});
test('storage key computation', () => {
element._changeNum = 1;
element._patchNum = 1;