| 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'); |
| 11 replaceBody(store); | 11 replaceBody(store); |
| 12 store.setupStore_(TEST_TREE); | 12 store.setupStore_(TEST_TREE); |
| 13 } | 13 } |
| 14 | 14 |
| 15 function navigateTo(route) { | 15 function navigateTo(route) { |
| 16 window.history.replaceState({}, '', route); | 16 window.history.replaceState({}, '', route); |
| 17 window.dispatchEvent(new CustomEvent('location-changed')); | 17 window.dispatchEvent(new CustomEvent('location-changed')); |
| 18 } | 18 } |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Overrides the chrome.bookmarks.search to pass results into the callback. | 21 * Overrides the chrome.bookmarks.search to pass results into the callback. |
| 22 * @param {Array} results | 22 * @param {Array} results |
| 23 */ | 23 */ |
| 24 function overrideBookmarksSearch(results) { | 24 function overrideBookmarksSearch(results) { |
| 25 chrome.bookmarks.search = function(searchTerm, callback) { | 25 chrome.bookmarks.search = function(searchTerm, callback) { |
| 26 callback(results); | 26 callback(results); |
| 27 }; | 27 }; |
| 28 } | 28 } |
| 29 | 29 |
| 30 /** |
| 31 * Overrides the chrome.bookmarks.getSubTree to pass results into the |
| 32 * callback. |
| 33 * @param {Array} results |
| 34 */ |
| 35 function overrideBookmarksGetSubTree(results) { |
| 36 chrome.bookmarks.getSubTree = function(parentId, callback) { |
| 37 callback(results); |
| 38 }; |
| 39 } |
| 40 |
| 30 setup(function() { | 41 setup(function() { |
| 31 TEST_TREE = createFolder('0', [ | 42 TEST_TREE = createFolder('0', [ |
| 32 createFolder( | 43 createFolder( |
| 33 '1', | 44 '1', |
| 34 [ | 45 [ |
| 35 createItem('2', {url: 'link2'}), | 46 createItem('2', {url: 'link2'}), |
| 36 createFolder('3', []), | 47 createFolder('3', []), |
| 48 createItem('6', {url: 'link4'}), |
| 49 createItem('7', {url: 'link5'}), |
| 37 ]), | 50 ]), |
| 38 createItem('4', {url: 'link4'}), | 51 createItem('4', {url: 'link4'}), |
| 39 createItem('5', {url: 'link5'}), | 52 createItem('5', {url: 'link5'}), |
| 40 createFolder('6', []), | 53 createFolder('8', []), |
| 41 ]); | 54 ]); |
| 42 | 55 |
| 43 replaceStore(); | 56 replaceStore(); |
| 44 }); | 57 }); |
| 45 | 58 |
| 46 teardown(function() { | 59 teardown(function() { |
| 47 // Clean up anything left in URL. | 60 // Clean up anything left in URL. |
| 48 navigateTo('/'); | 61 navigateTo('/'); |
| 49 }); | 62 }); |
| 50 | 63 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 }); | 74 }); |
| 62 | 75 |
| 63 test('correct paths generated for nodes', function() { | 76 test('correct paths generated for nodes', function() { |
| 64 var TEST_PATHS = { | 77 var TEST_PATHS = { |
| 65 '0': 'rootNode', | 78 '0': 'rootNode', |
| 66 '1': 'rootNode.children.#0', | 79 '1': 'rootNode.children.#0', |
| 67 '2': 'rootNode.children.#0.children.#0', | 80 '2': 'rootNode.children.#0.children.#0', |
| 68 '3': 'rootNode.children.#0.children.#1', | 81 '3': 'rootNode.children.#0.children.#1', |
| 69 '4': 'rootNode.children.#1', | 82 '4': 'rootNode.children.#1', |
| 70 '5': 'rootNode.children.#2', | 83 '5': 'rootNode.children.#2', |
| 71 '6': 'rootNode.children.#3', | 84 '6': 'rootNode.children.#0.children.#2', |
| 85 '7': 'rootNode.children.#0.children.#3', |
| 86 '8': 'rootNode.children.#3', |
| 72 }; | 87 }; |
| 73 | 88 |
| 74 for (var id in store.idToNodeMap_) | 89 for (var id in store.idToNodeMap_) |
| 75 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | 90 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); |
| 76 }); | 91 }); |
| 77 | 92 |
| 78 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
| 79 // editing bookmarks tree tests: | 94 // editing bookmarks tree tests: |
| 80 | 95 |
| 81 test('changing selectedId changes the displayedList', function() { | 96 test('changing selectedId changes the displayedList', function() { |
| 82 store.selectedId = '0'; | 97 store.selectedId = '0'; |
| 83 assertEquals(TEST_TREE.children, store.displayedList); | 98 assertEquals(TEST_TREE.children, store.displayedList); |
| 84 store.selectedId = '1'; | 99 store.selectedId = '1'; |
| 85 assertEquals(TEST_TREE.children[0].children, store.displayedList); | 100 assertEquals(TEST_TREE.children[0].children, store.displayedList); |
| 86 store.selectedId = '3'; | 101 store.selectedId = '3'; |
| 87 assertEquals( | 102 assertEquals( |
| 88 TEST_TREE.children[0].children[1].children, store.displayedList); | 103 TEST_TREE.children[0].children[1].children, store.displayedList); |
| 89 | 104 |
| 90 // Selecting an item selects the default folder. | 105 // Selecting an item selects the default folder. |
| 91 store.selectedId = '5'; | 106 store.selectedId = '5'; |
| 92 assertEquals(TEST_TREE.children[0].children, store.displayedList); | 107 assertEquals(TEST_TREE.children[0].children, store.displayedList); |
| 93 }); | 108 }); |
| 94 | 109 |
| 95 test('store updates on selected event', function() { | 110 test('store updates on selected event', function() { |
| 96 // First child of root is selected by default. | 111 // First child of root is selected by default. |
| 97 assertEquals('1', store.selectedId); | 112 assertEquals('1', store.selectedId); |
| 98 assertTrue(store.idToNodeMap_['1'].isSelected); | 113 assertTrue(store.idToNodeMap_['1'].isSelectedFolder); |
| 99 | 114 |
| 100 // Selecting a selected folder doesn't deselect it. | 115 // Selecting a selected folder doesn't deselect it. |
| 101 store.fire('selected-folder-changed', '1'); | 116 store.fire('selected-folder-changed', '1'); |
| 102 assertEquals('1', store.selectedId); | 117 assertEquals('1', store.selectedId); |
| 103 assertTrue(store.idToNodeMap_['1'].isSelected); | 118 assertTrue(store.idToNodeMap_['1'].isSelectedFolder); |
| 104 | 119 |
| 105 // Select a deeply nested descendant. | 120 // Select a deeply nested descendant. |
| 106 store.fire('selected-folder-changed', '3'); | 121 store.fire('selected-folder-changed', '3'); |
| 107 assertEquals('3', store.selectedId); | 122 assertEquals('3', store.selectedId); |
| 108 assertTrue(store.idToNodeMap_['3'].isSelected); | 123 assertTrue(store.idToNodeMap_['3'].isSelectedFolder); |
| 109 assertFalse(store.idToNodeMap_['1'].isSelected); | 124 assertFalse(store.idToNodeMap_['1'].isSelectedFolder); |
| 110 | 125 |
| 111 // Select a folder in separate subtree. | 126 // Select a folder in separate subtree. |
| 112 store.fire('selected-folder-changed', '6'); | 127 store.fire('selected-folder-changed', '8'); |
| 113 assertEquals('6', store.selectedId); | 128 assertEquals('8', store.selectedId); |
| 114 assertTrue(store.idToNodeMap_['6'].isSelected); | 129 assertTrue(store.idToNodeMap_['8'].isSelectedFolder); |
| 115 assertFalse(store.idToNodeMap_['3'].isSelected); | 130 assertFalse(store.idToNodeMap_['3'].isSelectedFolder); |
| 116 }); | 131 }); |
| 117 | 132 |
| 118 test('store updates on open and close', function() { | 133 test('store updates on open and close', function() { |
| 119 // All folders are open by default. | 134 // All folders are open by default. |
| 120 for (var id in store.idToNodeMap_) { | 135 for (var id in store.idToNodeMap_) { |
| 121 if (store.idToNodeMap_[id].url) | 136 if (store.idToNodeMap_[id].url) |
| 122 continue; | 137 continue; |
| 123 | 138 |
| 124 assertTrue(store.idToNodeMap_[id].isOpen); | 139 assertTrue(store.idToNodeMap_[id].isOpen); |
| 125 } | 140 } |
| 126 | 141 |
| 127 // Closing a folder doesn't close any descendants. | 142 // Closing a folder doesn't close any descendants. |
| 128 store.fire('folder-open-changed', {id: '1', open: false}); | 143 store.fire('folder-open-changed', {id: '1', open: false}); |
| 129 assertFalse(store.idToNodeMap_['1'].isOpen); | 144 assertFalse(store.idToNodeMap_['1'].isOpen); |
| 130 assertTrue(store.idToNodeMap_['3'].isOpen); | 145 assertTrue(store.idToNodeMap_['3'].isOpen); |
| 131 store.fire('folder-open-changed', {id: '1', open: true}); | 146 store.fire('folder-open-changed', {id: '1', open: true}); |
| 132 | 147 |
| 133 // Closing an ancestor folder of a selected folder selects the ancestor. | 148 // Closing an ancestor folder of a selected folder selects the ancestor. |
| 134 store.fire('selected-folder-changed', '3'); | 149 store.fire('selected-folder-changed', '3'); |
| 135 store.fire('folder-open-changed', {id: '1', open: false}); | 150 store.fire('folder-open-changed', {id: '1', open: false}); |
| 136 assertFalse(store.idToNodeMap_['1'].isOpen); | 151 assertFalse(store.idToNodeMap_['1'].isOpen); |
| 137 assertEquals('1', store.selectedId); | 152 assertEquals('1', store.selectedId); |
| 138 assertTrue(store.idToNodeMap_['1'].isSelected); | 153 assertTrue(store.idToNodeMap_['1'].isSelectedFolder); |
| 139 assertFalse(store.idToNodeMap_['3'].isSelected); | 154 assertFalse(store.idToNodeMap_['3'].isSelectedFolder); |
| 140 }); | 155 }); |
| 141 | 156 |
| 142 test('deleting a node updates the tree', function() { | 157 test('deleting a node updates the tree', function() { |
| 158 TEST_TREE.children.splice(1, 1); |
| 159 overrideBookmarksGetSubTree([TEST_TREE]); |
| 143 // Remove an empty folder/bookmark. | 160 // Remove an empty folder/bookmark. |
| 144 store.onBookmarkRemoved_('4', {parentId: '0', index: '1'}); | 161 store.onBookmarkRemoved_('4', {parentId: '0', index: 1}); |
| 145 | 162 |
| 146 // Check the tree is correct. | 163 // Check the tree is correct. |
| 147 assertEquals('5', store.rootNode.children[1].id); | 164 assertEquals('5', store.rootNode.children[1].id); |
| 148 | 165 |
| 149 // idToNodeMap_ has been updated. | 166 // idToNodeMap_ has been updated. |
| 150 assertEquals(undefined, store.idToNodeMap_['4']); | 167 assertEquals(undefined, store.idToNodeMap_['4']); |
| 151 assertEquals(store.rootNode.children[1], store.idToNodeMap_['5']); | 168 assertEquals(store.rootNode.children[1], store.idToNodeMap_['5']); |
| 152 | 169 |
| 153 // Paths have been updated. | 170 // Paths have been updated. |
| 154 var TEST_PATHS = { | 171 var TEST_PATHS = { |
| 155 '0': 'rootNode', | 172 '0': 'rootNode', |
| 156 '1': 'rootNode.children.#0', | 173 '1': 'rootNode.children.#0', |
| 157 '2': 'rootNode.children.#0.children.#0', | 174 '2': 'rootNode.children.#0.children.#0', |
| 158 '3': 'rootNode.children.#0.children.#1', | 175 '3': 'rootNode.children.#0.children.#1', |
| 159 '5': 'rootNode.children.#1', | 176 '5': 'rootNode.children.#1', |
| 160 '6': 'rootNode.children.#2', | 177 '6': 'rootNode.children.#0.children.#2', |
| 178 '7': 'rootNode.children.#0.children.#3', |
| 179 '8': 'rootNode.children.#2', |
| 161 }; | 180 }; |
| 162 | 181 |
| 163 for (var id in store.idToNodeMap_) | 182 for (var id in store.idToNodeMap_) |
| 164 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | 183 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); |
| 165 | 184 |
| 166 // Remove a folder with children. | 185 // Remove a folder with children. |
| 186 TEST_TREE.children.splice(0, 1); |
| 187 overrideBookmarksGetSubTree([TEST_TREE]); |
| 188 |
| 167 store.onBookmarkRemoved_('1', {parentId: '0', index: '0'}); | 189 store.onBookmarkRemoved_('1', {parentId: '0', index: '0'}); |
| 168 | 190 |
| 169 // Check the tree is correct. | 191 // Check the tree is correct. |
| 170 assertEquals('5', store.rootNode.children[0].id); | 192 assertEquals('5', store.rootNode.children[0].id); |
| 171 assertEquals('6', store.rootNode.children[1].id); | 193 assertEquals('8', store.rootNode.children[1].id); |
| 172 | 194 |
| 173 // idToNodeMap_ has been updated. | 195 // idToNodeMap_ has been updated. |
| 174 assertEquals(undefined, store.idToNodeMap_['1']); | 196 assertEquals(undefined, store.idToNodeMap_['1']); |
| 175 assertEquals(undefined, store.idToNodeMap_['2']); | 197 assertEquals(undefined, store.idToNodeMap_['2']); |
| 176 assertEquals(undefined, store.idToNodeMap_['3']); | 198 assertEquals(undefined, store.idToNodeMap_['3']); |
| 177 assertEquals(undefined, store.idToNodeMap_['4']); | 199 assertEquals(undefined, store.idToNodeMap_['4']); |
| 178 assertEquals(store.rootNode.children[0], store.idToNodeMap_['5']); | 200 assertEquals(store.rootNode.children[0], store.idToNodeMap_['5']); |
| 179 assertEquals(store.rootNode.children[1], store.idToNodeMap_['6']); | 201 assertEquals(store.rootNode.children[1], store.idToNodeMap_['8']); |
| 180 | 202 |
| 181 // Paths have been updated. | 203 // Paths have been updated. |
| 182 TEST_PATHS = { | 204 TEST_PATHS = { |
| 183 '0': 'rootNode', | 205 '0': 'rootNode', |
| 184 '5': 'rootNode.children.#0', | 206 '5': 'rootNode.children.#0', |
| 185 '6': 'rootNode.children.#1' | 207 '8': 'rootNode.children.#1' |
| 186 }; | 208 }; |
| 187 | 209 |
| 188 for (var id in store.idToNodeMap_) | 210 for (var id in store.idToNodeMap_) |
| 189 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | 211 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); |
| 190 }); | 212 }); |
| 191 | 213 |
| 192 test('selectedId updates after removing a selected folder', function() { | 214 test('selectedId updates after removing a selected folder', function() { |
| 193 // Selected folder gets removed. | 215 // Selected folder gets removed. |
| 194 store.selectedId = '2'; | 216 store.selectedId = '8'; |
| 195 store.onBookmarkRemoved_('2', {parentId: '1', index: '0'}); | 217 TEST_TREE.children.splice(3, 1); |
| 196 assertTrue(store.idToNodeMap_['1'].isSelected); | 218 overrideBookmarksGetSubTree([TEST_TREE]); |
| 197 assertEquals('1', store.selectedId); | 219 |
| 220 store.onBookmarkRemoved_('8', {parentId:'0', index:'3'}); |
| 221 assertTrue(store.idToNodeMap_['0'].isSelectedFolder); |
| 222 assertEquals('0', store.selectedId); |
| 198 | 223 |
| 199 // A folder with selected folder in it gets removed. | 224 // A folder with selected folder in it gets removed. |
| 225 TEST_TREE.children.splice(0, 1); |
| 226 overrideBookmarksGetSubTree([TEST_TREE]); |
| 227 |
| 200 store.selectedId = '3'; | 228 store.selectedId = '3'; |
| 201 store.onBookmarkRemoved_('1', {parentId: '0', index: '0'}); | 229 store.onBookmarkRemoved_('1', {parentId:'0', index:'0'}); |
| 202 assertTrue(store.idToNodeMap_['0'].isSelected); | 230 assertTrue(store.idToNodeMap_['0'].isSelectedFolder); |
| 203 assertEquals('0', store.selectedId); | 231 assertEquals('0', store.selectedId); |
| 204 }); | 232 }); |
| 205 | 233 |
| 206 test('bookmark gets updated after editing', function() { | 234 test('bookmark gets updated after editing', function() { |
| 207 // Edit title updates idToNodeMap_ properly. | 235 // Edit title updates idToNodeMap_ properly. |
| 208 store.onBookmarkChanged_('4', {'title': 'test'}); | 236 store.onBookmarkChanged_('4', {'title': 'test'}); |
| 209 assertEquals('test', store.idToNodeMap_['4'].title); | 237 assertEquals('test', store.idToNodeMap_['4'].title); |
| 210 assertEquals('link4', store.idToNodeMap_['4'].url); | 238 assertEquals('link4', store.idToNodeMap_['4'].url); |
| 211 | 239 |
| 212 // Edit url updates idToNodeMap_ properly. | 240 // Edit url updates idToNodeMap_ properly. |
| 213 store.onBookmarkChanged_('5', {'url': 'http://www.google.com'}); | 241 store.onBookmarkChanged_('5', {'url': 'http://www.google.com'}); |
| 214 assertEquals('', store.idToNodeMap_['5'].title); | 242 assertEquals('', store.idToNodeMap_['5'].title); |
| 215 assertEquals('http://www.google.com', store.idToNodeMap_['5'].url); | 243 assertEquals('http://www.google.com', store.idToNodeMap_['5'].url); |
| 216 | 244 |
| 217 // Edit url and title updates idToNodeMap_ properly. | 245 // Edit url and title updates idToNodeMap_ properly. |
| 218 store.onBookmarkChanged_('2', { | 246 store.onBookmarkChanged_('2', { |
| 219 'title': 'test', | 247 'title': 'test', |
| 220 'url': 'http://www.google.com', | 248 'url': 'http://www.google.com', |
| 221 }); | 249 }); |
| 222 assertEquals('test', store.idToNodeMap_['2'].title); | 250 assertEquals('test', store.idToNodeMap_['2'].title); |
| 223 assertEquals('http://www.google.com', store.idToNodeMap_['2'].url); | 251 assertEquals('http://www.google.com', store.idToNodeMap_['2'].url); |
| 224 }); | 252 }); |
| 225 | 253 |
| 226 ////////////////////////////////////////////////////////////////////////////// | 254 ////////////////////////////////////////////////////////////////////////////// |
| 227 // search tests: | 255 // search tests: |
| 228 | 256 |
| 229 test('displayedList updates after searchTerm changes', function() { | 257 test('displayedList updates after searchTerm changes', function() { |
| 230 var SEARCH_RESULTS = [ | 258 var SEARCH_RESULTS = [ |
| 231 'cat', | 259 createItem('1', {title: 'cat'}), |
| 232 'apple', | 260 createItem('2', {title: 'apple'}), |
| 233 'Paris', | 261 createItem('3', {title: 'paris'}), |
| 234 ]; | 262 ]; |
| 235 overrideBookmarksSearch(SEARCH_RESULTS); | 263 overrideBookmarksSearch(SEARCH_RESULTS); |
| 236 | 264 |
| 237 // Search for a non-empty string. | 265 // Search for a non-empty string. |
| 238 store.searchTerm = 'a'; | 266 store.searchTerm = 'a'; |
| 239 assertFalse(store.rootNode.children[0].isSelected); | 267 assertFalse(store.rootNode.children[0].isSelectedFolder); |
| 240 assertEquals(null, store.selectedId); | 268 assertEquals(null, store.selectedId); |
| 241 assertEquals(SEARCH_RESULTS, store.displayedList); | 269 assertEquals(SEARCH_RESULTS, store.displayedList); |
| 242 | 270 |
| 243 // Clear the searchTerm. | 271 // Clear the searchTerm. |
| 244 store.searchTerm = ''; | 272 store.searchTerm = ''; |
| 245 var defaultFolder = store.rootNode.children[0]; | 273 var defaultFolder = store.rootNode.children[0]; |
| 246 assertTrue(defaultFolder.isSelected); | 274 assertTrue(defaultFolder.isSelectedFolder); |
| 247 assertEquals(defaultFolder.id, store.selectedId); | 275 assertEquals(defaultFolder.id, store.selectedId); |
| 248 assertEquals(defaultFolder.children, store.displayedList); | 276 assertEquals(defaultFolder.children, store.displayedList); |
| 249 | 277 |
| 250 // Search with no bookmarks returned. | 278 // Search with no bookmarks returned. |
| 251 var EMPTY_RESULT = []; | 279 overrideBookmarksSearch([]); |
| 252 overrideBookmarksSearch(EMPTY_RESULT); | |
| 253 store.searchTerm = 'asdf'; | 280 store.searchTerm = 'asdf'; |
| 254 assertEquals(EMPTY_RESULT, store.displayedList); | 281 assertEquals(0, store.displayedList.length); |
| 255 }); | 282 }); |
| 256 | 283 |
| 257 ////////////////////////////////////////////////////////////////////////////// | 284 ////////////////////////////////////////////////////////////////////////////// |
| 258 // router tests: | 285 // router tests: |
| 259 | 286 |
| 260 test('search updates from route', function() { | 287 test('search updates from route', function() { |
| 261 overrideBookmarksSearch([]); | 288 overrideBookmarksSearch([]); |
| 262 searchTerm = 'Pond'; | 289 searchTerm = 'Pond'; |
| 263 navigateTo('/?q=' + searchTerm); | 290 navigateTo('/?q=' + searchTerm); |
| 264 assertEquals(searchTerm, store.searchTerm); | 291 assertEquals(searchTerm, store.searchTerm); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 navigateTo('/?id=' + selectedId); | 328 navigateTo('/?id=' + selectedId); |
| 302 replaceStore(); | 329 replaceStore(); |
| 303 assertEquals(selectedId, store.selectedId); | 330 assertEquals(selectedId, store.selectedId); |
| 304 }); | 331 }); |
| 305 | 332 |
| 306 test('route updates from selectedId', function() { | 333 test('route updates from selectedId', function() { |
| 307 var selectedId = '2'; | 334 var selectedId = '2'; |
| 308 store.selectedId = selectedId; | 335 store.selectedId = selectedId; |
| 309 assertEquals('chrome://bookmarks/?id=' + selectedId, window.location.href); | 336 assertEquals('chrome://bookmarks/?id=' + selectedId, window.location.href); |
| 310 }); | 337 }); |
| 338 |
| 339 ////////////////////////////////////////////////////////////////////////////// |
| 340 // selection tests: |
| 341 |
| 342 test('single select selects the correct bookmark', function() { |
| 343 for (var id in store.idToNodeMap_) |
| 344 assertFalse(store.idToNodeMap_[id].isSelectedItem); |
| 345 |
| 346 store.fire('select-item', {item: store.idToNodeMap_['2']}); |
| 347 assertDeepEquals( |
| 348 [true, false, false, false], |
| 349 store.displayedList.map(i => i.isSelectedItem)); |
| 350 assertEquals(0, store.anchorIndex_); |
| 351 |
| 352 // Select other item will remove the previous selection. |
| 353 store.fire('select-item', {item: store.idToNodeMap_['3']}); |
| 354 assertDeepEquals( |
| 355 [false, true, false, false], |
| 356 store.displayedList.map(i => i.isSelectedItem)); |
| 357 assertEquals(1, store.anchorIndex_); |
| 358 |
| 359 // Changing the selected folder will remove the select status of the |
| 360 // bookmark. |
| 361 store.selectedId = '3'; |
| 362 assertDeepEquals( |
| 363 [false, false, false, false], |
| 364 store.idToNodeMap_['1'].children.map(i => i.isSelectedItem)); |
| 365 assertEquals(null, store.anchorIndex_); |
| 366 |
| 367 // Delete the selected item will unselect everything. |
| 368 store.selectedId = '1'; |
| 369 store.fire('select-item', {item: store.idToNodeMap_['2']}); |
| 370 TEST_TREE.children[0].children.splice(0, 1); |
| 371 overrideBookmarksGetSubTree([TEST_TREE.children[0]]); |
| 372 store.onBookmarkRemoved_('2', {parentId: '1', index: 0}); |
| 373 assertDeepEquals( |
| 374 [false, false, false], |
| 375 store.displayedList.map(i => i.isSelectedItem)); |
| 376 assertEquals(null, store.anchorIndex_); |
| 377 }); |
| 378 |
| 379 test('shift select selects the correct bookmarks', function() { |
| 380 // When nothing has been selected, it selects a single item. |
| 381 assertEquals(null, store.anchorIndex_); |
| 382 store.fire('select-item', {item: store.idToNodeMap_['6'], range: true}); |
| 383 assertDeepEquals( |
| 384 [false, false, true, false], |
| 385 store.displayedList.map(i => i.isSelectedItem)); |
| 386 assertEquals(2, store.anchorIndex_); |
| 387 |
| 388 // Select an item below the previous selected item. |
| 389 store.fire('select-item', {item: store.idToNodeMap_['7'], range: true}); |
| 390 assertEquals(2, store.anchorIndex_); |
| 391 assertDeepEquals( |
| 392 [false, false, true, true], |
| 393 store.displayedList.map(i => i.isSelectedItem)); |
| 394 |
| 395 // Select an item above the previous selected item. |
| 396 store.fire('select-item', {item: store.idToNodeMap_['2'], range: true}); |
| 397 assertEquals(2, store.anchorIndex_); |
| 398 assertDeepEquals( |
| 399 [true, true, true, false], |
| 400 store.displayedList.map(i => i.isSelectedItem)); |
| 401 }); |
| 402 |
| 403 test('ctrl select selects the correct bookmarks', function() { |
| 404 // When nothing has been selected, it selects a single item. |
| 405 assertEquals(null, store.anchorIndex_); |
| 406 store.fire('select-item', {item: store.idToNodeMap_['6'], add: true}); |
| 407 assertDeepEquals( |
| 408 [false, false, true, false], |
| 409 store.displayedList.map(i => i.isSelectedItem)); |
| 410 assertEquals(2, store.anchorIndex_); |
| 411 |
| 412 // Select a new item will not deselect the previous item, but will update |
| 413 // anchorIndex_. |
| 414 store.fire('select-item', {item: store.idToNodeMap_['2'], add: true}); |
| 415 assertDeepEquals( |
| 416 [true, false, true, false], |
| 417 store.displayedList.map(i => i.isSelectedItem)); |
| 418 assertEquals(0, store.anchorIndex_); |
| 419 }); |
| 420 |
| 421 |
| 422 test('shift + ctrl select selects the correct bookmarks', function() { |
| 423 store.fire('select-item', {item: store.displayedList[0]}); |
| 424 store.fire( |
| 425 'select-item', {item: store.displayedList[2], add: true, range: false}); |
| 426 store.fire( |
| 427 'select-item', {item: store.displayedList[3], add: true, range: true}); |
| 428 assertDeepEquals( |
| 429 [true, false, true, true], |
| 430 store.displayedList.map(i => i.isSelectedItem)); |
| 431 assertEquals(2, store.anchorIndex_); |
| 432 }); |
| 433 |
| 434 test('selection in search mode', function() { |
| 435 // Item gets unselected in search. |
| 436 overrideBookmarksSearch([ |
| 437 createItem('4', {url: 'link4'}), |
| 438 createItem('2', {url: 'link2'}), |
| 439 createItem('5', {url: 'link5'}), |
| 440 ]); |
| 441 |
| 442 store.selectedId = '1'; |
| 443 store.fire('select-item', {item: store.idToNodeMap_['3']}); |
| 444 store.searchTerm = 'a'; |
| 445 assertFalse(store.idToNodeMap_['3'].isSelectedItem); |
| 446 assertEquals(null, store.anchorIndex_); |
| 447 |
| 448 // anchorIndex_ gets updated properly in single select. |
| 449 store.fire('select-item', {item: store.displayedList[1]}); |
| 450 assertDeepEquals( |
| 451 [false, true, false], |
| 452 store.displayedList.map(i => i.isSelectedItem)); |
| 453 assertEquals(1, store.anchorIndex_); |
| 454 |
| 455 // anchorIndex_ gets updated properly in ctrl select. |
| 456 store.fire('select-item', {item: store.displayedList[0], add: true}); |
| 457 assertDeepEquals( |
| 458 [true, true, false], |
| 459 store.displayedList.map(i => i.isSelectedItem)); |
| 460 assertEquals(0, store.anchorIndex_); |
| 461 |
| 462 // Delete the selected item will unselect everything. |
| 463 store.fire('select-item', {item: store.displayedList[1]}); |
| 464 overrideBookmarksSearch([ |
| 465 createItem('4', {url: 'link4'}), |
| 466 createItem('5', {url: 'link5'}), |
| 467 ]); |
| 468 TEST_TREE.children[0].children.splice(0, 1); |
| 469 overrideBookmarksGetSubTree([TEST_TREE.children[0]]); |
| 470 |
| 471 store.onBookmarkRemoved_('2', {parentId: '1', index: 0}); |
| 472 assertDeepEquals( |
| 473 [false, false], |
| 474 store.displayedList.map(i => i.isSelectedItem)); |
| 475 assertEquals(null, store.anchorIndex_); |
| 476 |
| 477 // Shift+Ctrl select selects the right item. |
| 478 overrideBookmarksSearch([ |
| 479 createItem('4', {url: 'link4'}), |
| 480 createFolder('3', []), |
| 481 createItem('5', {url: 'link5'}), |
| 482 createItem('6', {url: 'link4'}), |
| 483 createItem('7', {url: 'link5'}), |
| 484 ]); |
| 485 store.searchTerm = 'b'; |
| 486 store.fire('select-item', {item: store.displayedList[0]}); |
| 487 store.fire( |
| 488 'select-item', {item: store.displayedList[2], add: true, range: false}); |
| 489 store.fire( |
| 490 'select-item', {item: store.displayedList[4], add: true, range: true}); |
| 491 assertDeepEquals( |
| 492 [true, false, true, true, true], |
| 493 store.displayedList.map(i => i.isSelectedItem)); |
| 494 assertEquals(2, store.anchorIndex_); |
| 495 }); |
| 311 }); | 496 }); |
| OLD | NEW |