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

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

Issue 2752223004: MD Bookmarks: Remove deleted nodes from state tree (Closed)
Patch Set: Rebase 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() { 5 suite('selection state', function() {
6 var state; 6 var state;
7 var action; 7 var action;
8 8
9 function select(items, anchor, add) { 9 function select(items, anchor, add) {
10 return { 10 return {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 }); 71 });
72 72
73 test('is cleared when search cleared', function() { 73 test('is cleared when search cleared', function() {
74 action = select(['1', '2', '3'], '3', false); 74 action = select(['1', '2', '3'], '3', false);
75 state = bookmarks.SelectionState.updateSelection(state, action); 75 state = bookmarks.SelectionState.updateSelection(state, action);
76 76
77 action = bookmarks.actions.clearSearch(); 77 action = bookmarks.actions.clearSearch();
78 state = bookmarks.SelectionState.updateSelection(state, action); 78 state = bookmarks.SelectionState.updateSelection(state, action);
79 assertDeepEquals({}, state.items); 79 assertDeepEquals({}, state.items);
80 }); 80 });
81
82 test('deselects items when they are deleted', function() {
83 var nodeList = testTree(createFolder('0', [
84 createFolder(
85 '1',
86 [
87 createItem('2'),
88 createItem('3'),
89 createItem('4'),
90 ]),
91 createItem('5'),
92 ]));
93
94 action = select(['2', '4', '5'], '4', false);
95 state = bookmarks.SelectionState.updateSelection(state, action);
96
97 action = bookmarks.actions.removeBookmark('1', '0', 0, nodeList);
98 state = bookmarks.SelectionState.updateSelection(state, action);
99
100 assertDeepEquals({5: true}, state.items);
101 assertEquals(null, state.anchor);
102 });
81 }); 103 });
82 104
83 suite('closed folder state', function() { 105 suite('closed folder state', function() {
84 var nodes; 106 var nodes;
85 var state; 107 var state;
86 var action; 108 var action;
87 109
88 setup(function() { 110 setup(function() {
89 nodes = testTree( 111 nodes = testTree(
90 createFolder( 112 createFolder(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 }); 161 });
140 }); 162 });
141 163
142 suite('selected folder', function() { 164 suite('selected folder', function() {
143 var nodes; 165 var nodes;
144 var state; 166 var state;
145 var action; 167 var action;
146 168
147 setup(function() { 169 setup(function() {
148 nodes = testTree(createFolder('1', [ 170 nodes = testTree(createFolder('1', [
149 createFolder('2', []), 171 createFolder(
172 '2',
173 [
174 createFolder('3', []),
175 ]),
150 ])); 176 ]));
151 177
152 state = '1'; 178 state = '1';
153 }); 179 });
154 180
155 test('updates from selectFolder action', function() { 181 test('updates from selectFolder action', function() {
156 action = bookmarks.actions.selectFolder('2'); 182 action = bookmarks.actions.selectFolder('2');
157 state = bookmarks.SelectedFolderState.updateSelectedFolder( 183 state = bookmarks.SelectedFolderState.updateSelectedFolder(
158 state, action, nodes); 184 state, action, nodes);
159 assertEquals('2', state); 185 assertEquals('2', state);
160 }); 186 });
161 187
162 test('updates when parent of selected folder is closed', function() { 188 test('updates when parent of selected folder is closed', function() {
163 action = bookmarks.actions.selectFolder('2'); 189 action = bookmarks.actions.selectFolder('2');
164 state = bookmarks.SelectedFolderState.updateSelectedFolder( 190 state = bookmarks.SelectedFolderState.updateSelectedFolder(
165 state, action, nodes); 191 state, action, nodes);
166 192
167 action = bookmarks.actions.changeFolderOpen('1', false); 193 action = bookmarks.actions.changeFolderOpen('1', false);
168 state = bookmarks.SelectedFolderState.updateSelectedFolder( 194 state = bookmarks.SelectedFolderState.updateSelectedFolder(
169 state, action, nodes); 195 state, action, nodes);
170 assertEquals('1', state); 196 assertEquals('1', state);
171 }); 197 });
198
199 test('selects ancestor when selected folder is deleted', function() {
200 action = bookmarks.actions.selectFolder('3');
201 state = bookmarks.SelectedFolderState.updateSelectedFolder(
202 state, action, nodes);
203
204 // Delete the selected folder:
205 action = bookmarks.actions.removeBookmark('3', '2', 0, nodes);
206 state = bookmarks.SelectedFolderState.updateSelectedFolder(
207 state, action, nodes);
208
209 assertEquals('2', state);
210
211 action = bookmarks.actions.selectFolder('3');
calamity 2017/04/03 06:54:24 This is technically selecting a deleted folder, bu
tsergeant 2017/04/04 04:42:28 Seems like a reasonable change. In the meantime,
212 state = bookmarks.SelectedFolderState.updateSelectedFolder(
213 state, action, nodes);
214
215 // Delete an ancestor of the selected folder:
216 action = bookmarks.actions.removeBookmark('2', '1', 0, nodes);
217 state = bookmarks.SelectedFolderState.updateSelectedFolder(
218 state, action, nodes);
219
220 assertEquals('1', state);
221 });
172 }); 222 });
173 223
174 suite('node state', function() { 224 suite('node state', function() {
175 var state; 225 var state;
176 var action; 226 var action;
177 227
178 setup(function() { 228 setup(function() {
179 state = testTree( 229 state = testTree(
180 createFolder( 230 createFolder(
181 '1', 231 '1',
(...skipping 26 matching lines...) Expand all
208 258
209 // Cannot edit URL of a folder: 259 // Cannot edit URL of a folder:
210 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'}); 260 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'});
211 state = bookmarks.NodeState.updateNodes(state, action); 261 state = bookmarks.NodeState.updateNodes(state, action);
212 262
213 assertEquals('folder', state['4'].title); 263 assertEquals('folder', state['4'].title);
214 assertEquals(undefined, state['4'].url); 264 assertEquals(undefined, state['4'].url);
215 }); 265 });
216 266
217 test('updates when a node is deleted', function() { 267 test('updates when a node is deleted', function() {
218 action = bookmarks.actions.removeBookmark('3', '1', 1); 268 action = bookmarks.actions.removeBookmark('3', '1', 1, state);
219 state = bookmarks.NodeState.updateNodes(state, action); 269 state = bookmarks.NodeState.updateNodes(state, action);
220 270
221 assertDeepEquals(['2', '4'], state['1'].children); 271 assertDeepEquals(['2', '4'], state['1'].children);
222 272
223 // TODO(tsergeant): Deleted nodes should be removed from the nodes map 273 assertDeepEquals(['2', '4'], state['1'].children);
224 // entirely. 274 assertEquals(undefined, state['3']);
275 });
276
277 test('removes all children of deleted nodes', function() {
278 action = bookmarks.actions.removeBookmark('1', '0', 0, state);
279 state = bookmarks.NodeState.updateNodes(state, action);
280
281 assertDeepEquals(['0', '5'], Object.keys(state).sort());
225 }); 282 });
226 283
227 test('updates when a node is moved', function() { 284 test('updates when a node is moved', function() {
228 // Move within the same folder backwards. 285 // Move within the same folder backwards.
229 action = bookmarks.actions.moveBookmark('3', '1', 0, '1', 1); 286 action = bookmarks.actions.moveBookmark('3', '1', 0, '1', 1);
230 state = bookmarks.NodeState.updateNodes(state, action); 287 state = bookmarks.NodeState.updateNodes(state, action);
231 288
232 assertDeepEquals(['3', '2', '4'], state['1'].children); 289 assertDeepEquals(['3', '2', '4'], state['1'].children);
233 290
234 // Move within the same folder forwards. 291 // Move within the same folder forwards.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 355
299 // Case 2: Clear search by selecting a new folder. 356 // Case 2: Clear search by selecting a new folder.
300 action = bookmarks.actions.selectFolder('2'); 357 action = bookmarks.actions.selectFolder('2');
301 var selectedState = bookmarks.reduceAction(searchedState, action); 358 var selectedState = bookmarks.reduceAction(searchedState, action);
302 359
303 assertEquals('2', selectedState.selectedFolder); 360 assertEquals('2', selectedState.selectedFolder);
304 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); 361 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState));
305 assertEquals('', selectedState.search.term); 362 assertEquals('', selectedState.search.term);
306 assertDeepEquals([], selectedState.search.results); 363 assertDeepEquals([], selectedState.search.results);
307 }); 364 });
365
366 test('removes deleted nodes', function() {
367 var action;
368
369 action = bookmarks.actions.setSearchTerm('test');
370 state = bookmarks.reduceAction(state, action);
371
372 action = bookmarks.actions.setSearchResults(['1', '3', '2']);
373 state = bookmarks.reduceAction(state, action);
374
375 action = bookmarks.actions.removeBookmark('3', '2', 0, state.nodes);
376 state = bookmarks.reduceAction(state, action);
377
378 assertDeepEquals(['1', '2'], state.search.results);
calamity 2017/04/03 06:54:24 Also delete 1 and ensure 2 vanishes due to being a
tsergeant 2017/04/04 04:42:28 Done, I changed it to delete 2 and check 2 and 3 v
379 });
308 }); 380 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698