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

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

Issue 2740863003: MD Bookmarks: Implement search and selection in new data flow system (Closed)
Patch Set: Review round 2 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
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('closed folder state', function() { 5 suite('closed folder state', function() {
6 var nodes; 6 var nodes;
7 // TODO(tsergeant): Remove use of 'initialState' and 'nextState'.
7 var initialState; 8 var initialState;
8 9
9 setup(function() { 10 setup(function() {
10 nodes = testTree(createFolder('0', [ 11 nodes = testTree(createFolder('1', [
11 createFolder('1', []), 12 createFolder('2', []),
12 ])); 13 ]));
13 initialState = {}; 14 initialState = {};
14 }); 15 });
15 16
16 test('toggle folder open state', function() { 17 test('toggle folder open state', function() {
17 var action = bookmarks.actions.changeFolderOpen('1', false); 18 var action = bookmarks.actions.changeFolderOpen('2', false);
18 var nextState = bookmarks.ClosedFolderState.updateClosedFolders( 19 var nextState = bookmarks.ClosedFolderState.updateClosedFolders(
19 initialState, action, nodes); 20 initialState, action, nodes);
20 assertTrue(nextState['1']); 21 assertFalse(!!nextState['1']);
21 assertFalse(!!nextState['0']); 22 assertTrue(nextState['2']);
22 }); 23 });
23 24
24 test('select folder with closed parent', function() { 25 test('select folder with closed parent', function() {
25 var action; 26 var action;
26 var nextState; 27 var nextState;
27 // Close '0' 28 // Close '1'
28 action = bookmarks.actions.changeFolderOpen('0', false); 29 action = bookmarks.actions.changeFolderOpen('1', false);
29 nextState = bookmarks.ClosedFolderState.updateClosedFolders( 30 nextState = bookmarks.ClosedFolderState.updateClosedFolders(
30 initialState, action, nodes); 31 initialState, action, nodes);
31 assertTrue(nextState['0']); 32 assertTrue(nextState['1']);
33 assertFalse(!!nextState['2']);
32 34
33 // Should re-open when '1' is selected. 35 // Should re-open when '2' is selected.
34 action = bookmarks.actions.selectFolder('1'); 36 action = bookmarks.actions.selectFolder('2');
35 nextState = bookmarks.ClosedFolderState.updateClosedFolders( 37 nextState = bookmarks.ClosedFolderState.updateClosedFolders(
36 nextState, action, nodes); 38 nextState, action, nodes);
37 assertFalse(nextState['0']); 39 assertFalse(!!nextState['1']);
38 }); 40 });
39 }); 41 });
40 42
41 suite('selected folder', function() { 43 suite('selected folder', function() {
42 var nodes; 44 var nodes;
43 var initialState; 45 var initialState;
44 46
45 setup(function() { 47 setup(function() {
46 nodes = testTree(createFolder('0', [ 48 nodes = testTree(createFolder('1', [
47 createFolder('1', []), 49 createFolder('2', []),
48 ])); 50 ]));
49 51
50 initialState = '0'; 52 initialState = '1';
51 }); 53 });
52 54
53 test('updates from selectFolder action', function() { 55 test('updates from selectFolder action', function() {
54 var action = bookmarks.actions.selectFolder('1'); 56 var action = bookmarks.actions.selectFolder('2');
55 var newState = bookmarks.SelectedFolderState.updateSelectedFolder( 57 var newState = bookmarks.SelectedFolderState.updateSelectedFolder(
56 initialState, action, nodes); 58 initialState, action, nodes);
57 assertEquals('1', newState); 59 assertEquals('2', newState);
58 }); 60 });
59 61
60 test('updates when parent of selected folder is closed', function() { 62 test('updates when parent of selected folder is closed', function() {
61 var action; 63 var action;
62 var newState; 64 var newState;
63 65
64 action = bookmarks.actions.selectFolder('1'); 66 action = bookmarks.actions.selectFolder('2');
65 newState = bookmarks.SelectedFolderState.updateSelectedFolder( 67 newState = bookmarks.SelectedFolderState.updateSelectedFolder(
66 initialState, action, nodes); 68 initialState, action, nodes);
67 69
68 action = bookmarks.actions.changeFolderOpen('0', false); 70 action = bookmarks.actions.changeFolderOpen('1', false);
69 newState = bookmarks.SelectedFolderState.updateSelectedFolder( 71 newState = bookmarks.SelectedFolderState.updateSelectedFolder(
70 newState, action, nodes); 72 newState, action, nodes);
71 assertEquals('0', newState); 73 assertEquals('1', newState);
72 }); 74 });
73 }); 75 });
74 76
75 suite('node state', function() { 77 suite('node state', function() {
76 var initialState; 78 var initialState;
77 79
78 setup(function() { 80 setup(function() {
79 initialState = testTree(createFolder('0', [ 81 initialState = testTree(
80 createFolder( 82 createFolder(
81 '1', 83 '1',
82 [ 84 [
83 createItem('2', {title: 'a', url: 'a.com'}), 85 createItem('2', {title: 'a', url: 'a.com'}),
84 createItem('3'), 86 createItem('3'),
85 createFolder('4', []), 87 createFolder('4', []),
86 ]), 88 ]),
87 createFolder('5', []), 89 createFolder('5', []));
88 ]));
89 }); 90 });
90 91
91 test('updates when a node is edited', function() { 92 test('updates when a node is edited', function() {
92 var action = bookmarks.actions.editBookmark('2', {title: 'b'}); 93 var action = bookmarks.actions.editBookmark('2', {title: 'b'});
93 var nextState = bookmarks.NodeState.updateNodes(initialState, action); 94 var nextState = bookmarks.NodeState.updateNodes(initialState, action);
94 95
95 assertEquals('b', nextState['2'].title); 96 assertEquals('b', nextState['2'].title);
96 assertEquals('a.com', nextState['2'].url); 97 assertEquals('a.com', nextState['2'].url);
97 98
98 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'}); 99 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'});
(...skipping 19 matching lines...) Expand all
118 test('updates when a node is deleted', function() { 119 test('updates when a node is deleted', function() {
119 var action = bookmarks.actions.removeBookmark('3', '1', 1); 120 var action = bookmarks.actions.removeBookmark('3', '1', 1);
120 var nextState = bookmarks.NodeState.updateNodes(initialState, action); 121 var nextState = bookmarks.NodeState.updateNodes(initialState, action);
121 122
122 assertDeepEquals(['2', '4'], nextState['1'].children); 123 assertDeepEquals(['2', '4'], nextState['1'].children);
123 124
124 // TODO(tsergeant): Deleted nodes should be removed from the nodes map 125 // TODO(tsergeant): Deleted nodes should be removed from the nodes map
125 // entirely. 126 // entirely.
126 }); 127 });
127 }); 128 });
129
130 suite('search state', function() {
131 var state;
132
133 setup(function() {
134 // Search touches a few different things, so we test using the entire state:
135 state = bookmarks.util.createEmptyState();
136 state.nodes = testTree(createFolder('1', [
137 createFolder(
138 '2',
139 [
140 createItem('3'),
141 ]),
142 ]));
143 });
144
145 test('updates when search is started and finished', function() {
146 var action;
147
148 action = bookmarks.actions.selectFolder('2');
149 state = bookmarks.reduceAction(state, action);
150
151 action = bookmarks.actions.setSearchTerm('test');
152 state = bookmarks.reduceAction(state, action);
153
154 assertEquals('test', state.search.term);
155 assertTrue(state.search.inProgress);
156
157 // UI should not have changed yet:
158 assertEquals('2', state.selectedFolder);
159 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(state));
160
161 action = bookmarks.actions.setSearchResults(['2', '3']);
162 var searchedState = bookmarks.reduceAction(state, action);
163
164 assertFalse(searchedState.search.inProgress);
165
166 // UI changes once search results arrive:
167 assertEquals(null, searchedState.selectedFolder);
168 assertDeepEquals(
169 ['2', '3'], bookmarks.util.getDisplayedList(searchedState));
170
171 // Case 1: Clear search by setting an empty search term.
172 action = bookmarks.actions.setSearchTerm('');
173 var clearedState = bookmarks.reduceAction(searchedState, action);
174
175 assertEquals('1', clearedState.selectedFolder);
176 assertDeepEquals(['2'], bookmarks.util.getDisplayedList(clearedState));
177 assertEquals('', clearedState.search.term);
178 assertDeepEquals([], clearedState.search.results);
179
180 // Case 2: Clear search by selecting a new folder.
181 action = bookmarks.actions.selectFolder('2');
182 var selectedState = bookmarks.reduceAction(searchedState, action);
183
184 assertEquals('2', selectedState.selectedFolder);
185 assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState));
186 assertEquals('', selectedState.search.term);
187 assertDeepEquals([], selectedState.search.results);
188 });
189 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/item_test.js ('k') | chrome/test/data/webui/md_bookmarks/sidebar_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698