| 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('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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 }); | 80 }); |
| 81 | 81 |
| 82 test('deselect items', function() { | 82 test('deselect items', function() { |
| 83 action = select(['1', '2', '3'], '3', false); | 83 action = select(['1', '2', '3'], '3', false); |
| 84 state = bookmarks.SelectionState.updateSelection(state, action); | 84 state = bookmarks.SelectionState.updateSelection(state, action); |
| 85 | 85 |
| 86 action = bookmarks.actions.deselectItems(); | 86 action = bookmarks.actions.deselectItems(); |
| 87 state = bookmarks.SelectionState.updateSelection(state, action); | 87 state = bookmarks.SelectionState.updateSelection(state, action); |
| 88 assertDeepEquals({}, state.items); | 88 assertDeepEquals({}, state.items); |
| 89 }); | 89 }); |
| 90 |
| 91 test('deselects items when they are deleted', function() { |
| 92 var nodeList = testTree(createFolder('0', [ |
| 93 createFolder( |
| 94 '1', |
| 95 [ |
| 96 createItem('2'), |
| 97 createItem('3'), |
| 98 createItem('4'), |
| 99 ]), |
| 100 createItem('5'), |
| 101 ])); |
| 102 |
| 103 action = select(['2', '4', '5'], '4', false); |
| 104 state = bookmarks.SelectionState.updateSelection(state, action); |
| 105 |
| 106 action = bookmarks.actions.removeBookmark('1', '0', 0, nodeList); |
| 107 state = bookmarks.SelectionState.updateSelection(state, action); |
| 108 |
| 109 assertDeepEquals(['5'], normalizeSet(state.items)); |
| 110 assertEquals(null, state.anchor); |
| 111 }); |
| 90 }); | 112 }); |
| 91 | 113 |
| 92 suite('closed folder state', function() { | 114 suite('closed folder state', function() { |
| 93 var nodes; | 115 var nodes; |
| 94 var state; | 116 var state; |
| 95 var action; | 117 var action; |
| 96 | 118 |
| 97 setup(function() { | 119 setup(function() { |
| 98 nodes = testTree( | 120 nodes = testTree( |
| 99 createFolder( | 121 createFolder( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 }); | 170 }); |
| 149 }); | 171 }); |
| 150 | 172 |
| 151 suite('selected folder', function() { | 173 suite('selected folder', function() { |
| 152 var nodes; | 174 var nodes; |
| 153 var state; | 175 var state; |
| 154 var action; | 176 var action; |
| 155 | 177 |
| 156 setup(function() { | 178 setup(function() { |
| 157 nodes = testTree(createFolder('1', [ | 179 nodes = testTree(createFolder('1', [ |
| 158 createFolder('2', []), | 180 createFolder( |
| 181 '2', |
| 182 [ |
| 183 createFolder('3', []), |
| 184 createFolder('4', []), |
| 185 ]), |
| 159 ])); | 186 ])); |
| 160 | 187 |
| 161 state = '1'; | 188 state = '1'; |
| 162 }); | 189 }); |
| 163 | 190 |
| 164 test('updates from selectFolder action', function() { | 191 test('updates from selectFolder action', function() { |
| 165 action = bookmarks.actions.selectFolder('2'); | 192 action = bookmarks.actions.selectFolder('2'); |
| 166 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 193 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 167 state, action, nodes); | 194 state, action, nodes); |
| 168 assertEquals('2', state); | 195 assertEquals('2', state); |
| 169 }); | 196 }); |
| 170 | 197 |
| 171 test('updates when parent of selected folder is closed', function() { | 198 test('updates when parent of selected folder is closed', function() { |
| 172 action = bookmarks.actions.selectFolder('2'); | 199 action = bookmarks.actions.selectFolder('2'); |
| 173 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 200 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 174 state, action, nodes); | 201 state, action, nodes); |
| 175 | 202 |
| 176 action = bookmarks.actions.changeFolderOpen('1', false); | 203 action = bookmarks.actions.changeFolderOpen('1', false); |
| 177 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 204 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 178 state, action, nodes); | 205 state, action, nodes); |
| 179 assertEquals('1', state); | 206 assertEquals('1', state); |
| 180 }); | 207 }); |
| 208 |
| 209 test('selects ancestor when selected folder is deleted', function() { |
| 210 action = bookmarks.actions.selectFolder('3'); |
| 211 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 212 state, action, nodes); |
| 213 |
| 214 // Delete the selected folder: |
| 215 action = bookmarks.actions.removeBookmark('3', '2', 0, nodes); |
| 216 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 217 state, action, nodes); |
| 218 |
| 219 assertEquals('2', state); |
| 220 |
| 221 action = bookmarks.actions.selectFolder('4'); |
| 222 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 223 state, action, nodes); |
| 224 |
| 225 // Delete an ancestor of the selected folder: |
| 226 action = bookmarks.actions.removeBookmark('2', '1', 0, nodes); |
| 227 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 228 state, action, nodes); |
| 229 |
| 230 assertEquals('1', state); |
| 231 }); |
| 181 }); | 232 }); |
| 182 | 233 |
| 183 suite('node state', function() { | 234 suite('node state', function() { |
| 184 var state; | 235 var state; |
| 185 var action; | 236 var action; |
| 186 | 237 |
| 187 setup(function() { | 238 setup(function() { |
| 188 state = testTree( | 239 state = testTree( |
| 189 createFolder( | 240 createFolder( |
| 190 '1', | 241 '1', |
| (...skipping 26 matching lines...) Expand all Loading... |
| 217 | 268 |
| 218 // Cannot edit URL of a folder: | 269 // Cannot edit URL of a folder: |
| 219 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'}); | 270 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'}); |
| 220 state = bookmarks.NodeState.updateNodes(state, action); | 271 state = bookmarks.NodeState.updateNodes(state, action); |
| 221 | 272 |
| 222 assertEquals('folder', state['4'].title); | 273 assertEquals('folder', state['4'].title); |
| 223 assertEquals(undefined, state['4'].url); | 274 assertEquals(undefined, state['4'].url); |
| 224 }); | 275 }); |
| 225 | 276 |
| 226 test('updates when a node is deleted', function() { | 277 test('updates when a node is deleted', function() { |
| 227 action = bookmarks.actions.removeBookmark('3', '1', 1); | 278 action = bookmarks.actions.removeBookmark('3', '1', 1, state); |
| 228 state = bookmarks.NodeState.updateNodes(state, action); | 279 state = bookmarks.NodeState.updateNodes(state, action); |
| 229 | 280 |
| 230 assertDeepEquals(['2', '4'], state['1'].children); | 281 assertDeepEquals(['2', '4'], state['1'].children); |
| 231 | 282 |
| 232 // TODO(tsergeant): Deleted nodes should be removed from the nodes map | 283 assertDeepEquals(['2', '4'], state['1'].children); |
| 233 // entirely. | 284 assertEquals(undefined, state['3']); |
| 285 }); |
| 286 |
| 287 test('removes all children of deleted nodes', function() { |
| 288 action = bookmarks.actions.removeBookmark('1', '0', 0, state); |
| 289 state = bookmarks.NodeState.updateNodes(state, action); |
| 290 |
| 291 assertDeepEquals(['0', '5'], Object.keys(state).sort()); |
| 234 }); | 292 }); |
| 235 | 293 |
| 236 test('updates when a node is moved', function() { | 294 test('updates when a node is moved', function() { |
| 237 // Move within the same folder backwards. | 295 // Move within the same folder backwards. |
| 238 action = bookmarks.actions.moveBookmark('3', '1', 0, '1', 1); | 296 action = bookmarks.actions.moveBookmark('3', '1', 0, '1', 1); |
| 239 state = bookmarks.NodeState.updateNodes(state, action); | 297 state = bookmarks.NodeState.updateNodes(state, action); |
| 240 | 298 |
| 241 assertDeepEquals(['3', '2', '4'], state['1'].children); | 299 assertDeepEquals(['3', '2', '4'], state['1'].children); |
| 242 | 300 |
| 243 // Move within the same folder forwards. | 301 // Move within the same folder forwards. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 365 |
| 308 // Case 2: Clear search by selecting a new folder. | 366 // Case 2: Clear search by selecting a new folder. |
| 309 action = bookmarks.actions.selectFolder('2'); | 367 action = bookmarks.actions.selectFolder('2'); |
| 310 var selectedState = bookmarks.reduceAction(searchedState, action); | 368 var selectedState = bookmarks.reduceAction(searchedState, action); |
| 311 | 369 |
| 312 assertEquals('2', selectedState.selectedFolder); | 370 assertEquals('2', selectedState.selectedFolder); |
| 313 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); | 371 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); |
| 314 assertEquals('', selectedState.search.term); | 372 assertEquals('', selectedState.search.term); |
| 315 assertDeepEquals([], selectedState.search.results); | 373 assertDeepEquals([], selectedState.search.results); |
| 316 }); | 374 }); |
| 375 |
| 376 test('removes deleted nodes', function() { |
| 377 var action; |
| 378 |
| 379 action = bookmarks.actions.setSearchTerm('test'); |
| 380 state = bookmarks.reduceAction(state, action); |
| 381 |
| 382 action = bookmarks.actions.setSearchResults(['1', '3', '2']); |
| 383 state = bookmarks.reduceAction(state, action); |
| 384 |
| 385 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes); |
| 386 state = bookmarks.reduceAction(state, action); |
| 387 |
| 388 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of |
| 389 // 2. |
| 390 assertDeepEquals(['1'], state.search.results); |
| 391 }); |
| 317 }); | 392 }); |
| OLD | NEW |