Commit 5cdc120c authored by tsergeant's avatar tsergeant Committed by Commit bot

MD Bookmarks: Update TestStore API

This changes TestStore to inherit from Store, allowing tests to use
more production code paths. It also adds a new flag to TestStore which
allows page actions to be handled normally (rather than preventing them
from executing), which is useful for integration testing.

BUG=697706

Review-Url: https://codereview.chromium.org/2839393002
Cr-Commit-Position: refs/heads/master@{#467607}
parent 2b61f1cb
...@@ -2,55 +2,73 @@ ...@@ -2,55 +2,73 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
cr.define('bookmarks', function() { suiteSetup(function() {
var TestStore = function(data) { cr.define('bookmarks', function() {
this.data = Object.assign(bookmarks.util.createEmptyState(), data); var TestStore = function(data) {
this.lastAction_ = null; bookmarks.Store.call(this);
this.observers_ = []; this.data_ = Object.assign(bookmarks.util.createEmptyState(), data);
this.acceptInit_ = false; this.initialized_ = true;
};
this.lastAction_ = null;
TestStore.prototype = { this.acceptInit_ = false;
addObserver: function(client) { this.enableReducers_ = false;
this.observers_.push(client); };
},
TestStore.prototype = {
init: function(state) { __proto__: bookmarks.Store.prototype,
if (this.acceptInit_) {
this.data = state; init: function(state) {
this.acceptInit_ = false; if (this.acceptInit_)
} bookmarks.Store.prototype.init.call(this, state);
}, },
removeObserver: function(client) {}, get lastAction() {
return this.lastAction_;
isInitialized: function() { },
return true;
}, get data() {
return this.data_;
handleAction: function(action) { },
this.lastAction_ = action;
}, set data(newData) {
this.data_ = newData;
get lastAction() { },
return this.lastAction_;
}, /**
* Enable or disable calling bookmarks.reduceAction for each action.
notifyObservers: function() { * With reducers disabled (the default), TestStore is a stub which
// TODO(tsergeant): Revisit how state modifications work in UI tests. * requires state be managed manually (suitable for unit tests). With
// We don't want tests to worry about modifying the whole state tree. * reducers enabled, TestStore becomes a proxy for observing actions
// Instead, we could perform a deep clone in here to ensure that every * (suitable for integration tests).
// StoreClient is updated. * @param {boolean} enabled
this.observers_.forEach((client) => client.onStateChanged(this.data)); */
}, setReducersEnabled: function(enabled) {
this.enableReducers_ = enabled;
// Call in order to accept data from an init call to the TestStore once. },
acceptInitOnce: function() {
this.acceptInit_ = true; reduce_: function(action) {
}, this.lastAction_ = action;
}; if (this.enableReducers_)
bookmarks.Store.prototype.reduce_.call(this, action);
return { },
TestStore: TestStore,
}; notifyObservers: function() {
// TODO(tsergeant): Revisit how state modifications work in UI tests.
// We don't want tests to worry about modifying the whole state tree.
// Instead, we could perform a deep clone in here to ensure that every
// StoreClient is updated.
this.notifyObservers_(this.data);
},
// Call in order to accept data from an init call to the TestStore once.
acceptInitOnce: function() {
this.acceptInit_ = true;
this.initialized_ = false;
},
};
return {
TestStore: TestStore,
};
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment