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

Unified 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 comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/md_bookmarks/reducers_test.js
diff --git a/chrome/test/data/webui/md_bookmarks/reducers_test.js b/chrome/test/data/webui/md_bookmarks/reducers_test.js
index 381515db879ce1f401f76f614031c314edd5fcb2..8309c99987dc340cba505b8ecb38348cf5b5d3c8 100644
--- a/chrome/test/data/webui/md_bookmarks/reducers_test.js
+++ b/chrome/test/data/webui/md_bookmarks/reducers_test.js
@@ -7,34 +7,34 @@ suite('closed folder state', function() {
var initialState;
calamity 2017/03/14 03:32:18 Can we also ditch all the other initialStates in t
tsergeant 2017/03/14 05:51:10 TODO added
setup(function() {
- nodes = testTree(createFolder('0', [
- createFolder('1', []),
+ nodes = testTree(createFolder('1', [
+ createFolder('2', []),
]));
initialState = {};
});
test('toggle folder open state', function() {
- var action = bookmarks.actions.changeFolderOpen('1', false);
+ var action = bookmarks.actions.changeFolderOpen('2', false);
var nextState = bookmarks.ClosedFolderState.updateClosedFolders(
initialState, action, nodes);
- assertTrue(nextState['1']);
- assertFalse(!!nextState['0']);
+ assertTrue(nextState['2']);
+ assertFalse(!!nextState['1']);
calamity 2017/03/14 03:32:18 nit: reverse these 2 lines.
tsergeant 2017/03/14 05:51:10 Done.
});
test('select folder with closed parent', function() {
var action;
var nextState;
- // Close '0'
- action = bookmarks.actions.changeFolderOpen('0', false);
+ // Close '1'
+ action = bookmarks.actions.changeFolderOpen('1', false);
nextState = bookmarks.ClosedFolderState.updateClosedFolders(
initialState, action, nodes);
- assertTrue(nextState['0']);
+ assertTrue(nextState['1']);
calamity 2017/03/14 03:32:18 May as well also check '2's state here since there
tsergeant 2017/03/14 05:51:10 Done.
- // Should re-open when '1' is selected.
- action = bookmarks.actions.selectFolder('1');
+ // Should re-open when '2' is selected.
+ action = bookmarks.actions.selectFolder('2');
nextState = bookmarks.ClosedFolderState.updateClosedFolders(
nextState, action, nodes);
- assertFalse(nextState['0']);
+ assertFalse(!!nextState['1']);
});
});
@@ -43,32 +43,32 @@ suite('selected folder', function() {
var initialState;
setup(function() {
- nodes = testTree(createFolder('0', [
- createFolder('1', []),
+ nodes = testTree(createFolder('1', [
+ createFolder('2', []),
]));
- initialState = '0';
+ initialState = '1';
});
test('updates from selectFolder action', function() {
- var action = bookmarks.actions.selectFolder('1');
+ var action = bookmarks.actions.selectFolder('2');
var newState = bookmarks.SelectedFolderState.updateSelectedFolder(
initialState, action, nodes);
- assertEquals('1', newState);
+ assertEquals('2', newState);
});
test('updates when parent of selected folder is closed', function() {
var action;
var newState;
- action = bookmarks.actions.selectFolder('1');
+ action = bookmarks.actions.selectFolder('2');
newState = bookmarks.SelectedFolderState.updateSelectedFolder(
initialState, action, nodes);
- action = bookmarks.actions.changeFolderOpen('0', false);
+ action = bookmarks.actions.changeFolderOpen('1', false);
newState = bookmarks.SelectedFolderState.updateSelectedFolder(
newState, action, nodes);
- assertEquals('0', newState);
+ assertEquals('1', newState);
});
});
@@ -76,16 +76,15 @@ suite('node state', function() {
var initialState;
setup(function() {
- initialState = testTree(createFolder('0', [
- createFolder(
- '1',
- [
- createItem('2', {title: 'a', url: 'a.com'}),
- createItem('3'),
- createFolder('4', []),
- ]),
- createFolder('5', []),
- ]));
+ initialState = testTree(
+ createFolder(
+ '1',
+ [
+ createItem('2', {title: 'a', url: 'a.com'}),
+ createItem('3'),
+ createFolder('4', []),
+ ]),
+ createFolder('5', []));
});
test('updates when a node is edited', function() {
@@ -125,3 +124,64 @@ suite('node state', function() {
// entirely.
});
});
+
+suite('search state', function() {
+ var state;
+
+ setup(function() {
+ // Search touches a few different things, so we test using the entire state:
+ state = bookmarks.util.createEmptyState();
+ state.nodes = testTree(createFolder('1', [
+ createFolder(
+ '2',
+ [
+ createItem('3'),
+ ]),
+ ]));
+ });
+
+ test('updates when search is started and finished', function() {
+ var action;
+
+ action = bookmarks.actions.selectFolder('2');
+ state = bookmarks.reduceAction(state, action);
+
+ action = bookmarks.actions.setSearchTerm('test');
+ state = bookmarks.reduceAction(state, action);
+
+ assertEquals('test', state.search.term);
+ assertTrue(state.search.inProgress);
+
+ // UI should not have changed yet:
+ assertEquals('2', state.selectedFolder);
+ assertDeepEquals(['3'], bookmarks.util.getDisplayedList(state));
+
+ action = bookmarks.actions.setSearchResults(['2', '3']);
+ var searchedState = bookmarks.reduceAction(state, action);
+
+ assertFalse(searchedState.search.inProgress);
+
+ // UI changes once search results arrive:
+ assertEquals(null, searchedState.selectedFolder);
+ assertDeepEquals(
+ ['2', '3'], bookmarks.util.getDisplayedList(searchedState));
+
+ // Case 1: Clear search by setting an empty search term.
+ action = bookmarks.actions.setSearchTerm('');
+ var clearedState = bookmarks.reduceAction(searchedState, action);
+
+ assertEquals('1', clearedState.selectedFolder);
+ assertDeepEquals(['2'], bookmarks.util.getDisplayedList(clearedState));
+ assertEquals('', clearedState.search.term);
+ assertDeepEquals([], clearedState.search.results);
+
+ // Case 2: Clear search by selecting a new folder.
+ action = bookmarks.actions.selectFolder('2');
+ var selectedState = bookmarks.reduceAction(searchedState, action);
+
+ assertEquals('2', selectedState.selectedFolder);
+ assertDeepEquals(['3'], bookmarks.util.getDisplayedList(selectedState));
+ assertEquals('', selectedState.search.term);
+ assertDeepEquals([], selectedState.search.results);
+ });
+});

Powered by Google App Engine
This is Rietveld 408576698