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 selection; |
7 var action; | 7 var action; |
8 | 8 |
9 function select(items, anchor, add) { | 9 function select(items, anchor, add) { |
10 return { | 10 return { |
11 name: 'select-items', | 11 name: 'select-items', |
12 add: add, | 12 add: add, |
13 anchor: anchor, | 13 anchor: anchor, |
14 items: items, | 14 items: items, |
15 }; | 15 }; |
16 } | 16 } |
17 | 17 |
18 setup(function() { | 18 setup(function() { |
19 state = { | 19 selection = { |
20 anchor: null, | 20 anchor: null, |
21 items: {}, | 21 items: {}, |
22 }; | 22 }; |
23 }); | 23 }); |
24 | 24 |
25 test('can select an item', function() { | 25 test('can select an item', function() { |
26 action = select(['1'], '1', false); | 26 action = select(['1'], '1', false); |
27 state = bookmarks.SelectionState.updateSelection(state, action); | 27 selection = bookmarks.SelectionState.updateSelection(selection, action); |
28 | 28 |
29 assertDeepEquals(['1'], normalizeSet(state.items)); | 29 assertDeepEquals(['1'], normalizeSet(selection.items)); |
30 assertEquals('1', state.anchor); | 30 assertEquals('1', selection.anchor); |
31 | 31 |
32 // Replace current selection. | 32 // Replace current selection. |
33 action = select(['2'], '2', false); | 33 action = select(['2'], '2', false); |
34 state = bookmarks.SelectionState.updateSelection(state, action); | 34 selection = bookmarks.SelectionState.updateSelection(selection, action); |
35 assertDeepEquals(['2'], normalizeSet(state.items)); | 35 assertDeepEquals(['2'], normalizeSet(selection.items)); |
36 assertEquals('2', state.anchor); | 36 assertEquals('2', selection.anchor); |
37 | 37 |
38 // Add to current selection. | 38 // Add to current selection. |
39 action = select(['3'], '3', true); | 39 action = select(['3'], '3', true); |
40 state = bookmarks.SelectionState.updateSelection(state, action); | 40 selection = bookmarks.SelectionState.updateSelection(selection, action); |
41 assertDeepEquals(['2', '3'], normalizeSet(state.items)); | 41 assertDeepEquals(['2', '3'], normalizeSet(selection.items)); |
42 assertEquals('3', state.anchor); | 42 assertEquals('3', selection.anchor); |
43 }); | 43 }); |
44 | 44 |
45 test('can select multiple items', function() { | 45 test('can select multiple items', function() { |
46 action = select(['1', '2', '3'], '3', false); | 46 action = select(['1', '2', '3'], '3', false); |
47 state = bookmarks.SelectionState.updateSelection(state, action); | 47 selection = bookmarks.SelectionState.updateSelection(selection, action); |
48 assertDeepEquals(['1', '2', '3'], normalizeSet(state.items)); | 48 assertDeepEquals(['1', '2', '3'], normalizeSet(selection.items)); |
49 | 49 |
50 action = select(['3', '4'], '4', true); | 50 action = select(['3', '4'], '4', true); |
51 state = bookmarks.SelectionState.updateSelection(state, action); | 51 selection = bookmarks.SelectionState.updateSelection(selection, action); |
52 assertDeepEquals(['1', '2', '3', '4'], normalizeSet(state.items)); | 52 assertDeepEquals(['1', '2', '3', '4'], normalizeSet(selection.items)); |
53 }); | 53 }); |
54 | 54 |
55 test('is cleared when selected folder changes', function() { | 55 test('is cleared when selected folder changes', function() { |
56 action = select(['1', '2', '3'], '3', false); | 56 action = select(['1', '2', '3'], '3', false); |
57 state = bookmarks.SelectionState.updateSelection(state, action); | 57 selection = bookmarks.SelectionState.updateSelection(selection, action); |
58 | 58 |
59 action = bookmarks.actions.selectFolder('2'); | 59 action = bookmarks.actions.selectFolder('2'); |
60 state = bookmarks.SelectionState.updateSelection(state, action); | 60 selection = bookmarks.SelectionState.updateSelection(selection, action); |
61 assertDeepEquals({}, state.items); | 61 assertDeepEquals({}, selection.items); |
62 }); | 62 }); |
63 | 63 |
64 test('is cleared when search finished', function() { | 64 test('is cleared when search finished', function() { |
65 action = select(['1', '2', '3'], '3', false); | 65 action = select(['1', '2', '3'], '3', false); |
66 state = bookmarks.SelectionState.updateSelection(state, action); | 66 selection = bookmarks.SelectionState.updateSelection(selection, action); |
67 | 67 |
68 action = bookmarks.actions.setSearchResults(['2']); | 68 action = bookmarks.actions.setSearchResults(['2']); |
69 state = bookmarks.SelectionState.updateSelection(state, action); | 69 selection = bookmarks.SelectionState.updateSelection(selection, action); |
70 assertDeepEquals({}, state.items); | 70 assertDeepEquals({}, selection.items); |
71 }); | 71 }); |
72 | 72 |
73 test('is cleared when search cleared', function() { | 73 test('is cleared when search cleared', function() { |
74 action = select(['1', '2', '3'], '3', false); | 74 action = select(['1', '2', '3'], '3', false); |
75 state = bookmarks.SelectionState.updateSelection(state, action); | 75 selection = bookmarks.SelectionState.updateSelection(selection, action); |
76 | 76 |
77 action = bookmarks.actions.clearSearch(); | 77 action = bookmarks.actions.clearSearch(); |
78 state = bookmarks.SelectionState.updateSelection(state, action); | 78 selection = bookmarks.SelectionState.updateSelection(selection, action); |
79 assertDeepEquals({}, state.items); | 79 assertDeepEquals({}, selection.items); |
80 }); | 80 }); |
81 | 81 |
82 test('deselect items', function() { | 82 test('deselect items', function() { |
83 action = select(['1', '2', '3'], '3', false); | 83 action = select(['1', '2', '3'], '3', false); |
84 state = bookmarks.SelectionState.updateSelection(state, action); | 84 selection = bookmarks.SelectionState.updateSelection(selection, action); |
85 | 85 |
86 action = bookmarks.actions.deselectItems(); | 86 action = bookmarks.actions.deselectItems(); |
87 state = bookmarks.SelectionState.updateSelection(state, action); | 87 selection = bookmarks.SelectionState.updateSelection(selection, action); |
88 assertDeepEquals({}, state.items); | 88 assertDeepEquals({}, selection.items); |
89 }); | 89 }); |
90 | 90 |
91 test('deselects items when they are deleted', function() { | 91 test('deselects items when they are deleted', function() { |
92 var nodeList = testTree(createFolder('0', [ | 92 var nodeList = testTree(createFolder('0', [ |
93 createFolder( | 93 createFolder( |
94 '1', | 94 '1', |
95 [ | 95 [ |
96 createItem('2'), | 96 createItem('2'), |
97 createItem('3'), | 97 createItem('3'), |
98 createItem('4'), | 98 createItem('4'), |
99 ]), | 99 ]), |
100 createItem('5'), | 100 createItem('5'), |
101 ])); | 101 ])); |
102 | 102 |
103 action = select(['2', '4', '5'], '4', false); | 103 action = select(['2', '4', '5'], '4', false); |
104 state = bookmarks.SelectionState.updateSelection(state, action); | 104 selection = bookmarks.SelectionState.updateSelection(selection, action); |
105 | 105 |
106 action = bookmarks.actions.removeBookmark('1', '0', 0, nodeList); | 106 action = bookmarks.actions.removeBookmark('1', '0', 0, nodeList); |
107 state = bookmarks.SelectionState.updateSelection(state, action); | 107 selection = bookmarks.SelectionState.updateSelection(selection, action); |
108 | 108 |
109 assertDeepEquals(['5'], normalizeSet(state.items)); | 109 assertDeepEquals(['5'], normalizeSet(selection.items)); |
110 assertEquals(null, state.anchor); | 110 assertEquals(null, selection.anchor); |
111 }); | 111 }); |
112 }); | 112 }); |
113 | 113 |
114 suite('closed folder state', function() { | 114 suite('closed folder state', function() { |
115 var nodes; | 115 var nodes; |
116 var state; | 116 var closedFolders; |
117 var action; | 117 var action; |
118 | 118 |
119 setup(function() { | 119 setup(function() { |
120 nodes = testTree( | 120 nodes = testTree( |
121 createFolder( | 121 createFolder( |
122 '1', | 122 '1', |
123 [ | 123 [ |
124 createFolder('2', []), | 124 createFolder('2', []), |
125 createItem('3'), | 125 createItem('3'), |
126 ]), | 126 ]), |
127 createFolder('4', [])); | 127 createFolder('4', [])); |
128 state = new Set(); | 128 closedFolders = new Set(); |
129 }); | 129 }); |
130 | 130 |
131 test('toggle folder open state', function() { | 131 test('toggle folder open state', function() { |
132 action = bookmarks.actions.changeFolderOpen('2', false); | 132 action = bookmarks.actions.changeFolderOpen('2', false); |
133 state = | 133 closedFolders = bookmarks.ClosedFolderState.updateClosedFolders( |
134 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); | 134 closedFolders, action, nodes); |
135 assertFalse(state.has('1')); | 135 assertFalse(closedFolders.has('1')); |
136 assertTrue(state.has('2')); | 136 assertTrue(closedFolders.has('2')); |
137 }); | 137 }); |
138 | 138 |
139 test('select folder with closed parent', function() { | 139 test('select folder with closed parent', function() { |
140 // Close '1' | 140 // Close '1' |
141 action = bookmarks.actions.changeFolderOpen('1', false); | 141 action = bookmarks.actions.changeFolderOpen('1', false); |
142 state = | 142 closedFolders = bookmarks.ClosedFolderState.updateClosedFolders( |
143 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); | 143 closedFolders, action, nodes); |
144 assertTrue(state.has('1')); | 144 assertTrue(closedFolders.has('1')); |
145 assertFalse(state.has('2')); | 145 assertFalse(closedFolders.has('2')); |
146 | 146 |
147 // Should re-open when '2' is selected. | 147 // Should re-open when '2' is selected. |
148 action = bookmarks.actions.selectFolder('2'); | 148 action = bookmarks.actions.selectFolder('2'); |
149 state = | 149 closedFolders = bookmarks.ClosedFolderState.updateClosedFolders( |
150 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); | 150 closedFolders, action, nodes); |
151 assertFalse(state.has('1')); | 151 assertFalse(closedFolders.has('1')); |
152 }); | 152 }); |
153 | 153 |
154 test('move nodes in a closed folder', function() { | 154 test('move nodes in a closed folder', function() { |
155 // Moving bookmark items should not open folders. | 155 // Moving bookmark items should not open folders. |
156 state = new Set(['1']); | 156 closedFolders = new Set(['1']); |
157 action = bookmarks.actions.moveBookmark('3', '1', 1, '1', 0); | 157 action = bookmarks.actions.moveBookmark('3', '1', 1, '1', 0); |
158 state = | 158 closedFolders = bookmarks.ClosedFolderState.updateClosedFolders( |
159 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); | 159 closedFolders, action, nodes); |
160 | 160 |
161 assertTrue(state.has('1')); | 161 assertTrue(closedFolders.has('1')); |
162 | 162 |
163 // Moving folders should open their parents. | 163 // Moving folders should open their parents. |
164 state = new Set(['1', '2']); | 164 closedFolders = new Set(['1', '2']); |
165 action = bookmarks.actions.moveBookmark('4', '2', 0, '0', 1); | 165 action = bookmarks.actions.moveBookmark('4', '2', 0, '0', 1); |
166 state = | 166 closedFolders = bookmarks.ClosedFolderState.updateClosedFolders( |
167 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); | 167 closedFolders, action, nodes); |
168 assertFalse(state.has('1')); | 168 assertFalse(closedFolders.has('1')); |
169 assertFalse(state.has('2')); | 169 assertFalse(closedFolders.has('2')); |
170 }); | 170 }); |
171 }); | 171 }); |
172 | 172 |
173 suite('selected folder', function() { | 173 suite('selected folder', function() { |
174 var nodes; | 174 var nodes; |
175 var state; | 175 var selectedFolder; |
176 var action; | 176 var action; |
177 | 177 |
178 setup(function() { | 178 setup(function() { |
179 nodes = testTree(createFolder('1', [ | 179 nodes = testTree(createFolder('1', [ |
180 createFolder( | 180 createFolder( |
181 '2', | 181 '2', |
182 [ | 182 [ |
183 createFolder('3', []), | 183 createFolder('3', []), |
184 createFolder('4', []), | 184 createFolder('4', []), |
185 ]), | 185 ]), |
186 ])); | 186 ])); |
187 | 187 |
188 state = '1'; | 188 selectedFolder = '1'; |
189 }); | 189 }); |
190 | 190 |
191 test('updates from selectFolder action', function() { | 191 test('updates from selectFolder action', function() { |
192 action = bookmarks.actions.selectFolder('2'); | 192 action = bookmarks.actions.selectFolder('2'); |
193 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 193 selectedFolder = bookmarks.SelectedFolderState.updateSelectedFolder( |
194 state, action, nodes); | 194 selectedFolder, action, nodes); |
195 assertEquals('2', state); | 195 assertEquals('2', selectedFolder); |
196 }); | 196 }); |
197 | 197 |
198 test('updates when parent of selected folder is closed', function() { | 198 test('updates when parent of selected folder is closed', function() { |
199 action = bookmarks.actions.selectFolder('2'); | 199 action = bookmarks.actions.selectFolder('2'); |
200 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 200 selectedFolder = bookmarks.SelectedFolderState.updateSelectedFolder( |
201 state, action, nodes); | 201 selectedFolder, action, nodes); |
202 | 202 |
203 action = bookmarks.actions.changeFolderOpen('1', false); | 203 action = bookmarks.actions.changeFolderOpen('1', false); |
204 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 204 selectedFolder = bookmarks.SelectedFolderState.updateSelectedFolder( |
205 state, action, nodes); | 205 selectedFolder, action, nodes); |
206 assertEquals('1', state); | 206 assertEquals('1', selectedFolder); |
207 }); | 207 }); |
208 | 208 |
209 test('selects ancestor when selected folder is deleted', function() { | 209 test('selects ancestor when selected folder is deleted', function() { |
210 action = bookmarks.actions.selectFolder('3'); | 210 action = bookmarks.actions.selectFolder('3'); |
211 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 211 selectedFolder = bookmarks.SelectedFolderState.updateSelectedFolder( |
212 state, action, nodes); | 212 selectedFolder, action, nodes); |
213 | 213 |
214 // Delete the selected folder: | 214 // Delete the selected folder: |
215 action = bookmarks.actions.removeBookmark('3', '2', 0, nodes); | 215 action = bookmarks.actions.removeBookmark('3', '2', 0, nodes); |
216 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 216 selectedFolder = bookmarks.SelectedFolderState.updateSelectedFolder( |
217 state, action, nodes); | 217 selectedFolder, action, nodes); |
218 | 218 |
219 assertEquals('2', state); | 219 assertEquals('2', selectedFolder); |
220 | 220 |
221 action = bookmarks.actions.selectFolder('4'); | 221 action = bookmarks.actions.selectFolder('4'); |
222 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 222 selectedFolder = bookmarks.SelectedFolderState.updateSelectedFolder( |
223 state, action, nodes); | 223 selectedFolder, action, nodes); |
224 | 224 |
225 // Delete an ancestor of the selected folder: | 225 // Delete an ancestor of the selected folder: |
226 action = bookmarks.actions.removeBookmark('2', '1', 0, nodes); | 226 action = bookmarks.actions.removeBookmark('2', '1', 0, nodes); |
227 state = bookmarks.SelectedFolderState.updateSelectedFolder( | 227 selectedFolder = bookmarks.SelectedFolderState.updateSelectedFolder( |
228 state, action, nodes); | 228 selectedFolder, action, nodes); |
229 | 229 |
230 assertEquals('1', state); | 230 assertEquals('1', selectedFolder); |
231 }); | 231 }); |
232 }); | 232 }); |
233 | 233 |
234 suite('node state', function() { | 234 suite('node state', function() { |
235 var state; | 235 var nodes; |
236 var action; | 236 var action; |
237 | 237 |
238 setup(function() { | 238 setup(function() { |
239 state = testTree( | 239 nodes = testTree( |
240 createFolder( | 240 createFolder( |
241 '1', | 241 '1', |
242 [ | 242 [ |
243 createItem('2', {title: 'a', url: 'a.com'}), | 243 createItem('2', {title: 'a', url: 'a.com'}), |
244 createItem('3'), | 244 createItem('3'), |
245 createFolder('4', []), | 245 createFolder('4', []), |
246 ]), | 246 ]), |
247 createFolder('5', [])); | 247 createFolder('5', [])); |
248 }); | 248 }); |
249 | 249 |
250 test('updates when a node is edited', function() { | 250 test('updates when a node is edited', function() { |
251 action = bookmarks.actions.editBookmark('2', {title: 'b'}); | 251 action = bookmarks.actions.editBookmark('2', {title: 'b'}); |
252 state = bookmarks.NodeState.updateNodes(state, action); | 252 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
253 | 253 |
254 assertEquals('b', state['2'].title); | 254 assertEquals('b', nodes['2'].title); |
255 assertEquals('a.com', state['2'].url); | 255 assertEquals('a.com', nodes['2'].url); |
256 | 256 |
257 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'}); | 257 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'}); |
258 state = bookmarks.NodeState.updateNodes(state, action); | 258 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
259 | 259 |
260 assertEquals('c', state['2'].title); | 260 assertEquals('c', nodes['2'].title); |
261 assertEquals('c.com', state['2'].url); | 261 assertEquals('c.com', nodes['2'].url); |
262 | 262 |
263 action = bookmarks.actions.editBookmark('4', {title: 'folder'}); | 263 action = bookmarks.actions.editBookmark('4', {title: 'folder'}); |
264 state = bookmarks.NodeState.updateNodes(state, action); | 264 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
265 | 265 |
266 assertEquals('folder', state['4'].title); | 266 assertEquals('folder', nodes['4'].title); |
267 assertEquals(undefined, state['4'].url); | 267 assertEquals(undefined, nodes['4'].url); |
268 | 268 |
269 // Cannot edit URL of a folder: | 269 // Cannot edit URL of a folder: |
270 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'}); | 270 action = bookmarks.actions.editBookmark('4', {url: 'folder.com'}); |
271 state = bookmarks.NodeState.updateNodes(state, action); | 271 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
272 | 272 |
273 assertEquals('folder', state['4'].title); | 273 assertEquals('folder', nodes['4'].title); |
274 assertEquals(undefined, state['4'].url); | 274 assertEquals(undefined, nodes['4'].url); |
275 }); | 275 }); |
276 | 276 |
277 test('updates when a node is created', function() { | 277 test('updates when a node is created', function() { |
278 // Create a folder. | 278 // Create a folder. |
279 var folder = { | 279 var folder = { |
280 id: '6', | 280 id: '6', |
281 parentId: '1', | 281 parentId: '1', |
282 index: 2, | 282 index: 2, |
283 }; | 283 }; |
284 action = bookmarks.actions.createBookmark(folder.id, folder); | 284 action = bookmarks.actions.createBookmark(folder.id, folder); |
285 state = bookmarks.NodeState.updateNodes(state, action); | 285 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
286 | 286 |
287 assertEquals('1', state['6'].parentId); | 287 assertEquals('1', nodes['6'].parentId); |
288 assertDeepEquals([], state['6'].children); | 288 assertDeepEquals([], nodes['6'].children); |
289 assertDeepEquals(['2', '3', '6', '4'], state['1'].children); | 289 assertDeepEquals(['2', '3', '6', '4'], nodes['1'].children); |
290 | 290 |
291 // Add a new item to that folder. | 291 // Add a new item to that folder. |
292 var item = { | 292 var item = { |
293 id: '7', | 293 id: '7', |
294 parentId: '6', | 294 parentId: '6', |
295 index: 0, | 295 index: 0, |
296 url: 'https://www.example.com', | 296 url: 'https://www.example.com', |
297 }; | 297 }; |
298 | 298 |
299 action = bookmarks.actions.createBookmark(item.id, item); | 299 action = bookmarks.actions.createBookmark(item.id, item); |
300 state = bookmarks.NodeState.updateNodes(state, action); | 300 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
301 | 301 |
302 assertEquals('6', state['7'].parentId); | 302 assertEquals('6', nodes['7'].parentId); |
303 assertEquals(undefined, state['7'].children); | 303 assertEquals(undefined, nodes['7'].children); |
304 assertDeepEquals(['7'], state['6'].children); | 304 assertDeepEquals(['7'], nodes['6'].children); |
305 }); | 305 }); |
306 | 306 |
307 test('updates when a node is deleted', function() { | 307 test('updates when a node is deleted', function() { |
308 action = bookmarks.actions.removeBookmark('3', '1', 1, state); | 308 action = bookmarks.actions.removeBookmark('3', '1', 1, nodes); |
309 state = bookmarks.NodeState.updateNodes(state, action); | 309 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
310 | 310 |
311 assertDeepEquals(['2', '4'], state['1'].children); | 311 assertDeepEquals(['2', '4'], nodes['1'].children); |
312 | 312 |
313 assertDeepEquals(['2', '4'], state['1'].children); | 313 assertDeepEquals(['2', '4'], nodes['1'].children); |
314 assertEquals(undefined, state['3']); | 314 assertEquals(undefined, nodes['3']); |
315 }); | 315 }); |
316 | 316 |
317 test('removes all children of deleted nodes', function() { | 317 test('removes all children of deleted nodes', function() { |
318 action = bookmarks.actions.removeBookmark('1', '0', 0, state); | 318 action = bookmarks.actions.removeBookmark('1', '0', 0, nodes); |
319 state = bookmarks.NodeState.updateNodes(state, action); | 319 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
320 | 320 |
321 assertDeepEquals(['0', '5'], Object.keys(state).sort()); | 321 assertDeepEquals(['0', '5'], Object.keys(nodes).sort()); |
322 }); | 322 }); |
323 | 323 |
324 test('updates when a node is moved', function() { | 324 test('updates when a node is moved', function() { |
325 // Move within the same folder backwards. | 325 // Move within the same folder backwards. |
326 action = bookmarks.actions.moveBookmark('3', '1', 0, '1', 1); | 326 action = bookmarks.actions.moveBookmark('3', '1', 0, '1', 1); |
327 state = bookmarks.NodeState.updateNodes(state, action); | 327 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
328 | 328 |
329 assertDeepEquals(['3', '2', '4'], state['1'].children); | 329 assertDeepEquals(['3', '2', '4'], nodes['1'].children); |
330 | 330 |
331 // Move within the same folder forwards. | 331 // Move within the same folder forwards. |
332 action = bookmarks.actions.moveBookmark('3', '1', 2, '1', 0); | 332 action = bookmarks.actions.moveBookmark('3', '1', 2, '1', 0); |
333 state = bookmarks.NodeState.updateNodes(state, action); | 333 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
334 | 334 |
335 assertDeepEquals(['2', '4', '3'], state['1'].children); | 335 assertDeepEquals(['2', '4', '3'], nodes['1'].children); |
336 | 336 |
337 // Move between different folders. | 337 // Move between different folders. |
338 action = bookmarks.actions.moveBookmark('4', '5', 0, '1', 1); | 338 action = bookmarks.actions.moveBookmark('4', '5', 0, '1', 1); |
339 state = bookmarks.NodeState.updateNodes(state, action); | 339 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
340 | 340 |
341 assertDeepEquals(['2', '3'], state['1'].children); | 341 assertDeepEquals(['2', '3'], nodes['1'].children); |
342 assertDeepEquals(['4'], state['5'].children); | 342 assertDeepEquals(['4'], nodes['5'].children); |
343 }); | 343 }); |
344 | 344 |
345 test('updates when children of a node are reordered', function() { | 345 test('updates when children of a node are reordered', function() { |
346 action = bookmarks.actions.reorderChildren('1', ['4', '2', '3']); | 346 action = bookmarks.actions.reorderChildren('1', ['4', '2', '3']); |
347 state = bookmarks.NodeState.updateNodes(state, action); | 347 nodes = bookmarks.NodeState.updateNodes(nodes, action); |
348 | 348 |
349 assertDeepEquals(['4', '2', '3'], state['1'].children); | 349 assertDeepEquals(['4', '2', '3'], nodes['1'].children); |
350 }); | 350 }); |
351 }); | 351 }); |
352 | 352 |
353 suite('search state', function() { | 353 suite('search state', function() { |
354 var state; | 354 var state; |
355 | 355 |
356 setup(function() { | 356 setup(function() { |
357 // Search touches a few different things, so we test using the entire state: | 357 // Search touches a few different things, so we test using the entire state. |
358 state = bookmarks.util.createEmptyState(); | 358 state = bookmarks.util.createEmptyState(); |
359 state.nodes = testTree(createFolder('1', [ | 359 state.nodes = testTree(createFolder('1', [ |
360 createFolder( | 360 createFolder( |
361 '2', | 361 '2', |
362 [ | 362 [ |
363 createItem('3'), | 363 createItem('3'), |
364 ]), | 364 ]), |
365 ])); | 365 ])); |
366 }); | 366 }); |
367 | 367 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 state = bookmarks.reduceAction(state, action); | 420 state = bookmarks.reduceAction(state, action); |
421 | 421 |
422 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes); | 422 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes); |
423 state = bookmarks.reduceAction(state, action); | 423 state = bookmarks.reduceAction(state, action); |
424 | 424 |
425 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of | 425 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of |
426 // 2. | 426 // 2. |
427 assertDeepEquals(['1'], state.search.results); | 427 assertDeepEquals(['1'], state.search.results); |
428 }); | 428 }); |
429 }); | 429 }); |
OLD | NEW |