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

Unified 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, 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
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..4857ada8f664b22184ee87bf6a91403a8923eb26
--- /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;
+
+ 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.observe('items', function(state) {
+ return state.items;
+ });
+ this.updateFromStore();
+ },
+
+ itemsChanged_: function(newItems, oldItems) {
+ if (oldItems)
+ this.hasChanged = true;
+ },
+ });
+ });
+
+ function update(newState) {
+ store.notifyObservers_(newState);
+ Polymer.dom.flush();
+ }
+
+ function getRenderedItems() {
+ return Array.from(client.root.querySelectorAll('.item'))
+ .map((div) => div.textContent.trim());
+ }
+
+ 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 observed 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/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