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

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

Issue 2722083002: [MD Bookmarks] Flatten sidebar. (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
« no previous file with comments | « chrome/browser/resources/md_bookmarks/util.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 initialState; 6 var initialState;
7 7
8 function select(items, anchor, add) { 8 function select(items, anchor, add) {
9 return { 9 return {
10 name: 'select-items', 10 name: 'select-items',
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 action = select(['1', '2', '3'], '3', false); 78 action = select(['1', '2', '3'], '3', false);
79 nextState = bookmarks.SelectionState.updateSelection(initialState, action); 79 nextState = bookmarks.SelectionState.updateSelection(initialState, action);
80 80
81 action = bookmarks.actions.setSearchResults([createItem('2')]); 81 action = bookmarks.actions.setSearchResults([createItem('2')]);
82 nextState = bookmarks.SelectionState.updateSelection(nextState, action); 82 nextState = bookmarks.SelectionState.updateSelection(nextState, action);
83 assertDeepEquals({}, nextState.items); 83 assertDeepEquals({}, nextState.items);
84 }); 84 });
85 }); 85 });
86 86
87 suite('closed folder state', function() {
88 var nodes;
89 var initialState;
90
91 setup(function() {
92 nodes = testTree(createFolder('0', [
93 createFolder('1', []),
94 ]));
95 initialState = {};
96 });
97
98 test('toggle folder open state', function() {
99 var action = bookmarks.actions.changeFolderOpen('1', false);
100 var nextState = bookmarks.ClosedFolderState.updateClosedFolders(
101 initialState, action, nodes);
102 assertTrue(nextState['1']);
103 assertFalse(!!nextState['0']);
104 });
105
106 test('select folder with closed parent', function() {
107 var action;
108 var nextState;
109 // Close '0'
110 action = bookmarks.actions.changeFolderOpen('0', false);
111 nextState = bookmarks.ClosedFolderState.updateClosedFolders(
112 initialState, action, nodes);
113 assertTrue(nextState['0']);
114
115 // Should re-open when '1' is selected.
116 action = bookmarks.actions.selectFolder('1');
117 nextState = bookmarks.ClosedFolderState.updateClosedFolders(
118 nextState, action, nodes);
119 assertFalse(nextState['0']);
120 });
121 });
122
123 suite('selected folder', function() { 87 suite('selected folder', function() {
124 var nodes; 88 var nodes;
125 var initialState; 89 var initialState;
126 90
127 setup(function() { 91 setup(function() {
128 nodes = testTree(createFolder('0', [ 92 nodes = testTree(createFolder('0', [
129 createFolder('1', []), 93 createFolder('1', []),
130 ])); 94 ]));
131 95
132 initialState = '0'; 96 initialState = '0';
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Case 2: Clear search by selecting a new folder. 212 // Case 2: Clear search by selecting a new folder.
249 action = bookmarks.actions.selectFolder('0'); 213 action = bookmarks.actions.selectFolder('0');
250 var selectedState = bookmarks.reduceAction(searchedState, action); 214 var selectedState = bookmarks.reduceAction(searchedState, action);
251 215
252 assertEquals('0', selectedState.selectedFolder); 216 assertEquals('0', selectedState.selectedFolder);
253 assertDeepEquals(['1'], bookmarks.util.getDisplayedList(selectedState)); 217 assertDeepEquals(['1'], bookmarks.util.getDisplayedList(selectedState));
254 assertEquals('', selectedState.search.term); 218 assertEquals('', selectedState.search.term);
255 assertDeepEquals([], selectedState.search.results); 219 assertDeepEquals([], selectedState.search.results);
256 }); 220 });
257 }); 221 });
222
223 suite('sidebar', function() {
224 var initialState;
225 var state;
226 var action;
227
228 var assertFolderPropertyTrue = function(property, expected) {
229 var folderPropertyMap = {};
230 var open = {};
231 var count = 0;
232 state.sidebar.folders.forEach((folder) => {
233 folderPropertyMap[folder.id] = folder[property];
234 if (folder[property])
235 count++;
236 });
237 expected.forEach((id) => {
238 assertTrue(folderPropertyMap[id]);
239 });
240 assertEquals(expected.length, count);
241 };
242
243 setup(function() {
244 initialState = bookmarks.util.createEmptyState();
245 initialState.nodes = testTree(createFolder('0', [
246 createFolder(
247 '1',
248 [
249 createFolder('2', []),
250 ]),
251 createFolder('3', []),
252 ]));
253 initialState.sidebar =
254 bookmarks.util.initializeSidebar('0', initialState.nodes);
255 state = initialState;
256 });
257
258 test('toggle folder open state', function() {
259 action = bookmarks.actions.changeFolderOpen('1', false);
260 state = bookmarks.reduceAction(state, action);
261
262 assertFolderPropertyTrue('visible', ['1', '3']);
263 assertFolderPropertyTrue('open', ['2', '3']);
264 });
265
266 test('select folder with closed parent', function() {
267 // Close '1'
268 action = bookmarks.actions.changeFolderOpen('1', false);
269 state = bookmarks.reduceAction(state, action);
270 assertFolderPropertyTrue('visible', ['1', '3']);
271 assertFolderPropertyTrue('open', ['2', '3']);
272
273 // Should re-open when '2' is selected.
274 action = bookmarks.actions.selectFolder('2');
275 state = bookmarks.reduceAction(state, action);
276 assertFolderPropertyTrue('visible', ['1', '2', '3']);
277 assertFolderPropertyTrue('open', ['1', '2', '3']);
278 });
279
280 test('complex open close select', function() {
281 initialState.nodes = testTree(createFolder('0', [
282 createFolder(
283 '1',
284 [
285 createFolder('2', []),
286 createFolder(
287 '3',
288 [
289 createFolder('4', []),
290 ]),
291 ]),
292 createFolder(
293 '5',
294 [
295 createFolder('6', []),
296 createFolder('7', []),
297 ]),
298 ]));
299 initialState.sidebar =
300 bookmarks.util.initializeSidebar('0', initialState.nodes);
301
302 state = initialState;
303
304 // Close '3'
305 action = bookmarks.actions.changeFolderOpen('3', false);
306 state = bookmarks.reduceAction(state, action);
307 assertFolderPropertyTrue('visible', ['1', '2', '3', '5', '6', '7']);
308 assertFolderPropertyTrue('open', ['1', '2', '4', '5', '6', '7']);
309
310 // Close '1'
311 action = bookmarks.actions.changeFolderOpen('1', false);
312 state = bookmarks.reduceAction(state, action);
313 assertFolderPropertyTrue('visible', ['1', '5', '6', '7']);
314 assertFolderPropertyTrue('open', ['2', '4', '5', '6', '7']);
315
316 // Close '5'
317 action = bookmarks.actions.changeFolderOpen('5', false);
318 state = bookmarks.reduceAction(state, action);
319 assertFolderPropertyTrue('visible', ['1', '5']);
320 assertFolderPropertyTrue('open', ['2', '4', '6', '7']);
321
322 // 1' should re-open when '3' is selected.
323 action = bookmarks.actions.selectFolder('3');
324 state = bookmarks.reduceAction(state, action);
325 assertFolderPropertyTrue('visible', ['1', '2', '3', '5']);
326 assertFolderPropertyTrue('open', ['1', '2', '4', '6', '7']);
327 });
328
329 test('updates when a node is deleted', function() {
330 action = bookmarks.actions.removeBookmark('2', '1', 1);
331 state = bookmarks.reduceAction(state, action);
332
333 assertDeepEquals(
334 [
335 {id: '1', depth: 0, open: true, visible: true},
336 {id: '3', depth: 0, open: true, visible: true},
337 ],
338 state.sidebar.folders);
339 assertEquals(undefined, state.sidebar.folderMap['2']);
340 });
341
342 test('modifications for updating visibility', function() {
343 initialState.nodes = testTree(createFolder('0', [
344 createFolder(
345 '1',
346 [
347 createFolder('2', []),
348 createFolder(
349 '3',
350 [
351 createFolder('4', []),
352 ]),
353 ]),
354 createFolder(
355 '5',
356 [
357 createFolder('6', []),
358 createFolder('7', []),
359 ]),
360 ]));
361 initialState.sidebar =
362 bookmarks.util.initializeSidebar('0', initialState.nodes);
363
364 // Closing '3' should only change '4'.
365 assertDeepEquals(
366 ['4'],
367 Object.values(bookmarks.SidebarState
368 .updateVisibleFoldersBelowNode(state.sidebar.folders, 2, false))
369 .map((m) => m.id));
370
371 action = bookmarks.actions.changeFolderOpen('3', false);
372 state = bookmarks.reduceAction(state, action);
373
374 // Closing '1' should only change '2' and '3'.
375 assertDeepEquals(
376 ['2', '3'],
377 Object.values(bookmarks.SidebarState
378 .updateVisibleFoldersBelowNode(state.sidebar.folders, 0, false))
379 .map((m) => m.id));
380
381 action = bookmarks.actions.changeFolderOpen('1', false);
382 state = bookmarks.reduceAction(state, action);
383
384 // Opening '3' should have no effect.
385 assertDeepEquals(
386 [],
387 Object.values(bookmarks.SidebarState
388 .updateVisibleFoldersBelowNode(state.sidebar.folders, 2, true)));
389
390 action = bookmarks.actions.changeFolderOpen('3', true);
391 state = bookmarks.reduceAction(state, action);
392
393 // Opening '1' should change '2', '3', and '4'.
394 assertDeepEquals(
395 ['2', '3', '4'],
396 Object.values(bookmarks.SidebarState
397 .updateVisibleFoldersBelowNode(state.sidebar.folders, 0, true))
398 .map((m) => m.id));
399
400 action = bookmarks.actions.changeFolderOpen('1', true);
401 state = bookmarks.reduceAction(state, action);
402 });
403 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/util.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698