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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 '8': 'rootNode.children.#3', | 86 '8': 'rootNode.children.#3', |
87 }; | 87 }; |
88 | 88 |
89 for (var id in store.idToNodeMap_) | 89 for (var id in store.idToNodeMap_) |
90 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | 90 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); |
91 }); | 91 }); |
92 | 92 |
93 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
94 // editing bookmarks tree tests: | 94 // editing bookmarks tree tests: |
95 | 95 |
96 test('changing selectedId changes the displayedList', function() { | |
97 store.selectedId = '0'; | |
98 assertEquals(TEST_TREE.children, store.displayedList); | |
99 store.selectedId = '1'; | |
100 assertEquals(TEST_TREE.children[0].children, store.displayedList); | |
101 store.selectedId = '3'; | |
102 assertEquals( | |
103 TEST_TREE.children[0].children[1].children, store.displayedList); | |
104 | |
105 // Selecting an item selects the default folder. | |
106 store.selectedId = '5'; | |
107 assertEquals(TEST_TREE.children[0].children, store.displayedList); | |
108 }); | |
109 | |
110 test('store updates on selected event', function() { | 96 test('store updates on selected event', function() { |
111 // First child of root is selected by default. | 97 // First child of root is selected by default. |
112 assertEquals('1', store.selectedId); | 98 assertEquals('1', store.selectedId); |
113 assertTrue(store.idToNodeMap_['1'].isSelectedFolder); | 99 assertTrue(store.idToNodeMap_['1'].isSelectedFolder); |
114 | 100 |
115 // Selecting a selected folder doesn't deselect it. | 101 // Selecting a selected folder doesn't deselect it. |
116 store.fire('selected-folder-changed', '1'); | 102 store.fire('selected-folder-changed', '1'); |
117 assertEquals('1', store.selectedId); | 103 assertEquals('1', store.selectedId); |
118 assertTrue(store.idToNodeMap_['1'].isSelectedFolder); | 104 assertTrue(store.idToNodeMap_['1'].isSelectedFolder); |
119 | 105 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 assertEquals(defaultFolder.id, store.selectedId); | 277 assertEquals(defaultFolder.id, store.selectedId); |
292 assertEquals(defaultFolder.children, store.displayedList); | 278 assertEquals(defaultFolder.children, store.displayedList); |
293 | 279 |
294 // Search with no bookmarks returned. | 280 // Search with no bookmarks returned. |
295 overrideBookmarksSearch([]); | 281 overrideBookmarksSearch([]); |
296 store.searchTerm = 'asdf'; | 282 store.searchTerm = 'asdf'; |
297 assertEquals(0, store.displayedList.length); | 283 assertEquals(0, store.displayedList.length); |
298 }); | 284 }); |
299 | 285 |
300 ////////////////////////////////////////////////////////////////////////////// | 286 ////////////////////////////////////////////////////////////////////////////// |
301 // router tests: | |
302 | |
303 test('search updates from route', function() { | |
304 overrideBookmarksSearch([]); | |
305 searchTerm = 'Pond'; | |
306 navigateTo('/?q=' + searchTerm); | |
307 assertEquals(searchTerm, store.searchTerm); | |
308 }); | |
309 | |
310 test('search updates from route on setup', function() { | |
311 overrideBookmarksSearch([]); | |
312 var searchTerm = 'Boat24'; | |
313 navigateTo('/?q=' + searchTerm); | |
314 replaceStore(); | |
315 assertEquals(searchTerm, store.searchTerm); | |
316 }); | |
317 | |
318 test('route updates from search', function() { | |
319 overrideBookmarksSearch([]); | |
320 var searchTerm = 'Boat24'; | |
321 store.searchTerm = searchTerm; | |
322 assertEquals('chrome://bookmarks/?q=' + searchTerm, window.location.href); | |
323 }); | |
324 | |
325 test('selectedId updates from route', function() { | |
326 // Folder id routes to the corresponding folder. | |
327 var selectedId = '3'; | |
328 navigateTo('/?id=' + selectedId); | |
329 assertEquals(selectedId, store.selectedId); | |
330 | |
331 // Bookmark id routes to the default Bookmarks Bar. | |
332 var selectedId = '2'; | |
333 navigateTo('/?id=' + selectedId); | |
334 assertEquals(store.rootNode.children[0].id, store.selectedId); | |
335 | |
336 // Invalid id routes to the default Bookmarks Bar. | |
337 selectedId = 'foo'; | |
338 navigateTo('/?id=' + selectedId); | |
339 assertEquals(store.rootNode.children[0].id, store.selectedId); | |
340 }); | |
341 | |
342 test('selectedId updates from route on setup', function() { | |
343 selectedId = '3'; | |
344 navigateTo('/?id=' + selectedId); | |
345 replaceStore(); | |
346 assertEquals(selectedId, store.selectedId); | |
347 }); | |
348 | |
349 test('route updates from selectedId', function() { | |
350 var selectedId = '2'; | |
351 store.selectedId = selectedId; | |
352 assertEquals('chrome://bookmarks/?id=' + selectedId, window.location.href); | |
353 }); | |
354 | |
355 ////////////////////////////////////////////////////////////////////////////// | |
356 // selection tests: | 287 // selection tests: |
357 | 288 |
358 test('single select selects the correct bookmark', function() { | 289 test('single select selects the correct bookmark', function() { |
359 for (var id in store.idToNodeMap_) | 290 for (var id in store.idToNodeMap_) |
360 assertFalse(store.idToNodeMap_[id].isSelectedItem); | 291 assertFalse(store.idToNodeMap_[id].isSelectedItem); |
361 | 292 |
362 store.fire('select-item', {item: store.idToNodeMap_['2']}); | 293 store.fire('select-item', {item: store.idToNodeMap_['2']}); |
363 assertDeepEquals( | 294 assertDeepEquals( |
364 [true, false, false, false], | 295 [true, false, false, false], |
365 store.displayedList.map(i => i.isSelectedItem)); | 296 store.displayedList.map(i => i.isSelectedItem)); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 store.fire( | 433 store.fire( |
503 'select-item', {item: store.displayedList[2], add: true, range: false}); | 434 'select-item', {item: store.displayedList[2], add: true, range: false}); |
504 store.fire( | 435 store.fire( |
505 'select-item', {item: store.displayedList[4], add: true, range: true}); | 436 'select-item', {item: store.displayedList[4], add: true, range: true}); |
506 assertDeepEquals( | 437 assertDeepEquals( |
507 [true, false, true, true, true], | 438 [true, false, true, true, true], |
508 store.displayedList.map(i => i.isSelectedItem)); | 439 store.displayedList.map(i => i.isSelectedItem)); |
509 assertEquals(2, store.anchorIndex_); | 440 assertEquals(2, store.anchorIndex_); |
510 }); | 441 }); |
511 }); | 442 }); |
OLD | NEW |