Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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('<bookmarks-store>', function() { | 5 suite('<bookmarks-store>', function() { |
| 6 var store; | 6 var store; |
| 7 var TEST_TREE; | 7 var TEST_TREE; |
| 8 | 8 |
| 9 function replaceStore() { | 9 function replaceStore() { |
| 10 store = document.createElement('bookmarks-store'); | 10 store = document.createElement('bookmarks-store'); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 ////////////////////////////////////////////////////////////////////////////// | 226 ////////////////////////////////////////////////////////////////////////////// |
| 227 // search tests: | 227 // search tests: |
| 228 | 228 |
| 229 test('displayedList updates after searchTerm changes', function() { | 229 test('displayedList updates after searchTerm changes', function() { |
| 230 var SEARCH_RESULTS = [ | 230 var SEARCH_RESULTS = [ |
| 231 'cat', | 231 'cat', |
| 232 'apple', | 232 'apple', |
| 233 'Paris', | 233 'Paris', |
| 234 ]; | 234 ]; |
| 235 overrideBookmarksSearch(SEARCH_RESULTS); | 235 overrideBookmarksSearch(SEARCH_RESULTS); |
| 236 var prevFolder = store.idToNodeMap_[store.selectedId]; | |
| 236 | 237 |
| 237 // Search for a non-empty string. | 238 // Search for a non-empty string. |
| 238 store.searchTerm = 'a'; | 239 store.searchTerm = 'a'; |
| 239 assertFalse(store.rootNode.children[0].isSelected); | 240 assertFalse(prevFolder.isSelected); |
| 240 assertEquals(null, store.selectedId); | 241 assertEquals(prevFolder.id, store.selectedId); |
| 241 assertEquals(SEARCH_RESULTS, store.displayedList); | 242 assertEquals(SEARCH_RESULTS, store.displayedList); |
| 242 | 243 |
| 243 // Clear the searchTerm. | 244 // Clearing search sets the displayed list to the previous folder. |
| 244 store.searchTerm = ''; | 245 store.searchTerm = ''; |
| 245 var defaultFolder = store.rootNode.children[0]; | 246 assertTrue(prevFolder.isSelected); |
| 246 assertTrue(defaultFolder.isSelected); | 247 assertEquals(prevFolder.id, store.selectedId); |
| 247 assertEquals(defaultFolder.id, store.selectedId); | 248 assertEquals(prevFolder.children, store.displayedList); |
| 248 assertEquals(defaultFolder.children, store.displayedList); | |
| 249 | 249 |
| 250 // Search with no bookmarks returned. | 250 // Search with no bookmarks returned. |
| 251 var EMPTY_RESULT = []; | 251 var EMPTY_RESULT = []; |
| 252 overrideBookmarksSearch(EMPTY_RESULT); | 252 overrideBookmarksSearch(EMPTY_RESULT); |
| 253 store.searchTerm = 'asdf'; | 253 store.searchTerm = 'asdf'; |
| 254 assertEquals(EMPTY_RESULT, store.displayedList); | 254 assertEquals(EMPTY_RESULT, store.displayedList); |
| 255 }); | 255 }); |
| 256 | 256 |
| 257 ////////////////////////////////////////////////////////////////////////////// | 257 ////////////////////////////////////////////////////////////////////////////// |
| 258 // router tests: | 258 // router tests: |
| 259 | 259 |
| 260 test('search updates from route', function() { | 260 test('search updates from route', function() { |
| 261 overrideBookmarksSearch([]); | 261 overrideBookmarksSearch([]); |
| 262 searchTerm = 'Pond'; | 262 searchTerm = 'Pond'; |
| 263 navigateTo('/?q=' + searchTerm); | 263 navigateTo('/?q=' + searchTerm); |
| 264 assertEquals(searchTerm, store.searchTerm); | 264 assertEquals(searchTerm, store.searchTerm); |
| 265 }); | 265 }); |
| 266 | 266 |
| 267 test('search updates from route on setup', function() { | 267 test('search updates from route on setup', function() { |
| 268 overrideBookmarksSearch([]); | 268 overrideBookmarksSearch([]); |
| 269 var searchTerm = 'Boat24'; | 269 var searchTerm = 'Boat24'; |
| 270 navigateTo('/?q=' + searchTerm); | 270 navigateTo('/?q=' + searchTerm); |
| 271 replaceStore(); | 271 replaceStore(); |
| 272 assertEquals(searchTerm, store.searchTerm); | 272 assertEquals(searchTerm, store.searchTerm); |
| 273 }); | 273 }); |
| 274 | 274 |
| 275 test('route updates from search', function() { | 275 test('route updates from search', function() { |
| 276 overrideBookmarksSearch([]); | 276 overrideBookmarksSearch([]); |
| 277 var prevFolderId = '3'; | |
| 278 store.fire('selected-folder-changed', prevFolderId); | |
| 279 | |
| 280 // Searching sets the previous folder and searchTerm as the URL parameters. | |
|
tsergeant
2017/01/25 00:23:18
You should also test the opposite direction: If I
angelayang
2017/01/31 02:25:03
Okay i placed those in the 'search updates from ro
| |
| 277 var searchTerm = 'Boat24'; | 281 var searchTerm = 'Boat24'; |
| 278 store.searchTerm = searchTerm; | 282 store.searchTerm = searchTerm; |
| 279 assertEquals('chrome://bookmarks/?q=' + searchTerm, window.location.href); | 283 assertEquals( |
| 284 'chrome://bookmarks/?id=' + prevFolderId + '&q=' + searchTerm, | |
| 285 window.location.href); | |
| 286 | |
| 287 // Search parameter is removed from the URL when search is cleared. | |
| 288 searchTerm = ''; | |
| 289 store.searchTerm = searchTerm; | |
| 290 assertEquals( | |
| 291 'chrome://bookmarks/?id=' + prevFolderId, window.location.href); | |
| 280 }); | 292 }); |
| 281 | 293 |
| 282 test('selectedId updates from route', function() { | 294 test('selectedId updates from route', function() { |
| 283 // Folder id routes to the corresponding folder. | 295 // Folder id routes to the corresponding folder. |
| 284 var selectedId = '3'; | 296 var selectedId = '3'; |
| 285 navigateTo('/?id=' + selectedId); | 297 navigateTo('/?id=' + selectedId); |
| 286 assertEquals(selectedId, store.selectedId); | 298 assertEquals(selectedId, store.selectedId); |
| 287 | 299 |
| 288 // Bookmark id routes to the default Bookmarks Bar. | 300 // Bookmark id routes to the default Bookmarks Bar. |
| 289 var selectedId = '2'; | 301 var selectedId = '2'; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 302 replaceStore(); | 314 replaceStore(); |
| 303 assertEquals(selectedId, store.selectedId); | 315 assertEquals(selectedId, store.selectedId); |
| 304 }); | 316 }); |
| 305 | 317 |
| 306 test('route updates from selectedId', function() { | 318 test('route updates from selectedId', function() { |
| 307 var selectedId = '2'; | 319 var selectedId = '2'; |
| 308 store.selectedId = selectedId; | 320 store.selectedId = selectedId; |
| 309 assertEquals('chrome://bookmarks/?id=' + selectedId, window.location.href); | 321 assertEquals('chrome://bookmarks/?id=' + selectedId, window.location.href); |
| 310 }); | 322 }); |
| 311 }); | 323 }); |
| OLD | NEW |