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

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

Issue 2741393002: MD Bookmarks: Implement item selection in new data flow system (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/md_bookmarks/reducers_test.js
diff --git a/chrome/test/data/webui/md_bookmarks/reducers_test.js b/chrome/test/data/webui/md_bookmarks/reducers_test.js
index bffef5c0a938a3b8ccfc8ef05994c31aa46efc6d..01f79ac7f7c3880d91471252f1923f1a35fdc6b3 100644
--- a/chrome/test/data/webui/md_bookmarks/reducers_test.js
+++ b/chrome/test/data/webui/md_bookmarks/reducers_test.js
@@ -2,6 +2,88 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+suite('selection state', function() {
+ var initialState;
+
+ function select(items, anchor, add) {
+ return {
+ name: 'select-items',
+ add: add,
+ anchor: anchor,
+ items: items,
+ };
+ }
+
+ setup(function() {
+ initialState = {
+ anchor: null,
+ count: 0,
+ items: 1,
calamity 2017/03/14 03:01:45 This is supposed to be an Object.
tsergeant 2017/03/14 05:42:02 Done.
+ };
+ });
+
+ test('can select an item', function() {
+ var nextState;
+ var action;
+
+ action = select(['1'], '1', false);
+ nextState = bookmarks.SelectionState.updateSelection(initialState, action);
calamity 2017/03/14 03:01:45 nextState => state as in previous patch.
tsergeant 2017/03/14 05:42:02 Done.
+
+ assertDeepEquals({'1': true}, nextState.items);
+ assertEquals('1', nextState.anchor);
+
+ // Replace current selection.
+ action = select(['2'], '2', false);
+ nextState = bookmarks.SelectionState.updateSelection(nextState, action);
+ assertDeepEquals({'2': true}, nextState.items);
+ assertEquals('2', nextState.anchor);
+
+ // Add to current selection.
+ action = select(['3'], '3', true);
+ nextState = bookmarks.SelectionState.updateSelection(nextState, action);
+ assertDeepEquals({'2': true, '3': true}, nextState.items);
+ assertEquals('3', nextState.anchor);
+ });
+
+ test('can select multiple items', function() {
+ var nextState;
+ var action;
+
+ action = select(['1', '2', '3'], '3', false);
+ nextState = bookmarks.SelectionState.updateSelection(initialState, action);
+ assertDeepEquals({'1': true, '2': true, '3': true}, nextState.items);
+
+ action = select(['3', '4'], '4', true);
+ nextState = bookmarks.SelectionState.updateSelection(nextState, action);
+ assertDeepEquals(
+ {'1': true, '2': true, '3': true, '4': true}, nextState.items);
+ });
+
+ test('is cleared when selected folder changes', function() {
+ var nextState;
+ var action;
+
+ action = select(['1', '2', '3'], '3', false);
+ nextState = bookmarks.SelectionState.updateSelection(initialState, action);
+
+ action = bookmarks.actions.selectFolder('2');
+ nextState = bookmarks.SelectionState.updateSelection(nextState, action);
+ assertDeepEquals({}, nextState.items);
+ });
+
+ test('is cleared when search finished', function() {
+ var nextState;
+ var action;
+
+ action = select(['1', '2', '3'], '3', false);
+ nextState = bookmarks.SelectionState.updateSelection(initialState, action);
+
+ action = bookmarks.actions.setSearchResults(['2']);
+ nextState = bookmarks.SelectionState.updateSelection(nextState, action);
+ assertDeepEquals({}, nextState.items);
+ });
+});
+
suite('closed folder state', function() {
var nodes;
var initialState;

Powered by Google App Engine
This is Rietveld 408576698