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

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

Issue 2704983002: MD Bookmarks: Proof-of-concept reimplementation of data storage/binding layer (Closed)
Patch Set: Add doc comments Created 3 years, 9 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 suiteSetup(function() {
10 document.body.innerHTML = `
11 <dom-module is="test-store-client">
12 <template>
13 <template is="dom-repeat" items="[[items]]">
14 <div class="item">[[item]]</div>
15 </template>
16 </template>
17 </dom-module>
18 `;
19
20 Polymer({
21 is: 'test-store-client',
22
23 behaviors: [bookmarks.StoreClient],
24
25 properties: {
26 items: {
27 type: Array,
28 observer: 'itemsChanged_',
29 },
30 },
31
32 attached: function() {
33 this.hasChanged = false;
34 this.observe('items', function(state) {
35 return state.items;
36 });
37 this.updateFromStore();
38 },
39
40 itemsChanged_: function(newItems, oldItems) {
41 if (oldItems)
42 this.hasChanged = true;
43 },
44 });
45 });
46
47 function update(newState) {
48 store.notifyObservers_(newState);
49 Polymer.dom.flush();
50 }
51
52 function getRenderedItems() {
53 return Array.from(client.root.querySelectorAll('.item'))
54 .map((div) => div.textContent.trim());
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 observed 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/sidebar_test.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