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() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const RESTORED_MESSAGE = 'Content restored from a previous edit.';
|
||||||
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
|
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
|
||||||
|
|
||||||
Polymer({
|
Polymer({
|
||||||
@@ -31,6 +32,12 @@
|
|||||||
* @event editable-content-cancel
|
* @event editable-content-cancel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when content is restored from storage.
|
||||||
|
*
|
||||||
|
* @event show-alert
|
||||||
|
*/
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
content: {
|
content: {
|
||||||
notify: true,
|
notify: true,
|
||||||
@@ -81,10 +88,16 @@
|
|||||||
|
|
||||||
let content;
|
let content;
|
||||||
if (this.storageKey) {
|
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) {
|
if (!content) {
|
||||||
content = this.content;
|
content = this.content || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(wyatta) switch linkify sequence, see issue 5526.
|
// TODO(wyatta) switch linkify sequence, see issue 5526.
|
||||||
|
@@ -100,25 +100,30 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
suite('storageKey and related behavior', () => {
|
suite('storageKey and related behavior', () => {
|
||||||
|
let dispatchSpy;
|
||||||
setup(() => {
|
setup(() => {
|
||||||
element.content = 'current content';
|
element.content = 'current content';
|
||||||
element.storageKey = 'test';
|
element.storageKey = 'test';
|
||||||
|
dispatchSpy = sandbox.spy(element, 'dispatchEvent');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('editing toggled to true, has stored data', () => {
|
test('editing toggled to true, has stored data', () => {
|
||||||
sandbox.stub(element.$.storage, 'getEditableContentItem')
|
sandbox.stub(element.$.storage, 'getEditableContentItem')
|
||||||
.returns('stored content');
|
.returns({message: 'stored content'});
|
||||||
element.editing = true;
|
element.editing = true;
|
||||||
|
|
||||||
assert.equal(element._newContent, 'stored content');
|
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', () => {
|
test('editing toggled to true, has no stored data', () => {
|
||||||
sandbox.stub(element.$.storage, 'getEditableContentItem')
|
sandbox.stub(element.$.storage, 'getEditableContentItem')
|
||||||
.returns('');
|
.returns({});
|
||||||
element.editing = true;
|
element.editing = true;
|
||||||
|
|
||||||
assert.equal(element._newContent, 'current content');
|
assert.equal(element._newContent, 'current content');
|
||||||
|
assert.isFalse(dispatchSpy.called);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('edits are cached', () => {
|
test('edits are cached', () => {
|
||||||
|
Reference in New Issue
Block a user