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

Unified Diff: chrome/test/data/webui/md_bookmarks/store_client_test.js

Issue 2731473002: MD Bookmarks: Implement basis for new data-binding system (Closed)
Patch Set: calamity@ review Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/md_bookmarks_browsertest.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/md_bookmarks/store_client_test.js
diff --git a/chrome/test/data/webui/md_bookmarks/store_client_test.js b/chrome/test/data/webui/md_bookmarks/store_client_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..80bfa8494c909b690ed62db530bdf528995f5530
--- /dev/null
+++ b/chrome/test/data/webui/md_bookmarks/store_client_test.js
@@ -0,0 +1,94 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+suite('bookmarks.StoreClient', function() {
+ var store;
+ var client;
+
+ function update(newState) {
+ store.notifyObservers_(newState);
+ Polymer.dom.flush();
+ }
+
+ function getRenderedItems() {
+ return Array.from(client.root.querySelectorAll('.item'))
+ .map((div) => div.textContent.trim());
+ }
+
+ suiteSetup(function() {
+ document.body.innerHTML = `
+ <dom-module is="test-store-client">
+ <template>
+ <template is="dom-repeat" items="[[items]]">
+ <div class="item">[[item]]</div>
+ </template>
+ </template>
+ </dom-module>
+ `;
+
+ Polymer({
+ is: 'test-store-client',
+
+ behaviors: [bookmarks.StoreClient],
+
+ properties: {
+ items: {
+ type: Array,
+ observer: 'itemsChanged_',
+ },
+ },
+
+ attached: function() {
+ this.hasChanged = false;
+ this.watch('items', function(state) {
+ return state.items;
+ });
+ this.updateFromStore();
+ },
+
+ itemsChanged_: function(newItems, oldItems) {
+ if (oldItems)
+ this.hasChanged = true;
+ },
+ });
+ });
+
+ setup(function() {
+ PolymerTest.clearBody();
+
+ // Reset store instance:
+ bookmarks.Store.instance_ = new bookmarks.Store();
+ store = bookmarks.Store.getInstance();
+ store.init({
+ items: ['apple', 'banana', 'cantaloupe'],
+ count: 3,
+ });
+
+ client = document.createElement('test-store-client');
+ document.body.appendChild(client);
+ Polymer.dom.flush();
+ });
+
+ test('renders initial data', function() {
+ assertDeepEquals(['apple', 'banana', 'cantaloupe'], getRenderedItems());
+ });
+
+ test('renders changes to watched state', function() {
+ var newItems = ['apple', 'banana', 'courgette', 'durian'];
+ var newState = Object.assign({}, store.data, {
+ items: newItems,
+ });
+ update(newState);
+
+ assertTrue(client.hasChanged);
+ assertDeepEquals(newItems, getRenderedItems());
+ });
+
+ test('ignores changes to other subtrees', function() {
+ var newState = Object.assign({}, store.data, {count: 2});
+ update(newState);
+
+ assertFalse(client.hasChanged);
+ });
+});
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/md_bookmarks_browsertest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698