Upgrade gr-editable-content with alert

Editable content now shows an alert when it reloads with content cached
in gr-storage.

Bug: Issue 6309
Change-Id: Id38b7eddf26e223a2899a0ffb1b3fa72398da0f0
This commit is contained in:
Kasper Nilsson
2018-01-02 16:12:07 -08:00
parent 4b20dafe89
commit 9e54b7d4a9
2 changed files with 22 additions and 4 deletions

View File

@@ -14,6 +14,7 @@
(function() {
'use strict';
const RESTORED_MESSAGE = 'Content restored from a previous edit.';
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
Polymer({
@@ -31,6 +32,12 @@
* @event editable-content-cancel
*/
/**
* Fired when content is restored from storage.
*
* @event show-alert
*/
properties: {
content: {
notify: true,
@@ -81,10 +88,16 @@
let content;
if (this.storageKey) {
content = this.$.storage.getEditableContentItem(this.storageKey);
const storedContent =
this.$.storage.getEditableContentItem(this.storageKey);
if (storedContent && storedContent.message) {
content = storedContent.message;
this.dispatchEvent(new CustomEvent('show-alert',
{detail: {message: RESTORED_MESSAGE}, bubbles: true}));
}
}
if (!content) {
content = this.content;
content = this.content || '';
}
// TODO(wyatta) switch linkify sequence, see issue 5526.

View File

@@ -100,25 +100,30 @@ limitations under the License.
});
suite('storageKey and related behavior', () => {
let dispatchSpy;
setup(() => {
element.content = 'current content';
element.storageKey = 'test';
dispatchSpy = sandbox.spy(element, 'dispatchEvent');
});
test('editing toggled to true, has stored data', () => {
sandbox.stub(element.$.storage, 'getEditableContentItem')
.returns('stored content');
.returns({message: 'stored content'});
element.editing = true;
assert.equal(element._newContent, 'stored content');
assert.isTrue(dispatchSpy.called);
assert.equal(dispatchSpy.lastCall.args[0].type, 'show-alert');
});
test('editing toggled to true, has no stored data', () => {
sandbox.stub(element.$.storage, 'getEditableContentItem')
.returns('');
.returns({});
element.editing = true;
assert.equal(element._newContent, 'current content');
assert.isFalse(dispatchSpy.called);
});
test('edits are cached', () => {