Chromium Code Reviews| Index: chrome/test/data/webui/md_bookmarks/reducers_test.js |
| diff --git a/chrome/test/data/webui/md_bookmarks/reducers_test.js b/chrome/test/data/webui/md_bookmarks/reducers_test.js |
| index 381515db879ce1f401f76f614031c314edd5fcb2..bffef5c0a938a3b8ccfc8ef05994c31aa46efc6d 100644 |
| --- a/chrome/test/data/webui/md_bookmarks/reducers_test.js |
| +++ b/chrome/test/data/webui/md_bookmarks/reducers_test.js |
| @@ -125,3 +125,63 @@ suite('node state', function() { |
| // entirely. |
| }); |
| }); |
| + |
| +suite('search state', function() { |
| + var initialState; |
| + |
| + setup(function() { |
| + // Search touches a few different things, so we test using the entire state: |
| + initialState = bookmarks.util.createEmptyState(); |
| + initialState.nodes = testTree(createFolder('0', [ |
| + createFolder( |
| + '1', |
| + [ |
| + createItem('2'), |
| + ]), |
| + ])); |
| + }); |
| + |
| + test('updates when search is started and finished', function() { |
| + var action; |
| + var nextState; |
| + |
| + action = bookmarks.actions.selectFolder('0'); |
|
calamity
2017/03/13 04:50:36
Hmm. Can we select a real folder here. The root is
tsergeant
2017/03/14 02:40:36
Done. I've added an assert to the action to make s
calamity
2017/03/14 03:32:18
#Like+1.
|
| + nextState = bookmarks.reduceAction(initialState, action); |
|
calamity
2017/03/13 04:50:36
Initialize nextState with initialState so that thi
tsergeant
2017/03/14 02:40:36
For this test, I've combined initialState and next
|
| + |
| + action = bookmarks.actions.setSearchTerm('test'); |
| + nextState = bookmarks.reduceAction(nextState, action); |
| + |
| + assertEquals('test', nextState.search.term); |
| + assertTrue(nextState.search.inProgress); |
| + // UI should not have changed yet: |
| + assertEquals('0', nextState.selectedFolder); |
| + assertDeepEquals(['1'], bookmarks.util.getDisplayedList(nextState)); |
| + |
| + action = bookmarks.actions.setSearchResults(['1', '2']); |
| + var searchedState = bookmarks.reduceAction(nextState, action); |
| + |
| + assertFalse(searchedState.search.inProgress); |
| + // UI changes once search results arrive: |
|
calamity
2017/03/13 04:50:36
nit: Newlines before these comments.
tsergeant
2017/03/14 02:40:36
Done.
|
| + assertEquals(null, searchedState.selectedFolder); |
| + assertDeepEquals( |
| + ['1', '2'], bookmarks.util.getDisplayedList(searchedState)); |
| + |
| + // Case 1: Clear search by setting an empty search term. |
| + action = bookmarks.actions.setSearchTerm(''); |
| + var clearedState = bookmarks.reduceAction(searchedState, action); |
| + |
| + assertEquals('1', clearedState.selectedFolder); |
| + assertDeepEquals(['2'], bookmarks.util.getDisplayedList(clearedState)); |
| + assertEquals('', clearedState.search.term); |
| + assertDeepEquals([], clearedState.search.results); |
| + |
| + // Case 2: Clear search by selecting a new folder. |
| + action = bookmarks.actions.selectFolder('0'); |
| + var selectedState = bookmarks.reduceAction(searchedState, action); |
|
calamity
2017/03/13 04:50:36
Cool.
|
| + |
| + assertEquals('0', selectedState.selectedFolder); |
| + assertDeepEquals(['1'], bookmarks.util.getDisplayedList(selectedState)); |
| + assertEquals('', selectedState.search.term); |
| + assertDeepEquals([], selectedState.search.results); |
| + }); |
| +}); |