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

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: Review comments 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
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/list_test.js ('k') | 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 suite('selection state', function() {
6 var state;
7 var action;
8
9 function select(items, anchor, add) {
10 return {
11 name: 'select-items',
12 add: add,
13 anchor: anchor,
14 items: items,
15 };
16 }
17
18 setup(function() {
19 state = {
20 anchor: null,
21 items: {},
22 };
23 });
24
25 test('can select an item', function() {
26 action = select(['1'], '1', false);
27 state = bookmarks.SelectionState.updateSelection(state, action);
28
29 assertDeepEquals({'1': true}, state.items);
30 assertEquals('1', state.anchor);
31
32 // Replace current selection.
33 action = select(['2'], '2', false);
34 state = bookmarks.SelectionState.updateSelection(state, action);
35 assertDeepEquals({'2': true}, state.items);
36 assertEquals('2', state.anchor);
37
38 // Add to current selection.
39 action = select(['3'], '3', true);
40 state = bookmarks.SelectionState.updateSelection(state, action);
41 assertDeepEquals({'2': true, '3': true}, state.items);
42 assertEquals('3', state.anchor);
43 });
44
45 test('can select multiple items', function() {
46 action = select(['1', '2', '3'], '3', false);
47 state = bookmarks.SelectionState.updateSelection(state, action);
48 assertDeepEquals({'1': true, '2': true, '3': true}, state.items);
49
50 action = select(['3', '4'], '4', true);
51 state = bookmarks.SelectionState.updateSelection(state, action);
52 assertDeepEquals({'1': true, '2': true, '3': true, '4': true}, state.items);
53 });
54
55 test('is cleared when selected folder changes', function() {
56 action = select(['1', '2', '3'], '3', false);
57 state = bookmarks.SelectionState.updateSelection(state, action);
58
59 action = bookmarks.actions.selectFolder('2');
60 state = bookmarks.SelectionState.updateSelection(state, action);
61 assertDeepEquals({}, state.items);
62 });
63
64 test('is cleared when search finished', function() {
65 action = select(['1', '2', '3'], '3', false);
66 state = bookmarks.SelectionState.updateSelection(state, action);
67
68 action = bookmarks.actions.setSearchResults(['2']);
69 state = bookmarks.SelectionState.updateSelection(state, action);
70 assertDeepEquals({}, state.items);
71 });
72
73 test('is cleared when search cleared', function() {
74 action = select(['1', '2', '3'], '3', false);
75 state = bookmarks.SelectionState.updateSelection(state, action);
76
77 action = bookmarks.actions.clearSearch();
78 state = bookmarks.SelectionState.updateSelection(state, action);
79 assertDeepEquals({}, state.items);
80 });
81 });
82
5 suite('closed folder state', function() { 83 suite('closed folder state', function() {
6 var nodes; 84 var nodes;
7 // TODO(tsergeant): Remove use of 'initialState' and 'nextState'. 85 // TODO(tsergeant): Remove use of 'initialState' and 'nextState'.
8 var initialState; 86 var initialState;
9 87
10 setup(function() { 88 setup(function() {
11 nodes = testTree(createFolder('1', [ 89 nodes = testTree(createFolder('1', [
12 createFolder('2', []), 90 createFolder('2', []),
13 ])); 91 ]));
14 initialState = {}; 92 initialState = {};
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Case 2: Clear search by selecting a new folder. 258 // Case 2: Clear search by selecting a new folder.
181 action = bookmarks.actions.selectFolder('2'); 259 action = bookmarks.actions.selectFolder('2');
182 var selectedState = bookmarks.reduceAction(searchedState, action); 260 var selectedState = bookmarks.reduceAction(searchedState, action);
183 261
184 assertEquals('2', selectedState.selectedFolder); 262 assertEquals('2', selectedState.selectedFolder);
185 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); 263 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState));
186 assertEquals('', selectedState.search.term); 264 assertEquals('', selectedState.search.term);
187 assertDeepEquals([], selectedState.search.results); 265 assertDeepEquals([], selectedState.search.results);
188 }); 266 });
189 }); 267 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/list_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698