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:
@@ -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.
|
||||
|
@@ -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', () => {
|
||||
|
Reference in New Issue
Block a user