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

Side by Side 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 unified diff | Download patch
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 suite('selection state', function() {
6 var initialState;
7
8 function select(items, anchor, add) {
9 return {
10 name: 'select-items',
11 add: add,
12 anchor: anchor,
13 items: items,
14 };
15 }
16
17 setup(function() {
18 initialState = {
19 anchor: null,
20 count: 0,
21 items: 1,
calamity 2017/03/14 03:01:45 This is supposed to be an Object.
tsergeant 2017/03/14 05:42:02 Done.
22 };
23 });
24
25 test('can select an item', function() {
26 var nextState;
27 var action;
28
29 action = select(['1'], '1', false);
30 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.
31
32 assertDeepEquals({'1': true}, nextState.items);
33 assertEquals('1', nextState.anchor);
34
35 // Replace current selection.
36 action = select(['2'], '2', false);
37 nextState = bookmarks.SelectionState.updateSelection(nextState, action);
38 assertDeepEquals({'2': true}, nextState.items);
39 assertEquals('2', nextState.anchor);
40
41 // Add to current selection.
42 action = select(['3'], '3', true);
43 nextState = bookmarks.SelectionState.updateSelection(nextState, action);
44 assertDeepEquals({'2': true, '3': true}, nextState.items);
45 assertEquals('3', nextState.anchor);
46 });
47
48 test('can select multiple items', function() {
49 var nextState;
50 var action;
51
52 action = select(['1', '2', '3'], '3', false);
53 nextState = bookmarks.SelectionState.updateSelection(initialState, action);
54 assertDeepEquals({'1': true, '2': true, '3': true}, nextState.items);
55
56 action = select(['3', '4'], '4', true);
57 nextState = bookmarks.SelectionState.updateSelection(nextState, action);
58 assertDeepEquals(
59 {'1': true, '2': true, '3': true, '4': true}, nextState.items);
60 });
61
62 test('is cleared when selected folder changes', function() {
63 var nextState;
64 var action;
65
66 action = select(['1', '2', '3'], '3', false);
67 nextState = bookmarks.SelectionState.updateSelection(initialState, action);
68
69 action = bookmarks.actions.selectFolder('2');
70 nextState = bookmarks.SelectionState.updateSelection(nextState, action);
71 assertDeepEquals({}, nextState.items);
72 });
73
74 test('is cleared when search finished', function() {
75 var nextState;
76 var action;
77
78 action = select(['1', '2', '3'], '3', false);
79 nextState = bookmarks.SelectionState.updateSelection(initialState, action);
80
81 action = bookmarks.actions.setSearchResults(['2']);
82 nextState = bookmarks.SelectionState.updateSelection(nextState, action);
83 assertDeepEquals({}, nextState.items);
84 });
85 });
86
5 suite('closed folder state', function() { 87 suite('closed folder state', function() {
6 var nodes; 88 var nodes;
7 var initialState; 89 var initialState;
8 90
9 setup(function() { 91 setup(function() {
10 nodes = testTree(createFolder('0', [ 92 nodes = testTree(createFolder('0', [
11 createFolder('1', []), 93 createFolder('1', []),
12 ])); 94 ]));
13 initialState = {}; 95 initialState = {};
14 }); 96 });
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Case 2: Clear search by selecting a new folder. 260 // Case 2: Clear search by selecting a new folder.
179 action = bookmarks.actions.selectFolder('0'); 261 action = bookmarks.actions.selectFolder('0');
180 var selectedState = bookmarks.reduceAction(searchedState, action); 262 var selectedState = bookmarks.reduceAction(searchedState, action);
181 263
182 assertEquals('0', selectedState.selectedFolder); 264 assertEquals('0', selectedState.selectedFolder);
183 assertDeepEquals(['1'], bookmarks.util.getDisplayedList(selectedState)); 265 assertDeepEquals(['1'], bookmarks.util.getDisplayedList(selectedState));
184 assertEquals('', selectedState.search.term); 266 assertEquals('', selectedState.search.term);
185 assertDeepEquals([], selectedState.search.results); 267 assertDeepEquals([], selectedState.search.results);
186 }); 268 });
187 }); 269 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698