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

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

Issue 2972963003: MD Bookmarks: Prevent flash of folder contents when changing search term (Closed)
Patch Set: Created 3 years, 5 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 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 selection; 6 var selection;
7 var action; 7 var action;
8 8
9 function select(items, anchor, clear, toggle) { 9 function select(items, anchor, clear, toggle) {
10 return { 10 return {
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // Case 1: Clear search by setting an empty search term. 429 // Case 1: Clear search by setting an empty search term.
430 action = bookmarks.actions.setSearchTerm(''); 430 action = bookmarks.actions.setSearchTerm('');
431 var clearedState = bookmarks.reduceAction(searchedState, action); 431 var clearedState = bookmarks.reduceAction(searchedState, action);
432 432
433 // Should go back to displaying the contents of '2', which was shown before 433 // Should go back to displaying the contents of '2', which was shown before
434 // the search. 434 // the search.
435 assertEquals('2', clearedState.selectedFolder); 435 assertEquals('2', clearedState.selectedFolder);
436 assertFalse(bookmarks.util.isShowingSearch(clearedState)); 436 assertFalse(bookmarks.util.isShowingSearch(clearedState));
437 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(clearedState)); 437 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(clearedState));
438 assertEquals('', clearedState.search.term); 438 assertEquals('', clearedState.search.term);
439 assertDeepEquals([], clearedState.search.results); 439 assertDeepEquals(null, clearedState.search.results);
440 440
441 // Case 2: Clear search by selecting a new folder. 441 // Case 2: Clear search by selecting a new folder.
442 action = bookmarks.actions.selectFolder('1'); 442 action = bookmarks.actions.selectFolder('1');
443 var selectedState = bookmarks.reduceAction(searchedState, action); 443 var selectedState = bookmarks.reduceAction(searchedState, action);
444 444
445 assertEquals('1', selectedState.selectedFolder); 445 assertEquals('1', selectedState.selectedFolder);
446 assertFalse(bookmarks.util.isShowingSearch(selectedState)); 446 assertFalse(bookmarks.util.isShowingSearch(selectedState));
447 assertDeepEquals(['2'], bookmarks.util.getDisplayedList(selectedState)); 447 assertDeepEquals(['2'], bookmarks.util.getDisplayedList(selectedState));
448 assertEquals('', selectedState.search.term); 448 assertEquals('', selectedState.search.term);
449 assertDeepEquals([], selectedState.search.results); 449 assertDeepEquals(null, selectedState.search.results);
450 });
451
452 test('results do not clear while performing a second search', function() {
453 action = bookmarks.actions.setSearchTerm('te');
454 state = bookmarks.reduceAction(state, action);
455
456 assertFalse(bookmarks.util.isShowingSearch(state));
457
458 action = bookmarks.actions.setSearchResults(['2', '3']);
459 state = bookmarks.reduceAction(state, action);
460
461 assertFalse(state.search.inProgress);
462 assertTrue(bookmarks.util.isShowingSearch(state));
463
464 // Continuing the search should not clear the previous results, which should
465 // continue to show until the new results arrive.
466 action = bookmarks.actions.setSearchTerm('test');
467 state = bookmarks.reduceAction(state, action);
468
469 assertTrue(state.search.inProgress);
470 assertTrue(bookmarks.util.isShowingSearch(state));
471 assertDeepEquals(['2', '3'], bookmarks.util.getDisplayedList(state));
472
473 action = bookmarks.actions.setSearchResults(['3']);
474 state = bookmarks.reduceAction(state, action);
475
476 assertFalse(state.search.inProgress);
477 assertTrue(bookmarks.util.isShowingSearch(state));
478 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(state));
450 }); 479 });
451 480
452 test('removes deleted nodes', function() { 481 test('removes deleted nodes', function() {
453 var action; 482 var action;
454 483
455 action = bookmarks.actions.setSearchTerm('test'); 484 action = bookmarks.actions.setSearchTerm('test');
456 state = bookmarks.reduceAction(state, action); 485 state = bookmarks.reduceAction(state, action);
457 486
458 action = bookmarks.actions.setSearchResults(['1', '3', '2']); 487 action = bookmarks.actions.setSearchResults(['1', '3', '2']);
459 state = bookmarks.reduceAction(state, action); 488 state = bookmarks.reduceAction(state, action);
460 489
461 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes); 490 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes);
462 state = bookmarks.reduceAction(state, action); 491 state = bookmarks.reduceAction(state, action);
463 492
464 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of 493 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of
465 // 2. 494 // 2.
466 assertDeepEquals(['1'], state.search.results); 495 assertDeepEquals(['1'], state.search.results);
467 }); 496 });
468 }); 497 });
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