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

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

Issue 2839393002: MD Bookmarks: Update TestStore API (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('bookmarks', function() { 5 suiteSetup(function() {
6 var TestStore = function(data) { 6 cr.define('bookmarks', function() {
7 this.data = Object.assign(bookmarks.util.createEmptyState(), data); 7 var TestStore = function(data) {
8 this.lastAction_ = null; 8 bookmarks.Store.call(this);
9 this.observers_ = []; 9 this.data_ = Object.assign(bookmarks.util.createEmptyState(), data);
10 this.acceptInit_ = false; 10 this.initialized_ = true;
11 };
12 11
13 TestStore.prototype = { 12 this.lastAction_ = null;
14 addObserver: function(client) { 13 this.acceptInit_ = false;
15 this.observers_.push(client); 14 this.enableReducers_ = false;
16 }, 15 };
17 16
18 init: function(state) { 17 TestStore.prototype = {
19 if (this.acceptInit_) { 18 __proto__: bookmarks.Store.prototype,
20 this.data = state;
21 this.acceptInit_ = false;
22 }
23 },
24 19
25 removeObserver: function(client) {}, 20 init: function(state) {
21 if (this.acceptInit_) {
22 bookmarks.Store.prototype.init.call(this, state);
23 }
calamity 2017/04/27 04:23:53 nit: no curlies.
tsergeant 2017/04/27 04:48:16 Done.
24 },
26 25
27 isInitialized: function() { 26 get lastAction() {
28 return true; 27 return this.lastAction_;
29 }, 28 },
30 29
31 handleAction: function(action) { 30 get data() {
32 this.lastAction_ = action; 31 return this.data_;
33 }, 32 },
34 33
35 get lastAction() { 34 set data(newData) {
36 return this.lastAction_; 35 this.data_ = newData;
37 }, 36 },
38 37
39 notifyObservers: function() { 38 /**
40 // TODO(tsergeant): Revisit how state modifications work in UI tests. 39 * Enable or disable calling bookmarks.reduceAction for each action.
41 // We don't want tests to worry about modifying the whole state tree. 40 * With reducers disabled (the default), TestStore is a stub which
42 // Instead, we could perform a deep clone in here to ensure that every 41 * requires state be managed manually (suitable for unit tests). With
43 // StoreClient is updated. 42 * reducers enabled, TestStore becomes a proxy for observing actions
44 this.observers_.forEach((client) => client.onStateChanged(this.data)); 43 * (suitable for integration tests).
45 }, 44 * @param {boolean} enabled
45 */
46 setReducersEnabled: function(enabled) {
47 this.enableReducers_ = enabled;
48 },
46 49
47 // Call in order to accept data from an init call to the TestStore once. 50 reduce_: function(action) {
48 acceptInitOnce: function() { 51 this.lastAction_ = action;
49 this.acceptInit_ = true; 52 if (this.enableReducers_)
50 }, 53 bookmarks.Store.prototype.reduce_.call(this, action);
51 }; 54 },
52 55
53 return { 56 notifyObservers: function() {
54 TestStore: TestStore, 57 // TODO(tsergeant): Revisit how state modifications work in UI tests.
55 }; 58 // We don't want tests to worry about modifying the whole state tree.
59 // Instead, we could perform a deep clone in here to ensure that every
60 // StoreClient is updated.
61 this.notifyObservers_(this.data);
62 },
63
64 // Call in order to accept data from an init call to the TestStore once.
65 acceptInitOnce: function() {
66 this.acceptInit_ = true;
67 this.initialized_ = false;
68 },
69 };
70
71 return {
72 TestStore: TestStore,
73 };
74 });
56 }); 75 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698