Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1077)

Side by Side Diff: chrome/test/data/webui/md_bookmarks/reducers_test.js

Issue 2750463010: [MD Bookmarks] Handle bookmark moves. (Closed)
Patch Set: remove log Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/md_bookmarks/reducers.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 var state; 85 var state;
86 var action; 86 var action;
87 87
88 setup(function() { 88 setup(function() {
89 nodes = testTree(createFolder('1', [ 89 nodes = testTree(
90 createFolder('2', []), 90 createFolder(
91 ])); 91 '1',
92 [
93 createFolder('2', []),
94 createItem('3'),
95 ]),
96 createFolder('4', []));
92 state = {}; 97 state = {};
93 }); 98 });
94 99
95 test('toggle folder open state', function() { 100 test('toggle folder open state', function() {
96 action = bookmarks.actions.changeFolderOpen('2', false); 101 action = bookmarks.actions.changeFolderOpen('2', false);
97 state = 102 state =
98 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 103 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
99 assertFalse(!!state['1']); 104 assertFalse(!!state['1']);
100 assertTrue(state['2']); 105 assertTrue(state['2']);
101 }); 106 });
102 107
103 test('select folder with closed parent', function() { 108 test('select folder with closed parent', function() {
104 // Close '1' 109 // Close '1'
105 action = bookmarks.actions.changeFolderOpen('1', false); 110 action = bookmarks.actions.changeFolderOpen('1', false);
106 state = 111 state =
107 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 112 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
108 assertTrue(state['1']); 113 assertTrue(state['1']);
109 assertFalse(!!state['2']); 114 assertFalse(!!state['2']);
110 115
111 // Should re-open when '2' is selected. 116 // Should re-open when '2' is selected.
112 action = bookmarks.actions.selectFolder('2'); 117 action = bookmarks.actions.selectFolder('2');
113 state = 118 state =
114 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 119 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
115 assertFalse(!!state['1']); 120 assertFalse(!!state['1']);
116 }); 121 });
122
123 test('move nodes in a closed folder', function() {
124 // Moving bookmark items should not open folders.
125 state = {'1': true};
126 action = bookmarks.actions.moveBookmark('3', '1', 1, '1', 0);
127 state =
128 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
129
130 assertTrue(state['1']);
131
132 // Moving folders should open their parents.
133 state = {'1': true, '2': true};
134 action = bookmarks.actions.moveBookmark('4', '2', 0, '0', 1);
135 state =
136 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
137 assertFalse(!!state['1']);
138 assertFalse(!!state['2']);
139 });
117 }); 140 });
118 141
119 suite('selected folder', function() { 142 suite('selected folder', function() {
120 var nodes; 143 var nodes;
121 var state; 144 var state;
122 var action; 145 var action;
123 146
124 setup(function() { 147 setup(function() {
125 nodes = testTree(createFolder('1', [ 148 nodes = testTree(createFolder('1', [
126 createFolder('2', []), 149 createFolder('2', []),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 216
194 test('updates when a node is deleted', function() { 217 test('updates when a node is deleted', function() {
195 action = bookmarks.actions.removeBookmark('3', '1', 1); 218 action = bookmarks.actions.removeBookmark('3', '1', 1);
196 state = bookmarks.NodeState.updateNodes(state, action); 219 state = bookmarks.NodeState.updateNodes(state, action);
197 220
198 assertDeepEquals(['2', '4'], state['1'].children); 221 assertDeepEquals(['2', '4'], state['1'].children);
199 222
200 // TODO(tsergeant): Deleted nodes should be removed from the nodes map 223 // TODO(tsergeant): Deleted nodes should be removed from the nodes map
201 // entirely. 224 // entirely.
202 }); 225 });
226
227 test('updates when a node is moved', function() {
228 // Move within the same folder backwards.
229 action = bookmarks.actions.moveBookmark('3', '1', 0, '1', 1);
230 state = bookmarks.NodeState.updateNodes(state, action);
231
232 assertDeepEquals(['3', '2', '4'], state['1'].children);
233
234 // Move within the same folder forwards.
235 action = bookmarks.actions.moveBookmark('3', '1', 2, '1', 0);
236 state = bookmarks.NodeState.updateNodes(state, action);
237
238 assertDeepEquals(['2', '4', '3'], state['1'].children);
239
240 // Move between different folders.
241 action = bookmarks.actions.moveBookmark('4', '5', 0, '1', 1);
242 state = bookmarks.NodeState.updateNodes(state, action);
243
244 assertDeepEquals(['2', '3'], state['1'].children);
245 assertDeepEquals(['4'], state['5'].children);
246 });
203 }); 247 });
204 248
205 suite('search state', function() { 249 suite('search state', function() {
206 var state; 250 var state;
207 251
208 setup(function() { 252 setup(function() {
209 // Search touches a few different things, so we test using the entire state: 253 // Search touches a few different things, so we test using the entire state:
210 state = bookmarks.util.createEmptyState(); 254 state = bookmarks.util.createEmptyState();
211 state.nodes = testTree(createFolder('1', [ 255 state.nodes = testTree(createFolder('1', [
212 createFolder( 256 createFolder(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Case 2: Clear search by selecting a new folder. 299 // Case 2: Clear search by selecting a new folder.
256 action = bookmarks.actions.selectFolder('2'); 300 action = bookmarks.actions.selectFolder('2');
257 var selectedState = bookmarks.reduceAction(searchedState, action); 301 var selectedState = bookmarks.reduceAction(searchedState, action);
258 302
259 assertEquals('2', selectedState.selectedFolder); 303 assertEquals('2', selectedState.selectedFolder);
260 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); 304 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState));
261 assertEquals('', selectedState.search.term); 305 assertEquals('', selectedState.search.term);
262 assertDeepEquals([], selectedState.search.results); 306 assertDeepEquals([], selectedState.search.results);
263 }); 307 });
264 }); 308 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/reducers.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698