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

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

Issue 2740863003: MD Bookmarks: Implement search and 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
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('closed folder state', function() { 5 suite('closed folder state', function() {
6 var nodes; 6 var nodes;
7 var initialState; 7 var initialState;
calamity 2017/03/14 03:32:18 Can we also ditch all the other initialStates in t
tsergeant 2017/03/14 05:51:10 TODO added
8 8
9 setup(function() { 9 setup(function() {
10 nodes = testTree(createFolder('0', [ 10 nodes = testTree(createFolder('1', [
11 createFolder('1', []), 11 createFolder('2', []),
12 ])); 12 ]));
13 initialState = {}; 13 initialState = {};
14 }); 14 });
15 15
16 test('toggle folder open state', function() { 16 test('toggle folder open state', function() {
17 var action = bookmarks.actions.changeFolderOpen('1', false); 17 var action = bookmarks.actions.changeFolderOpen('2', false);
18 var nextState = bookmarks.ClosedFolderState.updateClosedFolders( 18 var nextState = bookmarks.ClosedFolderState.updateClosedFolders(
19 initialState, action, nodes); 19 initialState, action, nodes);
20 assertTrue(nextState['1']); 20 assertTrue(nextState['2']);
21 assertFalse(!!nextState['0']); 21 assertFalse(!!nextState['1']);
calamity 2017/03/14 03:32:18 nit: reverse these 2 lines.
tsergeant 2017/03/14 05:51:10 Done.
22 }); 22 });
23 23
24 test('select folder with closed parent', function() { 24 test('select folder with closed parent', function() {
25 var action; 25 var action;
26 var nextState; 26 var nextState;
27 // Close '0' 27 // Close '1'
28 action = bookmarks.actions.changeFolderOpen('0', false); 28 action = bookmarks.actions.changeFolderOpen('1', false);
29 nextState = bookmarks.ClosedFolderState.updateClosedFolders( 29 nextState = bookmarks.ClosedFolderState.updateClosedFolders(
30 initialState, action, nodes); 30 initialState, action, nodes);
31 assertTrue(nextState['0']); 31 assertTrue(nextState['1']);
calamity 2017/03/14 03:32:18 May as well also check '2's state here since there
tsergeant 2017/03/14 05:51:10 Done.
32 32
33 // Should re-open when '1' is selected. 33 // Should re-open when '2' is selected.
34 action = bookmarks.actions.selectFolder('1'); 34 action = bookmarks.actions.selectFolder('2');
35 nextState = bookmarks.ClosedFolderState.updateClosedFolders( 35 nextState = bookmarks.ClosedFolderState.updateClosedFolders(
36 nextState, action, nodes); 36 nextState, action, nodes);
37 assertFalse(nextState['0']); 37 assertFalse(!!nextState['1']);
38 }); 38 });
39 }); 39 });
40 40
41 suite('selected folder', function() { 41 suite('selected folder', function() {
42 var nodes; 42 var nodes;
43 var initialState; 43 var initialState;
44 44
45 setup(function() { 45 setup(function() {
46 nodes = testTree(createFolder('0', [ 46 nodes = testTree(createFolder('1', [
47 createFolder('1', []), 47 createFolder('2', []),
48 ])); 48 ]));
49 49
50 initialState = '0'; 50 initialState = '1';
51 }); 51 });
52 52
53 test('updates from selectFolder action', function() { 53 test('updates from selectFolder action', function() {
54 var action = bookmarks.actions.selectFolder('1'); 54 var action = bookmarks.actions.selectFolder('2');
55 var newState = bookmarks.SelectedFolderState.updateSelectedFolder( 55 var newState = bookmarks.SelectedFolderState.updateSelectedFolder(
56 initialState, action, nodes); 56 initialState, action, nodes);
57 assertEquals('1', newState); 57 assertEquals('2', newState);
58 }); 58 });
59 59
60 test('updates when parent of selected folder is closed', function() { 60 test('updates when parent of selected folder is closed', function() {
61 var action; 61 var action;
62 var newState; 62 var newState;
63 63
64 action = bookmarks.actions.selectFolder('1'); 64 action = bookmarks.actions.selectFolder('2');
65 newState = bookmarks.SelectedFolderState.updateSelectedFolder( 65 newState = bookmarks.SelectedFolderState.updateSelectedFolder(
66 initialState, action, nodes); 66 initialState, action, nodes);
67 67
68 action = bookmarks.actions.changeFolderOpen('0', false); 68 action = bookmarks.actions.changeFolderOpen('1', false);
69 newState = bookmarks.SelectedFolderState.updateSelectedFolder( 69 newState = bookmarks.SelectedFolderState.updateSelectedFolder(
70 newState, action, nodes); 70 newState, action, nodes);
71 assertEquals('0', newState); 71 assertEquals('1', newState);
72 }); 72 });
73 }); 73 });
74 74
75 suite('node state', function() { 75 suite('node state', function() {
76 var initialState; 76 var initialState;
77 77
78 setup(function() { 78 setup(function() {
79 initialState = testTree(createFolder('0', [ 79 initialState = testTree(
80 createFolder( 80 createFolder(
81 '1', 81 '1',
82 [ 82 [
83 createItem('2', {title: 'a', url: 'a.com'}), 83 createItem('2', {title: 'a', url: 'a.com'}),
84 createItem('3'), 84 createItem('3'),
85 createFolder('4', []), 85 createFolder('4', []),
86 ]), 86 ]),
87 createFolder('5', []), 87 createFolder('5', []));
88 ]));
89 }); 88 });
90 89
91 test('updates when a node is edited', function() { 90 test('updates when a node is edited', function() {
92 var action = bookmarks.actions.editBookmark('2', {title: 'b'}); 91 var action = bookmarks.actions.editBookmark('2', {title: 'b'});
93 var nextState = bookmarks.NodeState.updateNodes(initialState, action); 92 var nextState = bookmarks.NodeState.updateNodes(initialState, action);
94 93
95 assertEquals('b', nextState['2'].title); 94 assertEquals('b', nextState['2'].title);
96 assertEquals('a.com', nextState['2'].url); 95 assertEquals('a.com', nextState['2'].url);
97 96
98 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'}); 97 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'});
(...skipping 19 matching lines...) Expand all
118 test('updates when a node is deleted', function() { 117 test('updates when a node is deleted', function() {
119 var action = bookmarks.actions.removeBookmark('3', '1', 1); 118 var action = bookmarks.actions.removeBookmark('3', '1', 1);
120 var nextState = bookmarks.NodeState.updateNodes(initialState, action); 119 var nextState = bookmarks.NodeState.updateNodes(initialState, action);
121 120
122 assertDeepEquals(['2', '4'], nextState['1'].children); 121 assertDeepEquals(['2', '4'], nextState['1'].children);
123 122
124 // TODO(tsergeant): Deleted nodes should be removed from the nodes map 123 // TODO(tsergeant): Deleted nodes should be removed from the nodes map
125 // entirely. 124 // entirely.
126 }); 125 });
127 }); 126 });
127
128 suite('search state', function() {
129 var state;
130
131 setup(function() {
132 // Search touches a few different things, so we test using the entire state:
133 state = bookmarks.util.createEmptyState();
134 state.nodes = testTree(createFolder('1', [
135 createFolder(
136 '2',
137 [
138 createItem('3'),
139 ]),
140 ]));
141 });
142
143 test('updates when search is started and finished', function() {
144 var action;
145
146 action = bookmarks.actions.selectFolder('2');
147 state = bookmarks.reduceAction(state, action);
148
149 action = bookmarks.actions.setSearchTerm('test');
150 state = bookmarks.reduceAction(state, action);
151
152 assertEquals('test', state.search.term);
153 assertTrue(state.search.inProgress);
154
155 // UI should not have changed yet:
156 assertEquals('2', state.selectedFolder);
157 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(state));
158
159 action = bookmarks.actions.setSearchResults(['2', '3']);
160 var searchedState = bookmarks.reduceAction(state, action);
161
162 assertFalse(searchedState.search.inProgress);
163
164 // UI changes once search results arrive:
165 assertEquals(null, searchedState.selectedFolder);
166 assertDeepEquals(
167 ['2', '3'], bookmarks.util.getDisplayedList(searchedState));
168
169 // Case 1: Clear search by setting an empty search term.
170 action = bookmarks.actions.setSearchTerm('');
171 var clearedState = bookmarks.reduceAction(searchedState, action);
172
173 assertEquals('1', clearedState.selectedFolder);
174 assertDeepEquals(['2'], bookmarks.util.getDisplayedList(clearedState));
175 assertEquals('', clearedState.search.term);
176 assertDeepEquals([], clearedState.search.results);
177
178 // Case 2: Clear search by selecting a new folder.
179 action = bookmarks.actions.selectFolder('2');
180 var selectedState = bookmarks.reduceAction(searchedState, action);
181
182 assertEquals('2', selectedState.selectedFolder);
183 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState));
184 assertEquals('', selectedState.search.term);
185 assertDeepEquals([], selectedState.search.results);
186 });
187 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698