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

Unified Diff: chrome/test/data/webui/md_bookmarks/reducers_test.js

Issue 2752223004: MD Bookmarks: Remove deleted nodes from state tree (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 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 fdf838f646d5ba2536f59bcf84f7f58bfcb79380..5706dc8cb4ec9f717d8ee23fdf8fc2eb4982b7a0 100644
--- a/chrome/test/data/webui/md_bookmarks/reducers_test.js
+++ b/chrome/test/data/webui/md_bookmarks/reducers_test.js
@@ -87,6 +87,28 @@ suite('selection state', function() {
state = bookmarks.SelectionState.updateSelection(state, action);
assertDeepEquals({}, state.items);
});
+
+ test('deselects items when they are deleted', function() {
+ var nodeList = testTree(createFolder('0', [
+ createFolder(
+ '1',
+ [
+ createItem('2'),
+ createItem('3'),
+ createItem('4'),
+ ]),
+ createItem('5'),
+ ]));
+
+ action = select(['2', '4', '5'], '4', false);
+ state = bookmarks.SelectionState.updateSelection(state, action);
+
+ action = bookmarks.actions.removeBookmark('1', '0', 0, nodeList);
+ state = bookmarks.SelectionState.updateSelection(state, action);
+
+ assertDeepEquals(['5'], normalizeSet(state.items));
+ assertEquals(null, state.anchor);
+ });
});
suite('closed folder state', function() {
@@ -155,7 +177,12 @@ suite('selected folder', function() {
setup(function() {
nodes = testTree(createFolder('1', [
- createFolder('2', []),
+ createFolder(
+ '2',
+ [
+ createFolder('3', []),
+ createFolder('4', []),
+ ]),
]));
state = '1';
@@ -178,6 +205,30 @@ suite('selected folder', function() {
state, action, nodes);
assertEquals('1', state);
});
+
+ test('selects ancestor when selected folder is deleted', function() {
+ action = bookmarks.actions.selectFolder('3');
+ state = bookmarks.SelectedFolderState.updateSelectedFolder(
+ state, action, nodes);
+
+ // Delete the selected folder:
+ action = bookmarks.actions.removeBookmark('3', '2', 0, nodes);
+ state = bookmarks.SelectedFolderState.updateSelectedFolder(
+ state, action, nodes);
+
+ assertEquals('2', state);
+
+ action = bookmarks.actions.selectFolder('4');
+ state = bookmarks.SelectedFolderState.updateSelectedFolder(
+ state, action, nodes);
+
+ // Delete an ancestor of the selected folder:
+ action = bookmarks.actions.removeBookmark('2', '1', 0, nodes);
+ state = bookmarks.SelectedFolderState.updateSelectedFolder(
+ state, action, nodes);
+
+ assertEquals('1', state);
+ });
});
suite('node state', function() {
@@ -224,13 +275,20 @@ suite('node state', function() {
});
test('updates when a node is deleted', function() {
- action = bookmarks.actions.removeBookmark('3', '1', 1);
+ action = bookmarks.actions.removeBookmark('3', '1', 1, state);
state = bookmarks.NodeState.updateNodes(state, action);
assertDeepEquals(['2', '4'], state['1'].children);
- // TODO(tsergeant): Deleted nodes should be removed from the nodes map
- // entirely.
+ assertDeepEquals(['2', '4'], state['1'].children);
+ assertEquals(undefined, state['3']);
+ });
+
+ test('removes all children of deleted nodes', function() {
+ action = bookmarks.actions.removeBookmark('1', '0', 0, state);
+ state = bookmarks.NodeState.updateNodes(state, action);
+
+ assertDeepEquals(['0', '5'], Object.keys(state).sort());
});
test('updates when a node is moved', function() {
@@ -314,4 +372,21 @@ suite('search state', function() {
assertEquals('', selectedState.search.term);
assertDeepEquals([], selectedState.search.results);
});
+
+ test('removes deleted nodes', function() {
+ var action;
+
+ action = bookmarks.actions.setSearchTerm('test');
+ state = bookmarks.reduceAction(state, action);
+
+ action = bookmarks.actions.setSearchResults(['1', '3', '2']);
+ state = bookmarks.reduceAction(state, action);
+
+ action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes);
+ state = bookmarks.reduceAction(state, action);
+
+ // 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of
+ // 2.
+ assertDeepEquals(['1'], state.search.results);
+ });
});
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/md_bookmarks_browsertest.js ('k') | chrome/test/data/webui/md_bookmarks/util_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698