| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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('selection state', function() { | 5 suite('selection state', function() { |
| 6 var state; | 6 var state; |
| 7 var action; | 7 var action; |
| 8 | 8 |
| 9 function select(items, anchor, add) { | 9 function select(items, anchor, add) { |
| 10 return { | 10 return { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 state = bookmarks.SelectionState.updateSelection(state, action); | 75 state = bookmarks.SelectionState.updateSelection(state, action); |
| 76 | 76 |
| 77 action = bookmarks.actions.clearSearch(); | 77 action = bookmarks.actions.clearSearch(); |
| 78 state = bookmarks.SelectionState.updateSelection(state, action); | 78 state = bookmarks.SelectionState.updateSelection(state, action); |
| 79 assertDeepEquals({}, state.items); | 79 assertDeepEquals({}, state.items); |
| 80 }); | 80 }); |
| 81 }); | 81 }); |
| 82 | 82 |
| 83 suite('closed folder state', function() { | 83 suite('closed folder state', function() { |
| 84 var nodes; | 84 var nodes; |
| 85 // TODO(tsergeant): Remove use of 'initialState' and 'nextState'. | 85 var state; |
| 86 var initialState; | 86 var action; |
| 87 | 87 |
| 88 setup(function() { | 88 setup(function() { |
| 89 nodes = testTree(createFolder('1', [ | 89 nodes = testTree(createFolder('1', [ |
| 90 createFolder('2', []), | 90 createFolder('2', []), |
| 91 ])); | 91 ])); |
| 92 initialState = {}; | 92 state = {}; |
| 93 }); | 93 }); |
| 94 | 94 |
| 95 test('toggle folder open state', function() { | 95 test('toggle folder open state', function() { |
| 96 var action = bookmarks.actions.changeFolderOpen('2', false); | 96 action = bookmarks.actions.changeFolderOpen('2', false); |
| 97 var nextState = bookmarks.ClosedFolderState.updateClosedFolders( | 97 state = |
| 98 initialState, action, nodes); | 98 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); |
| 99 assertFalse(!!nextState['1']); | 99 assertFalse(!!state['1']); |
| 100 assertTrue(nextState['2']); | 100 assertTrue(state['2']); |
| 101 }); | 101 }); |
| 102 | 102 |
| 103 test('select folder with closed parent', function() { | 103 test('select folder with closed parent', function() { |
| 104 var action; | |
| 105 var nextState; | |
| 106 // Close '1' | 104 // Close '1' |
| 107 action = bookmarks.actions.changeFolderOpen('1', false); | 105 action = bookmarks.actions.changeFolderOpen('1', false); |
| 108 nextState = bookmarks.ClosedFolderState.updateClosedFolders( | 106 state = |
| 109 initialState, action, nodes); | 107 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); |
| 110 assertTrue(nextState['1']); | 108 assertTrue(state['1']); |
| 111 assertFalse(!!nextState['2']); | 109 assertFalse(!!state['2']); |
| 112 | 110 |
| 113 // Should re-open when '2' is selected. | 111 // Should re-open when '2' is selected. |
| 114 action = bookmarks.actions.selectFolder('2'); | 112 action = bookmarks.actions.selectFolder('2'); |
| 115 nextState = bookmarks.ClosedFolderState.updateClosedFolders( | 113 state = |
| 116 nextState, action, nodes); | 114 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); |
| 117 assertFalse(!!nextState['1']); | 115 assertFalse(!!state['1']); |
| 118 }); | 116 }); |
| 119 }); | 117 }); |
| 120 | 118 |
| 121 suite('selected folder', function() { | 119 suite('selected folder', function() { |
| 122 var nodes; | 120 var nodes; |
| 123 var initialState; | 121 var state; |
| 122 var action; |
| 124 | 123 |
| 125 setup(function() { | 124 setup(function() { |
| 126 nodes = testTree(createFolder('1', [ | 125 nodes = testTree(createFolder('1', [ |
| 127 createFolder('2', []), | 126 createFolder('2', []), |
| 128 ])); | 127 ])); |
| 129 | 128 |
| 130 initialState = '1'; | 129 state = '1'; |
| 131 }); | 130 }); |
| 132 | 131 |
| 133 test('updates from selectFolder action', function() { | 132 test('updates from selectFolder action', function() { |
| 134 var action = bookmarks.actions.selectFolder('2'); | 133 action = bookmarks.actions.selectFolder('2'); |
| 135 var newState = bookmarks.SelectedFolderState.updateSelectedFolder( | 134 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 136 initialState, action, nodes); | 135 state, action, nodes); |
| 137 assertEquals('2', newState); | 136 assertEquals('2', state); |
| 138 }); | 137 }); |
| 139 | 138 |
| 140 test('updates when parent of selected folder is closed', function() { | 139 test('updates when parent of selected folder is closed', function() { |
| 141 var action; | |
| 142 var newState; | |
| 143 | |
| 144 action = bookmarks.actions.selectFolder('2'); | 140 action = bookmarks.actions.selectFolder('2'); |
| 145 newState = bookmarks.SelectedFolderState.updateSelectedFolder( | 141 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 146 initialState, action, nodes); | 142 state, action, nodes); |
| 147 | 143 |
| 148 action = bookmarks.actions.changeFolderOpen('1', false); | 144 action = bookmarks.actions.changeFolderOpen('1', false); |
| 149 newState = bookmarks.SelectedFolderState.updateSelectedFolder( | 145 state = bookmarks.SelectedFolderState.updateSelectedFolder( |
| 150 newState, action, nodes); | 146 state, action, nodes); |
| 151 assertEquals('1', newState); | 147 assertEquals('1', state); |
| 152 }); | 148 }); |
| 153 }); | 149 }); |
| 154 | 150 |
| 155 suite('node state', function() { | 151 suite('node state', function() { |
| 156 var initialState; | 152 var state; |
| 153 var action; |
| 157 | 154 |
| 158 setup(function() { | 155 setup(function() { |
| 159 initialState = testTree( | 156 state = testTree( |
| 160 createFolder( | 157 createFolder( |
| 161 '1', | 158 '1', |
| 162 [ | 159 [ |
| 163 createItem('2', {title: 'a', url: 'a.com'}), | 160 createItem('2', {title: 'a', url: 'a.com'}), |
| 164 createItem('3'), | 161 createItem('3'), |
| 165 createFolder('4', []), | 162 createFolder('4', []), |
| 166 ]), | 163 ]), |
| 167 createFolder('5', [])); | 164 createFolder('5', [])); |
| 168 }); | 165 }); |
| 169 | 166 |
| 170 test('updates when a node is edited', function() { | 167 test('updates when a node is edited', function() { |
| 171 var action = bookmarks.actions.editBookmark('2', {title: 'b'}); | 168 action = bookmarks.actions.editBookmark('2', {title: 'b'}); |
| 172 var nextState = bookmarks.NodeState.updateNodes(initialState, action); | 169 state = bookmarks.NodeState.updateNodes(state, action); |
| 173 | 170 |
| 174 assertEquals('b', nextState['2'].title); | 171 assertEquals('b', state['2'].title); |
| 175 assertEquals('a.com', nextState['2'].url); | 172 assertEquals('a.com', state['2'].url); |
| 176 | 173 |
| 177 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'}); | 174 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'}); |
| 178 nextState = bookmarks.NodeState.updateNodes(nextState, action); | 175 state = bookmarks.NodeState.updateNodes(state, action); |
| 179 | 176 |
| 180 assertEquals('c', nextState['2'].title); | 177 assertEquals('c', state['2'].title); |
| 181 assertEquals('c.com', nextState['2'].url); | 178 assertEquals('c.com', state['2'].url); |
| 182 | 179 |
| 183 action = bookmarks.actions.editBookmark('4', {title: 'folder'}); | 180 action = bookmarks.actions.editBookmark('4', {title: 'folder'}); |
| 184 nextState = bookmarks.NodeState.updateNodes(nextState, action); | 181 state = bookmarks.NodeState.updateNodes(state, action); |
| 185 | 182 |
| 186 assertEquals('folder', nextState['4'].title); | 183 assertEquals('folder', state['4'].title); |
| 187 assertEquals(undefined, nextState['4'].url); | 184 assertEquals(undefined, state['4'].url); |
| 188 | 185 |
| 189 // Cannot edit URL of a folder: | 186 // Cannot edit URL of a folder: |
| 190 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'}); | 187 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'}); |
| 191 nextState = bookmarks.NodeState.updateNodes(nextState, action); | 188 state = bookmarks.NodeState.updateNodes(state, action); |
| 192 | 189 |
| 193 assertEquals('folder', nextState['4'].title); | 190 assertEquals('folder', state['4'].title); |
| 194 assertEquals(undefined, nextState['4'].url); | 191 assertEquals(undefined, state['4'].url); |
| 195 }); | 192 }); |
| 196 | 193 |
| 197 test('updates when a node is deleted', function() { | 194 test('updates when a node is deleted', function() { |
| 198 var action = bookmarks.actions.removeBookmark('3', '1', 1); | 195 action = bookmarks.actions.removeBookmark('3', '1', 1); |
| 199 var nextState = bookmarks.NodeState.updateNodes(initialState, action); | 196 state = bookmarks.NodeState.updateNodes(state, action); |
| 200 | 197 |
| 201 assertDeepEquals(['2', '4'], nextState['1'].children); | 198 assertDeepEquals(['2', '4'], state['1'].children); |
| 202 | 199 |
| 203 // TODO(tsergeant): Deleted nodes should be removed from the nodes map | 200 // TODO(tsergeant): Deleted nodes should be removed from the nodes map |
| 204 // entirely. | 201 // entirely. |
| 205 }); | 202 }); |
| 206 }); | 203 }); |
| 207 | 204 |
| 208 suite('search state', function() { | 205 suite('search state', function() { |
| 209 var state; | 206 var state; |
| 210 | 207 |
| 211 setup(function() { | 208 setup(function() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // Case 2: Clear search by selecting a new folder. | 255 // Case 2: Clear search by selecting a new folder. |
| 259 action = bookmarks.actions.selectFolder('2'); | 256 action = bookmarks.actions.selectFolder('2'); |
| 260 var selectedState = bookmarks.reduceAction(searchedState, action); | 257 var selectedState = bookmarks.reduceAction(searchedState, action); |
| 261 | 258 |
| 262 assertEquals('2', selectedState.selectedFolder); | 259 assertEquals('2', selectedState.selectedFolder); |
| 263 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); | 260 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); |
| 264 assertEquals('', selectedState.search.term); | 261 assertEquals('', selectedState.search.term); |
| 265 assertDeepEquals([], selectedState.search.results); | 262 assertDeepEquals([], selectedState.search.results); |
| 266 }); | 263 }); |
| 267 }); | 264 }); |
| OLD | NEW |