Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 suite('<bookmarks-store>', function() { | |
| 6 var store; | |
| 7 var TEST_TREE = { | |
| 8 id: '0', | |
| 9 children: [ | |
| 10 { | |
| 11 id: '1', | |
| 12 children: [ | |
| 13 {id: '2', url: 'link2'}, | |
| 14 {id: '3', children: []} | |
| 15 ] | |
| 16 }, | |
| 17 {id: '4', url: 'link4'}, | |
| 18 {id: '5', url: 'link5'} | |
| 19 ] | |
| 20 }; | |
| 21 | |
| 22 setup(function() { | |
| 23 store = document.createElement('bookmarks-store'); | |
| 24 store.isTesting_ = true; | |
| 25 replaceBody(store); | |
| 26 store.setupStore_(TEST_TREE); | |
| 27 }); | |
| 28 | |
| 29 test('mapNodes inserts nodes into idToNodeMap', function(){ | |
|
tsergeant
2016/12/28 23:51:50
mapNodes is now called initNodes
angelayang
2016/12/29 02:53:34
Done.
| |
| 30 assertEquals(TEST_TREE, store.idToNodeMap_['0']); | |
| 31 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[1], store.idToNodeMap_['3']); | |
| 34 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); | |
| 35 assertEquals(TEST_TREE.children[2], store.idToNodeMap_['5']); | |
| 36 }); | |
| 37 | |
| 38 test('changing selectedId is changing the selectedNode', function(){ | |
|
tsergeant
2016/12/28 23:51:50
Grammar nit:
changing selectedId changes the sele
angelayang
2016/12/29 02:53:34
Done.
| |
| 39 store.selectedId = '0'; | |
| 40 assertEquals(TEST_TREE, store.selectedNode); | |
| 41 store.selectedId = '1'; | |
| 42 assertEquals(TEST_TREE.children[0], store.selectedNode); | |
| 43 store.selectedId = '2'; | |
| 44 assertEquals(TEST_TREE.children[0].children[0], store.selectedNode); | |
| 45 store.selectedId = '3'; | |
| 46 assertEquals(TEST_TREE.children[0].children[1], store.selectedNode); | |
| 47 store.selectedId = '4'; | |
| 48 assertEquals(TEST_TREE.children[1], store.selectedNode); | |
| 49 store.selectedId = '5'; | |
| 50 assertEquals(TEST_TREE.children[2], store.selectedNode); | |
| 51 }); | |
| 52 | |
| 53 test('correct paths generated for nodes', function() { | |
| 54 var TEST_PATHS = { | |
| 55 '0': 'rootNode', | |
| 56 '1': 'rootNode.children.0', | |
| 57 '2': 'rootNode.children.0.children.0', | |
| 58 '3': 'rootNode.children.0.children.1', | |
| 59 '4': 'rootNode.children.1', | |
| 60 '5': 'rootNode.children.2', | |
| 61 }; | |
| 62 | |
| 63 for (var id in store.idToNodeMap_) | |
| 64 assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path); | |
| 65 }); | |
| 66 | |
| 67 test('store updates on selected event', function() { | |
| 68 // First child of root is selected by default. | |
| 69 assertEquals('1', store.selectedId); | |
| 70 assertTrue(store.idToNodeMap_['1'].isSelected); | |
| 71 | |
| 72 // Selecting a selected folder doesn't deselect it. | |
| 73 store.fire('selected-folder-changed', '1'); | |
| 74 assertEquals('1', store.selectedId); | |
| 75 assertTrue(store.idToNodeMap_['1'].isSelected); | |
| 76 | |
| 77 // Select a deeply nested descendant. | |
| 78 store.fire('selected-folder-changed', '3'); | |
| 79 assertEquals('3', store.selectedId); | |
| 80 assertTrue(store.idToNodeMap_['3'].isSelected); | |
| 81 assertFalse(store.idToNodeMap_['1'].isSelected); | |
| 82 | |
| 83 // Select a folder in separate subtree. | |
| 84 store.fire('selected-folder-changed', '5'); | |
| 85 assertEquals('5', store.selectedId); | |
| 86 assertTrue(store.idToNodeMap_['5'].isSelected); | |
| 87 assertFalse(store.idToNodeMap_['3'].isSelected); | |
| 88 }); | |
| 89 | |
| 90 test('store update on folder open and closed', function() { | |
|
calamity
2016/12/29 00:54:50
nit: updates, open and close.
angelayang
2016/12/29 02:53:34
Done.
| |
| 91 // All folders are open by default. | |
| 92 for (var id in store.idToNodeMap_) { | |
| 93 if (store.idToNodeMap_[id].url) | |
| 94 continue; | |
| 95 | |
| 96 assertTrue(store.idToNodeMap_[id].isOpen); | |
| 97 } | |
| 98 | |
| 99 // Closing a folder doesn't close any descendants. | |
| 100 store.fire('folder-open-changed', {id: '1', open: false}); | |
| 101 assertFalse(store.idToNodeMap_['1'].isOpen); | |
| 102 assertTrue(store.idToNodeMap_['3'].isOpen); | |
| 103 store.fire('folder-open-changed', {id: '1', open: true}); | |
| 104 | |
| 105 // Closing an ancestor folder of a selected folder selects the ancestor. | |
| 106 store.fire('selected-folder-changed', '3'); | |
| 107 store.fire('folder-open-changed', {id: '1', open: false}); | |
| 108 assertFalse(store.idToNodeMap_['1'].isOpen); | |
| 109 assertEquals('1', store.selectedId); | |
| 110 assertTrue(store.idToNodeMap_['1'].isSelected); | |
| 111 assertFalse(store.idToNodeMap_['3'].isSelected); | |
| 112 }); | |
| 113 }); | |
| OLD | NEW |