Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: chrome/test/data/webui/md_bookmarks/store_client_test.js

Issue 2946203002: MD Bookmarks: Batch updates to the UI when processing deletes and moves (Closed)
Patch Set: Batch in API listener Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 suite('bookmarks.StoreClient', function() {
6 var store;
7 var client;
8
9 function update(newState) {
10 store.notifyObservers_(newState);
11 Polymer.dom.flush();
12 }
13
14 function getRenderedItems() {
15 return Array.from(client.root.querySelectorAll('.item'))
16 .map((div) => div.textContent.trim());
17 }
18
19 suiteSetup(function() {
20 document.body.innerHTML = `
21 <dom-module is="test-store-client">
22 <template>
23 <template is="dom-repeat" items="[[items]]">
24 <div class="item">[[item]]</div>
25 </template>
26 </template>
27 </dom-module>
28 `;
29
30 Polymer({
31 is: 'test-store-client',
32
33 behaviors: [bookmarks.StoreClient],
34
35 properties: {
36 items: {
37 type: Array,
38 observer: 'itemsChanged_',
39 },
40 },
41
42 attached: function() {
43 this.hasChanged = false;
44 this.watch('items', function(state) {
45 return state.items;
46 });
47 this.updateFromStore();
48 },
49
50 itemsChanged_: function(newItems, oldItems) {
51 if (oldItems)
52 this.hasChanged = true;
53 },
54 });
55 });
56
57 setup(function() {
58 PolymerTest.clearBody();
59
60 // Reset store instance:
61 bookmarks.Store.instance_ = new bookmarks.Store();
62 store = bookmarks.Store.getInstance();
63 store.init({
64 items: ['apple', 'banana', 'cantaloupe'],
65 count: 3,
66 });
67
68 client = document.createElement('test-store-client');
69 document.body.appendChild(client);
70 Polymer.dom.flush();
71 });
72
73 test('renders initial data', function() {
74 assertDeepEquals(['apple', 'banana', 'cantaloupe'], getRenderedItems());
75 });
76
77 test('renders changes to watched state', function() {
78 var newItems = ['apple', 'banana', 'courgette', 'durian'];
79 var newState = Object.assign({}, store.data, {
80 items: newItems,
81 });
82 update(newState);
83
84 assertTrue(client.hasChanged);
85 assertDeepEquals(newItems, getRenderedItems());
86 });
87
88 test('ignores changes to other subtrees', function() {
89 var newState = Object.assign({}, store.data, {count: 2});
90 update(newState);
91
92 assertFalse(client.hasChanged);
93 });
94 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/md_bookmarks_browsertest.js ('k') | chrome/test/data/webui/md_bookmarks/store_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698