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

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

Issue 2774233006: [MD Bookmarks] Change selection items from Map to Set. (Closed)
Patch Set: rebase Created 3 years, 8 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
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 {
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 state = {
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 state = bookmarks.SelectionState.updateSelection(state, action);
28 28
29 assertDeepEquals({'1': true}, state.items); 29 assertDeepEquals(['1'], normalizeSet(state.items));
30 assertEquals('1', state.anchor); 30 assertEquals('1', state.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 state = bookmarks.SelectionState.updateSelection(state, action);
35 assertDeepEquals({'2': true}, state.items); 35 assertDeepEquals(['2'], normalizeSet(state.items));
36 assertEquals('2', state.anchor); 36 assertEquals('2', state.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 state = bookmarks.SelectionState.updateSelection(state, action);
41 assertDeepEquals({'2': true, '3': true}, state.items); 41 assertDeepEquals(['2', '3'], normalizeSet(state.items));
42 assertEquals('3', state.anchor); 42 assertEquals('3', state.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 state = bookmarks.SelectionState.updateSelection(state, action);
48 assertDeepEquals({'1': true, '2': true, '3': true}, state.items); 48 assertDeepEquals(['1', '2', '3'], normalizeSet(state.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 state = bookmarks.SelectionState.updateSelection(state, action);
52 assertDeepEquals({'1': true, '2': true, '3': true, '4': true}, state.items); 52 assertDeepEquals(['1', '2', '3', '4'], normalizeSet(state.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 state = bookmarks.SelectionState.updateSelection(state, action);
58 58
59 action = bookmarks.actions.selectFolder('2'); 59 action = bookmarks.actions.selectFolder('2');
60 state = bookmarks.SelectionState.updateSelection(state, action); 60 state = bookmarks.SelectionState.updateSelection(state, action);
61 assertDeepEquals({}, state.items); 61 assertDeepEquals({}, state.items);
62 }); 62 });
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 setup(function() { 97 setup(function() {
98 nodes = testTree( 98 nodes = testTree(
99 createFolder( 99 createFolder(
100 '1', 100 '1',
101 [ 101 [
102 createFolder('2', []), 102 createFolder('2', []),
103 createItem('3'), 103 createItem('3'),
104 ]), 104 ]),
105 createFolder('4', [])); 105 createFolder('4', []));
106 state = {}; 106 state = new Set();
107 }); 107 });
108 108
109 test('toggle folder open state', function() { 109 test('toggle folder open state', function() {
110 action = bookmarks.actions.changeFolderOpen('2', false); 110 action = bookmarks.actions.changeFolderOpen('2', false);
111 state = 111 state =
112 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 112 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
113 assertFalse(!!state['1']); 113 assertFalse(state.has('1'));
114 assertTrue(state['2']); 114 assertTrue(state.has('2'));
115 }); 115 });
116 116
117 test('select folder with closed parent', function() { 117 test('select folder with closed parent', function() {
118 // Close '1' 118 // Close '1'
119 action = bookmarks.actions.changeFolderOpen('1', false); 119 action = bookmarks.actions.changeFolderOpen('1', false);
120 state = 120 state =
121 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 121 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
122 assertTrue(state['1']); 122 assertTrue(state.has('1'));
123 assertFalse(!!state['2']); 123 assertFalse(state.has('2'));
124 124
125 // Should re-open when '2' is selected. 125 // Should re-open when '2' is selected.
126 action = bookmarks.actions.selectFolder('2'); 126 action = bookmarks.actions.selectFolder('2');
127 state = 127 state =
128 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 128 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
129 assertFalse(!!state['1']); 129 assertFalse(state.has('1'));
130 }); 130 });
131 131
132 test('move nodes in a closed folder', function() { 132 test('move nodes in a closed folder', function() {
133 // Moving bookmark items should not open folders. 133 // Moving bookmark items should not open folders.
134 state = {'1': true}; 134 state = new Set(['1']);
135 action = bookmarks.actions.moveBookmark('3', '1', 1, '1', 0); 135 action = bookmarks.actions.moveBookmark('3', '1', 1, '1', 0);
136 state = 136 state =
137 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 137 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
138 138
139 assertTrue(state['1']); 139 assertTrue(state.has('1'));
140 140
141 // Moving folders should open their parents. 141 // Moving folders should open their parents.
142 state = {'1': true, '2': true}; 142 state = new Set(['1', '2']);
143 action = bookmarks.actions.moveBookmark('4', '2', 0, '0', 1); 143 action = bookmarks.actions.moveBookmark('4', '2', 0, '0', 1);
144 state = 144 state =
145 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes); 145 bookmarks.ClosedFolderState.updateClosedFolders(state, action, nodes);
146 assertFalse(!!state['1']); 146 assertFalse(state.has('1'));
147 assertFalse(!!state['2']); 147 assertFalse(state.has('2'));
148 }); 148 });
149 }); 149 });
150 150
151 suite('selected folder', function() { 151 suite('selected folder', function() {
152 var nodes; 152 var nodes;
153 var state; 153 var state;
154 var action; 154 var action;
155 155
156 setup(function() { 156 setup(function() {
157 nodes = testTree(createFolder('1', [ 157 nodes = testTree(createFolder('1', [
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // Case 2: Clear search by selecting a new folder. 308 // Case 2: Clear search by selecting a new folder.
309 action = bookmarks.actions.selectFolder('2'); 309 action = bookmarks.actions.selectFolder('2');
310 var selectedState = bookmarks.reduceAction(searchedState, action); 310 var selectedState = bookmarks.reduceAction(searchedState, action);
311 311
312 assertEquals('2', selectedState.selectedFolder); 312 assertEquals('2', selectedState.selectedFolder);
313 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState)); 313 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState));
314 assertEquals('', selectedState.search.term); 314 assertEquals('', selectedState.search.term);
315 assertDeepEquals([], selectedState.search.results); 315 assertDeepEquals([], selectedState.search.results);
316 }); 316 });
317 }); 317 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/dnd_manager_test.js ('k') | chrome/test/data/webui/md_bookmarks/test_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698