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

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

Issue 2804503002: MD Bookmarks: Allow 'complex' actions to access the page state directly (Closed)
Patch Set: Self-review 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 c4a34f7e50712e28310ea0633bbbf503086b9fe6..68b93882284aa9cd1f56183e05893410ad441dc4 100644
--- a/chrome/test/data/webui/md_bookmarks/reducers_test.js
+++ b/chrome/test/data/webui/md_bookmarks/reducers_test.js
@@ -2,19 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+/**
+ * Helper method for creating a 'remove-bookmark' action.
+ * @param {string} id
+ * @param {string} parentId
+ * @param {number} index
+ * @param {!Array<string>} descendants
+ * @return {!Action}
+ */
+function remove(id, parentId, index, descendants) {
+ descendants.push(id);
+ return bookmarks.actions.removeBookmarkSubtree(
+ id, parentId, index, new Set(descendants));
+}
+
suite('selection state', function() {
var state;
var action;
- function select(items, anchor, add) {
- return {
- name: 'select-items',
- add: add,
- anchor: anchor,
- items: items,
- };
- }
-
setup(function() {
state = {
anchor: null,
@@ -23,37 +28,37 @@ suite('selection state', function() {
});
test('can select an item', function() {
- action = select(['1'], '1', false);
+ action = bookmarks.actions.selectItemSet(['1'], '1', false);
state = bookmarks.SelectionState.updateSelection(state, action);
assertDeepEquals(['1'], normalizeSet(state.items));
assertEquals('1', state.anchor);
// Replace current selection.
- action = select(['2'], '2', false);
+ action = bookmarks.actions.selectItemSet(['2'], '2', false);
state = bookmarks.SelectionState.updateSelection(state, action);
assertDeepEquals(['2'], normalizeSet(state.items));
assertEquals('2', state.anchor);
// Add to current selection.
- action = select(['3'], '3', true);
+ action = bookmarks.actions.selectItemSet(['3'], '3', true);
state = bookmarks.SelectionState.updateSelection(state, action);
assertDeepEquals(['2', '3'], normalizeSet(state.items));
assertEquals('3', state.anchor);
});
test('can select multiple items', function() {
- action = select(['1', '2', '3'], '3', false);
+ action = bookmarks.actions.selectItemSet(['1', '2', '3'], '3', false);
state = bookmarks.SelectionState.updateSelection(state, action);
assertDeepEquals(['1', '2', '3'], normalizeSet(state.items));
- action = select(['3', '4'], '4', true);
+ action = bookmarks.actions.selectItemSet(['3', '4'], '4', true);
state = bookmarks.SelectionState.updateSelection(state, action);
assertDeepEquals(['1', '2', '3', '4'], normalizeSet(state.items));
});
test('is cleared when selected folder changes', function() {
- action = select(['1', '2', '3'], '3', false);
+ action = bookmarks.actions.selectItemSet(['1', '2', '3'], '3', false);
state = bookmarks.SelectionState.updateSelection(state, action);
action = bookmarks.actions.selectFolder('2');
@@ -62,7 +67,7 @@ suite('selection state', function() {
});
test('is cleared when search finished', function() {
- action = select(['1', '2', '3'], '3', false);
+ action = bookmarks.actions.selectItemSet(['1', '2', '3'], '3', false);
state = bookmarks.SelectionState.updateSelection(state, action);
action = bookmarks.actions.setSearchResults(['2']);
@@ -71,7 +76,7 @@ suite('selection state', function() {
});
test('is cleared when search cleared', function() {
- action = select(['1', '2', '3'], '3', false);
+ action = bookmarks.actions.selectItemSet(['1', '2', '3'], '3', false);
state = bookmarks.SelectionState.updateSelection(state, action);
action = bookmarks.actions.clearSearch();
@@ -80,7 +85,7 @@ suite('selection state', function() {
});
test('deselect items', function() {
- action = select(['1', '2', '3'], '3', false);
+ action = bookmarks.actions.selectItemSet(['1', '2', '3'], '3', false);
state = bookmarks.SelectionState.updateSelection(state, action);
action = bookmarks.actions.deselectItems();
@@ -100,10 +105,10 @@ suite('selection state', function() {
createItem('5'),
]));
- action = select(['2', '4', '5'], '4', false);
+ action = bookmarks.actions.selectItemSet(['2', '4', '5'], '4', false);
state = bookmarks.SelectionState.updateSelection(state, action);
- action = bookmarks.actions.removeBookmark('1', '0', 0, nodeList);
+ action = remove('1', '0', 0, ['2', '3', '4']);
state = bookmarks.SelectionState.updateSelection(state, action);
assertDeepEquals(['5'], normalizeSet(state.items));
@@ -212,7 +217,7 @@ suite('selected folder', function() {
state, action, nodes);
// Delete the selected folder:
- action = bookmarks.actions.removeBookmark('3', '2', 0, nodes);
+ action = remove('3', '2', 0, []);
state = bookmarks.SelectedFolderState.updateSelectedFolder(
state, action, nodes);
@@ -223,7 +228,7 @@ suite('selected folder', function() {
state, action, nodes);
// Delete an ancestor of the selected folder:
- action = bookmarks.actions.removeBookmark('2', '1', 0, nodes);
+ action = remove('2', '1', 0, ['3']);
state = bookmarks.SelectedFolderState.updateSelectedFolder(
state, action, nodes);
@@ -305,7 +310,7 @@ suite('node state', function() {
});
test('updates when a node is deleted', function() {
- action = bookmarks.actions.removeBookmark('3', '1', 1, state);
+ action = remove('3', '1', 1, []);
state = bookmarks.NodeState.updateNodes(state, action);
assertDeepEquals(['2', '4'], state['1'].children);
@@ -315,7 +320,7 @@ suite('node state', function() {
});
test('removes all children of deleted nodes', function() {
- action = bookmarks.actions.removeBookmark('1', '0', 0, state);
+ action = remove('1', '0', 0, ['2', '3', '4']);
state = bookmarks.NodeState.updateNodes(state, action);
assertDeepEquals(['0', '5'], Object.keys(state).sort());
@@ -412,7 +417,7 @@ suite('search state', function() {
action = bookmarks.actions.setSearchResults(['1', '3', '2']);
state = bookmarks.reduceAction(state, action);
- action = bookmarks.actions.removeBookmark('2', '1', 0, state.nodes);
+ action = remove('2', '1', 0, ['3']);
state = bookmarks.reduceAction(state, action);
// 2 and 3 should be removed, since 2 was deleted and 3 was a descendant of

Powered by Google App Engine
This is Rietveld 408576698