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 id: '0', | 8 |
| 9 children: [ | 9 setup(function() { |
| 10 TEST_TREE = { | |
| 11 id: '0', | |
| 12 children: [ | |
| 10 { | 13 { |
| 11 id: '1', | 14 id: '1', |
| 12 children: [ | 15 children: [ |
| 13 {id: '2', url: 'link2'}, | 16 {id: '2', url: 'link2'}, |
| 14 {id: '3', children: []} | 17 {id: '3', children: []} |
| 15 ] | 18 ] |
| 16 }, | 19 }, |
| 17 {id: '4', url: 'link4'}, | 20 {id: '4', url: 'link4'}, |
| 18 {id: '5', url: 'link5'} | 21 {id: '5', url: 'link5'} |
| 19 ] | 22 ] |
| 20 }; | 23 }; |
| 21 | 24 |
| 22 setup(function() { | |
| 23 store = document.createElement('bookmarks-store'); | 25 store = document.createElement('bookmarks-store'); |
| 24 store.isTesting_ = true; | |
| 25 replaceBody(store); | 26 replaceBody(store); |
| 26 store.setupStore_(TEST_TREE); | 27 store.setupStore_(TEST_TREE); |
| 27 }); | 28 }); |
| 28 | 29 |
| 29 test('initNodes inserts nodes into idToNodeMap', function(){ | 30 test('initNodes inserts nodes into idToNodeMap', function(){ |
| 30 assertEquals(TEST_TREE, store.idToNodeMap_['0']); | 31 assertEquals(TEST_TREE, store.idToNodeMap_['0']); |
| 31 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); | 32 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); |
| 32 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']); | 33 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']); |
| 33 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']); | 34 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']); |
| 34 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); | 35 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 46 assertEquals(TEST_TREE.children[0].children[1], store.selectedNode); | 47 assertEquals(TEST_TREE.children[0].children[1], store.selectedNode); |
| 47 store.selectedId = '4'; | 48 store.selectedId = '4'; |
| 48 assertEquals(TEST_TREE.children[1], store.selectedNode); | 49 assertEquals(TEST_TREE.children[1], store.selectedNode); |
| 49 store.selectedId = '5'; | 50 store.selectedId = '5'; |
| 50 assertEquals(TEST_TREE.children[2], store.selectedNode); | 51 assertEquals(TEST_TREE.children[2], store.selectedNode); |
| 51 }); | 52 }); |
| 52 | 53 |
| 53 test('correct paths generated for nodes', function() { | 54 test('correct paths generated for nodes', function() { |
| 54 var TEST_PATHS = { | 55 var TEST_PATHS = { |
| 55 '0': 'rootNode', | 56 '0': 'rootNode', |
| 56 '1': 'rootNode.children.0', | 57 '1': 'rootNode.children.#0', |
| 57 '2': 'rootNode.children.0.children.0', | 58 '2': 'rootNode.children.#0.children.#0', |
| 58 '3': 'rootNode.children.0.children.1', | 59 '3': 'rootNode.children.#0.children.#1', |
| 59 '4': 'rootNode.children.1', | 60 '4': 'rootNode.children.#1', |
| 60 '5': 'rootNode.children.2', | 61 '5': 'rootNode.children.#2', |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 for (var id in store.idToNodeMap_) | 64 for (var id in store.idToNodeMap_) |
| 64 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | 65 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); |
| 65 }); | 66 }); |
| 66 | 67 |
| 67 test('store updates on selected event', function() { | 68 test('store updates on selected event', function() { |
| 68 // First child of root is selected by default. | 69 // First child of root is selected by default. |
| 69 assertEquals('1', store.selectedId); | 70 assertEquals('1', store.selectedId); |
| 70 assertTrue(store.idToNodeMap_['1'].isSelected); | 71 assertTrue(store.idToNodeMap_['1'].isSelected); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 store.fire('folder-open-changed', {id: '1', open: true}); | 104 store.fire('folder-open-changed', {id: '1', open: true}); |
| 104 | 105 |
| 105 // Closing an ancestor folder of a selected folder selects the ancestor. | 106 // Closing an ancestor folder of a selected folder selects the ancestor. |
| 106 store.fire('selected-folder-changed', '3'); | 107 store.fire('selected-folder-changed', '3'); |
| 107 store.fire('folder-open-changed', {id: '1', open: false}); | 108 store.fire('folder-open-changed', {id: '1', open: false}); |
| 108 assertFalse(store.idToNodeMap_['1'].isOpen); | 109 assertFalse(store.idToNodeMap_['1'].isOpen); |
| 109 assertEquals('1', store.selectedId); | 110 assertEquals('1', store.selectedId); |
| 110 assertTrue(store.idToNodeMap_['1'].isSelected); | 111 assertTrue(store.idToNodeMap_['1'].isSelected); |
| 111 assertFalse(store.idToNodeMap_['3'].isSelected); | 112 assertFalse(store.idToNodeMap_['3'].isSelected); |
| 112 }); | 113 }); |
| 114 | |
| 115 test('deleting a node updates the tree', function() { | |
| 116 // Remove an empty folder/bookmark. | |
| 117 store.onBookmarkRemoved_('4', {parentId: '0', index: '1'}); | |
| 118 | |
| 119 // Check the tree is correct. | |
| 120 assertEquals('5', store.rootNode.children[1].id); | |
| 121 | |
| 122 // idToNodeMap_ has been updated. | |
| 123 assertEquals(undefined, store.idToNodeMap_['4']); | |
| 124 assertEquals(store.rootNode.children[1], store.idToNodeMap_['5']); | |
| 125 | |
| 126 // paths have been updated. | |
|
calamity
2017/01/04 06:57:44
Capitalization.
jiaxi
2017/01/04 22:44:01
Done.
| |
| 127 var TEST_PATHS = { | |
| 128 '0': 'rootNode', | |
| 129 '1': 'rootNode.children.#0', | |
| 130 '2': 'rootNode.children.#0.children.#0', | |
| 131 '3': 'rootNode.children.#0.children.#1', | |
| 132 '5': 'rootNode.children.#1', | |
| 133 }; | |
| 134 | |
| 135 for (var id in store.idToNodeMap_) | |
| 136 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | |
| 137 | |
| 138 // Remove a folder with children. | |
| 139 store.onBookmarkRemoved_('1', {parentId: '0', index: '0'}); | |
| 140 | |
| 141 // Check the tree is correct. | |
| 142 assertEquals('5', store.rootNode.children[0].id); | |
| 143 | |
| 144 // idToNodeMap_ has been updated. | |
| 145 assertEquals(undefined, store.idToNodeMap_['1']); | |
| 146 assertEquals(undefined, store.idToNodeMap_['2']); | |
| 147 assertEquals(undefined, store.idToNodeMap_['3']); | |
| 148 assertEquals(undefined, store.idToNodeMap_['4']); | |
| 149 assertEquals(store.rootNode.children[0], store.idToNodeMap_['5']); | |
| 150 | |
| 151 // paths have been updated. | |
|
calamity
2017/01/04 06:57:44
Capitalization.
jiaxi
2017/01/04 22:44:01
Done.
| |
| 152 TEST_PATHS = { | |
| 153 '0': 'rootNode', | |
| 154 '5': 'rootNode.children.#0', | |
| 155 }; | |
| 156 | |
| 157 for (var id in store.idToNodeMap_) | |
| 158 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | |
| 159 }); | |
| 160 | |
| 161 test('selectedId updates after removing a selected folder', function() { | |
| 162 // Selected folder gets removed. | |
| 163 store.selectedId = '2'; | |
| 164 store.onBookmarkRemoved_('2', {parentId:'1', index:'0'}); | |
| 165 assertTrue(store.idToNodeMap_['1'].isSelected); | |
| 166 assertEquals('1', store.selectedId); | |
| 167 | |
| 168 // A folder with selected folder in it gets removed. | |
| 169 store.selectedId = '3'; | |
| 170 store.onBookmarkRemoved_('1', {parentId:'0', index:'0'}); | |
| 171 assertTrue(store.idToNodeMap_['0'].isSelected); | |
| 172 assertEquals('0', store.selectedId); | |
| 173 }); | |
| 113 }); | 174 }); |
| OLD | NEW |