Chromium Code Reviews| OLD | NEW |
|---|---|
| 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('closed folder state', function() { | 5 suite('closed folder state', function() { |
| 6 var nodes; | 6 var nodes; |
| 7 var initialState; | 7 var initialState; |
| 8 | 8 |
| 9 setup(function() { | 9 setup(function() { |
| 10 nodes = testTree(createFolder('0', [ | 10 nodes = testTree(createFolder('0', [ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 test('updates when a node is deleted', function() { | 118 test('updates when a node is deleted', function() { |
| 119 var action = bookmarks.actions.removeBookmark('3', '1', 1); | 119 var action = bookmarks.actions.removeBookmark('3', '1', 1); |
| 120 var nextState = bookmarks.NodeState.updateNodes(initialState, action); | 120 var nextState = bookmarks.NodeState.updateNodes(initialState, action); |
| 121 | 121 |
| 122 assertDeepEquals(['2', '4'], nextState['1'].children); | 122 assertDeepEquals(['2', '4'], nextState['1'].children); |
| 123 | 123 |
| 124 // TODO(tsergeant): Deleted nodes should be removed from the nodes map | 124 // TODO(tsergeant): Deleted nodes should be removed from the nodes map |
| 125 // entirely. | 125 // entirely. |
| 126 }); | 126 }); |
| 127 }); | 127 }); |
| 128 | |
| 129 suite('search state', function() { | |
| 130 var initialState; | |
| 131 | |
| 132 setup(function() { | |
| 133 // Search touches a few different things, so we test using the entire state: | |
| 134 initialState = bookmarks.util.createEmptyState(); | |
| 135 initialState.nodes = testTree(createFolder('0', [ | |
| 136 createFolder( | |
| 137 '1', | |
| 138 [ | |
| 139 createItem('2'), | |
| 140 ]), | |
| 141 ])); | |
| 142 }); | |
| 143 | |
| 144 test('updates when search is started and finished', function() { | |
| 145 var action; | |
| 146 var nextState; | |
| 147 | |
| 148 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.
| |
| 149 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
| |
| 150 | |
| 151 action = bookmarks.actions.setSearchTerm('test'); | |
| 152 nextState = bookmarks.reduceAction(nextState, action); | |
| 153 | |
| 154 assertEquals('test', nextState.search.term); | |
| 155 assertTrue(nextState.search.inProgress); | |
| 156 // UI should not have changed yet: | |
| 157 assertEquals('0', nextState.selectedFolder); | |
| 158 assertDeepEquals(['1'], bookmarks.util.getDisplayedList(nextState)); | |
| 159 | |
| 160 action = bookmarks.actions.setSearchResults(['1', '2']); | |
| 161 var searchedState = bookmarks.reduceAction(nextState, action); | |
| 162 | |
| 163 assertFalse(searchedState.search.inProgress); | |
| 164 // 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.
| |
| 165 assertEquals(null, searchedState.selectedFolder); | |
| 166 assertDeepEquals( | |
| 167 ['1', '2'], bookmarks.util.getDisplayedList(searchedState)); | |
| 168 | |
| 169 // Case 1: Clear search by setting an empty search term. | |
| 170 action = bookmarks.actions.setSearchTerm(''); | |
| 171 var clearedState = bookmarks.reduceAction(searchedState, action); | |
| 172 | |
| 173 assertEquals('1', clearedState.selectedFolder); | |
| 174 assertDeepEquals(['2'], bookmarks.util.getDisplayedList(clearedState)); | |
| 175 assertEquals('', clearedState.search.term); | |
| 176 assertDeepEquals([], clearedState.search.results); | |
| 177 | |
| 178 // Case 2: Clear search by selecting a new folder. | |
| 179 action = bookmarks.actions.selectFolder('0'); | |
| 180 var selectedState = bookmarks.reduceAction(searchedState, action); | |
|
calamity
2017/03/13 04:50:36
Cool.
| |
| 181 | |
| 182 assertEquals('0', selectedState.selectedFolder); | |
| 183 assertDeepEquals(['1'], bookmarks.util.getDisplayedList(selectedState)); | |
| 184 assertEquals('', selectedState.search.term); | |
| 185 assertDeepEquals([], selectedState.search.results); | |
| 186 }); | |
| 187 }); | |
| OLD | NEW |