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

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

Issue 2812493002: MD Bookmarks: Restore any previously selected folder when clearing search (Closed)
Patch Set: Fix comment Created 3 years, 8 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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 action = bookmarks.actions.selectFolder('2'); 371 action = bookmarks.actions.selectFolder('2');
372 state = bookmarks.reduceAction(state, action); 372 state = bookmarks.reduceAction(state, action);
373 373
374 action = bookmarks.actions.setSearchTerm('test'); 374 action = bookmarks.actions.setSearchTerm('test');
375 state = bookmarks.reduceAction(state, action); 375 state = bookmarks.reduceAction(state, action);
376 376
377 assertEquals('test', state.search.term); 377 assertEquals('test', state.search.term);
378 assertTrue(state.search.inProgress); 378 assertTrue(state.search.inProgress);
379 379
380 // UI should not have changed yet: 380 // UI should not have changed yet.
381 assertEquals('2', state.selectedFolder); 381 assertFalse(bookmarks.util.isShowingSearch(state));
382 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(state)); 382 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(state));
383 383
384 action = bookmarks.actions.setSearchResults(['2', '3']); 384 action = bookmarks.actions.setSearchResults(['2', '3']);
385 var searchedState = bookmarks.reduceAction(state, action); 385 var searchedState = bookmarks.reduceAction(state, action);
386 386
387 assertFalse(searchedState.search.inProgress); 387 assertFalse(searchedState.search.inProgress);
388 388
389 // UI changes once search results arrive: 389 // UI changes once search results arrive.
390 assertEquals(null, searchedState.selectedFolder); 390 assertTrue(bookmarks.util.isShowingSearch(searchedState));
391 assertDeepEquals( 391 assertDeepEquals(
392 ['2', '3'], bookmarks.util.getDisplayedList(searchedState)); 392 ['2', '3'], bookmarks.util.getDisplayedList(searchedState));
393 393
394 // Case 1: Clear search by setting an empty search term. 394 // Case 1: Clear search by setting an empty search term.
395 action = bookmarks.actions.setSearchTerm(''); 395 action = bookmarks.actions.setSearchTerm('');
396 var clearedState = bookmarks.reduceAction(searchedState, action); 396 var clearedState = bookmarks.reduceAction(searchedState, action);
397 397
398 assertEquals('1', clearedState.selectedFolder); 398 // Should go back to displaying the contents of '2', which was shown before
399 assertDeepEquals(['2'], bookmarks.util.getDisplayedList(clearedState)); 399 // the search.
400 assertEquals('2', clearedState.selectedFolder);
401 assertFalse(bookmarks.util.isShowingSearch(clearedState));
402 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(clearedState));
400 assertEquals('', clearedState.search.term); 403 assertEquals('', clearedState.search.term);
401 assertDeepEquals([], clearedState.search.results); 404 assertDeepEquals([], clearedState.search.results);
402 405
403 // Case 2: Clear search by selecting a new folder. 406 // Case 2: Clear search by selecting a new folder.
404 action = bookmarks.actions.selectFolder('2'); 407 action = bookmarks.actions.selectFolder('1');
405 var selectedState = bookmarks.reduceAction(searchedState, action); 408 var selectedState = bookmarks.reduceAction(searchedState, action);
406 409
407 assertEquals('2', selectedState.selectedFolder); 410 assertEquals('1', selectedState.selectedFolder);
408 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); 411 assertFalse(bookmarks.util.isShowingSearch(selectedState));
412 assertDeepEquals(['2'], bookmarks.util.getDisplayedList(selectedState));
409 assertEquals('', selectedState.search.term); 413 assertEquals('', selectedState.search.term);
410 assertDeepEquals([], selectedState.search.results); 414 assertDeepEquals([], selectedState.search.results);
411 }); 415 });
412 416
413 test('removes deleted nodes', function() { 417 test('removes deleted nodes', function() {
414 var action; 418 var action;
415 419
416 action = bookmarks.actions.setSearchTerm('test'); 420 action = bookmarks.actions.setSearchTerm('test');
417 state = bookmarks.reduceAction(state, action); 421 state = bookmarks.reduceAction(state, action);
418 422
419 action = bookmarks.actions.setSearchResults(['1', '3', '2']); 423 action = bookmarks.actions.setSearchResults(['1', '3', '2']);
420 state = bookmarks.reduceAction(state, action); 424 state = bookmarks.reduceAction(state, action);
421 425
422 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes); 426 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes);
423 state = bookmarks.reduceAction(state, action); 427 state = bookmarks.reduceAction(state, action);
424 428
425 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of 429 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of
426 // 2. 430 // 2.
427 assertDeepEquals(['1'], state.search.results); 431 assertDeepEquals(['1'], state.search.results);
428 }); 432 });
429 }); 433 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/util.js ('k') | chrome/test/data/webui/md_bookmarks/router_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698