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 selection; | 6 var selection; |
7 var action; | 7 var action; |
8 | 8 |
9 function select(items, anchor, clear, toggle) { | 9 function select(items, anchor, clear, toggle) { |
10 return { | 10 return { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 }); | 99 }); |
100 | 100 |
101 test('update anchor', function() { | 101 test('update anchor', function() { |
102 action = bookmarks.actions.updateAnchor('3'); | 102 action = bookmarks.actions.updateAnchor('3'); |
103 selection = bookmarks.SelectionState.updateSelection(selection, action); | 103 selection = bookmarks.SelectionState.updateSelection(selection, action); |
104 | 104 |
105 assertEquals('3', selection.anchor); | 105 assertEquals('3', selection.anchor); |
106 }); | 106 }); |
107 | 107 |
108 test('deselects items when they are deleted', function() { | 108 test('deselects items when they are deleted', function() { |
109 var nodeMap = testTree(createFolder('0', [ | 109 var nodeMap = testTree( |
110 createFolder( | 110 createFolder( |
111 '1', | 111 '1', |
112 [ | 112 [ |
113 createItem('2'), | 113 createItem('2'), |
114 createItem('3'), | 114 createItem('3'), |
115 createItem('4'), | 115 createItem('4'), |
116 ]), | 116 ]), |
117 createItem('5'), | 117 createItem('5'), |
118 ])); | 118 ); |
119 | 119 |
120 action = select(['2', '4', '5'], '4', true, false); | 120 action = select(['2', '4', '5'], '4', true, false); |
121 selection = bookmarks.SelectionState.updateSelection(selection, action); | 121 selection = bookmarks.SelectionState.updateSelection(selection, action); |
122 | 122 |
123 action = bookmarks.actions.removeBookmark('1', '0', 0, nodeMap); | 123 action = bookmarks.actions.removeBookmark('1', '0', 0, nodeMap); |
124 selection = bookmarks.SelectionState.updateSelection(selection, action); | 124 selection = bookmarks.SelectionState.updateSelection(selection, action); |
125 | 125 |
126 assertDeepEquals(['5'], normalizeSet(selection.items)); | 126 assertDeepEquals(['5'], normalizeSet(selection.items)); |
127 assertEquals(null, selection.anchor); | 127 assertEquals(null, selection.anchor); |
128 }); | 128 }); |
129 | |
130 test('deselects items when they are moved to a different folder', function() { | |
131 var nodeMap = testTree( | |
132 createFolder('1', []), | |
133 createItem('2'), | |
134 createItem('3'), | |
135 ); | |
136 | |
137 action = select(['2', '3'], '2', true, false); | |
138 selection = bookmarks.SelectionState.updateSelection(selection, action); | |
139 | |
140 // Move item '2' from the 1st item in '0' to the 0th item in '1'. | |
141 action = bookmarks.actions.moveBookmark('2', '1', 0, '0', 1); | |
calamity
2017/06/22 05:35:34
I feel like we should have made these objects. It'
tsergeant
2017/06/22 06:59:09
Do you mean in general or just in this test?
This
| |
142 selection = bookmarks.SelectionState.updateSelection(selection, action); | |
143 | |
144 assertDeepEquals(['3'], normalizeSet(selection.items)); | |
145 assertEquals(null, selection.anchor); | |
146 }); | |
129 }); | 147 }); |
130 | 148 |
131 suite('closed folder state', function() { | 149 suite('closed folder state', function() { |
132 var nodes; | 150 var nodes; |
133 var closedFolders; | 151 var closedFolders; |
134 var action; | 152 var action; |
135 | 153 |
136 setup(function() { | 154 setup(function() { |
137 nodes = testTree( | 155 nodes = testTree( |
138 createFolder( | 156 createFolder( |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 state = bookmarks.reduceAction(state, action); | 459 state = bookmarks.reduceAction(state, action); |
442 | 460 |
443 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes); | 461 action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes); |
444 state = bookmarks.reduceAction(state, action); | 462 state = bookmarks.reduceAction(state, action); |
445 | 463 |
446 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of | 464 // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of |
447 // 2. | 465 // 2. |
448 assertDeepEquals(['1'], state.search.results); | 466 assertDeepEquals(['1'], state.search.results); |
449 }); | 467 }); |
450 }); | 468 }); |
OLD | NEW |