| 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 74e828be14de0cc864ad7783845a93df9da672aa..2740eaaeb8c0a44b21bc972ea258b5c7c52b30e3 100644
|
| --- a/chrome/test/data/webui/md_bookmarks/reducers_test.js
|
| +++ b/chrome/test/data/webui/md_bookmarks/reducers_test.js
|
| @@ -84,42 +84,6 @@ suite('selection state', function() {
|
| });
|
| });
|
|
|
| -suite('closed folder state', function() {
|
| - var nodes;
|
| - var initialState;
|
| -
|
| - setup(function() {
|
| - nodes = testTree(createFolder('0', [
|
| - createFolder('1', []),
|
| - ]));
|
| - initialState = {};
|
| - });
|
| -
|
| - test('toggle folder open state', function() {
|
| - var action = bookmarks.actions.changeFolderOpen('1', false);
|
| - var nextState = bookmarks.ClosedFolderState.updateClosedFolders(
|
| - initialState, action, nodes);
|
| - assertTrue(nextState['1']);
|
| - assertFalse(!!nextState['0']);
|
| - });
|
| -
|
| - test('select folder with closed parent', function() {
|
| - var action;
|
| - var nextState;
|
| - // Close '0'
|
| - action = bookmarks.actions.changeFolderOpen('0', false);
|
| - nextState = bookmarks.ClosedFolderState.updateClosedFolders(
|
| - initialState, action, nodes);
|
| - assertTrue(nextState['0']);
|
| -
|
| - // Should re-open when '1' is selected.
|
| - action = bookmarks.actions.selectFolder('1');
|
| - nextState = bookmarks.ClosedFolderState.updateClosedFolders(
|
| - nextState, action, nodes);
|
| - assertFalse(nextState['0']);
|
| - });
|
| -});
|
| -
|
| suite('selected folder', function() {
|
| var nodes;
|
| var initialState;
|
| @@ -255,3 +219,185 @@ suite('search', function() {
|
| assertDeepEquals([], selectedState.search.results);
|
| });
|
| });
|
| +
|
| +suite('sidebar', function() {
|
| + var initialState;
|
| + var state;
|
| + var action;
|
| +
|
| + var assertFolderPropertyTrue = function(property, expected) {
|
| + var folderPropertyMap = {};
|
| + var open = {};
|
| + var count = 0;
|
| + state.sidebar.folders.forEach((folder) => {
|
| + folderPropertyMap[folder.id] = folder[property];
|
| + if (folder[property])
|
| + count++;
|
| + });
|
| + expected.forEach((id) => {
|
| + assertTrue(folderPropertyMap[id]);
|
| + });
|
| + assertEquals(expected.length, count);
|
| + };
|
| +
|
| + setup(function() {
|
| + initialState = bookmarks.util.createEmptyState();
|
| + initialState.nodes = testTree(createFolder('0', [
|
| + createFolder(
|
| + '1',
|
| + [
|
| + createFolder('2', []),
|
| + ]),
|
| + createFolder('3', []),
|
| + ]));
|
| + initialState.sidebar =
|
| + bookmarks.util.initializeSidebar('0', initialState.nodes);
|
| + state = initialState;
|
| + });
|
| +
|
| + test('toggle folder open state', function() {
|
| + action = bookmarks.actions.changeFolderOpen('1', false);
|
| + state = bookmarks.reduceAction(state, action);
|
| +
|
| + assertFolderPropertyTrue('visible', ['1', '3']);
|
| + assertFolderPropertyTrue('open', ['2', '3']);
|
| + });
|
| +
|
| + test('select folder with closed parent', function() {
|
| + // Close '1'
|
| + action = bookmarks.actions.changeFolderOpen('1', false);
|
| + state = bookmarks.reduceAction(state, action);
|
| + assertFolderPropertyTrue('visible', ['1', '3']);
|
| + assertFolderPropertyTrue('open', ['2', '3']);
|
| +
|
| + // Should re-open when '2' is selected.
|
| + action = bookmarks.actions.selectFolder('2');
|
| + state = bookmarks.reduceAction(state, action);
|
| + assertFolderPropertyTrue('visible', ['1', '2', '3']);
|
| + assertFolderPropertyTrue('open', ['1', '2', '3']);
|
| + });
|
| +
|
| + test('complex open close select', function() {
|
| + initialState.nodes = testTree(createFolder('0', [
|
| + createFolder(
|
| + '1',
|
| + [
|
| + createFolder('2', []),
|
| + createFolder(
|
| + '3',
|
| + [
|
| + createFolder('4', []),
|
| + ]),
|
| + ]),
|
| + createFolder(
|
| + '5',
|
| + [
|
| + createFolder('6', []),
|
| + createFolder('7', []),
|
| + ]),
|
| + ]));
|
| + initialState.sidebar =
|
| + bookmarks.util.initializeSidebar('0', initialState.nodes);
|
| +
|
| + state = initialState;
|
| +
|
| + // Close '3'
|
| + action = bookmarks.actions.changeFolderOpen('3', false);
|
| + state = bookmarks.reduceAction(state, action);
|
| + assertFolderPropertyTrue('visible', ['1', '2', '3', '5', '6', '7']);
|
| + assertFolderPropertyTrue('open', ['1', '2', '4', '5', '6', '7']);
|
| +
|
| + // Close '1'
|
| + action = bookmarks.actions.changeFolderOpen('1', false);
|
| + state = bookmarks.reduceAction(state, action);
|
| + assertFolderPropertyTrue('visible', ['1', '5', '6', '7']);
|
| + assertFolderPropertyTrue('open', ['2', '4', '5', '6', '7']);
|
| +
|
| + // Close '5'
|
| + action = bookmarks.actions.changeFolderOpen('5', false);
|
| + state = bookmarks.reduceAction(state, action);
|
| + assertFolderPropertyTrue('visible', ['1', '5']);
|
| + assertFolderPropertyTrue('open', ['2', '4', '6', '7']);
|
| +
|
| + // 1' should re-open when '3' is selected.
|
| + action = bookmarks.actions.selectFolder('3');
|
| + state = bookmarks.reduceAction(state, action);
|
| + assertFolderPropertyTrue('visible', ['1', '2', '3', '5']);
|
| + assertFolderPropertyTrue('open', ['1', '2', '4', '6', '7']);
|
| + });
|
| +
|
| + test('updates when a node is deleted', function() {
|
| + action = bookmarks.actions.removeBookmark('2', '1', 1);
|
| + state = bookmarks.reduceAction(state, action);
|
| +
|
| + assertDeepEquals(
|
| + [
|
| + {id: '1', depth: 0, open: true, visible: true},
|
| + {id: '3', depth: 0, open: true, visible: true},
|
| + ],
|
| + state.sidebar.folders);
|
| + assertEquals(undefined, state.sidebar.folderMap['2']);
|
| + });
|
| +
|
| + test('modifications for updating visibility', function() {
|
| + initialState.nodes = testTree(createFolder('0', [
|
| + createFolder(
|
| + '1',
|
| + [
|
| + createFolder('2', []),
|
| + createFolder(
|
| + '3',
|
| + [
|
| + createFolder('4', []),
|
| + ]),
|
| + ]),
|
| + createFolder(
|
| + '5',
|
| + [
|
| + createFolder('6', []),
|
| + createFolder('7', []),
|
| + ]),
|
| + ]));
|
| + initialState.sidebar =
|
| + bookmarks.util.initializeSidebar('0', initialState.nodes);
|
| +
|
| + // Closing '3' should only change '4'.
|
| + assertDeepEquals(
|
| + ['4'],
|
| + Object.values(bookmarks.SidebarState
|
| + .updateVisibleFoldersBelowNode(state.sidebar.folders, 2, false))
|
| + .map((m) => m.id));
|
| +
|
| + action = bookmarks.actions.changeFolderOpen('3', false);
|
| + state = bookmarks.reduceAction(state, action);
|
| +
|
| + // Closing '1' should only change '2' and '3'.
|
| + assertDeepEquals(
|
| + ['2', '3'],
|
| + Object.values(bookmarks.SidebarState
|
| + .updateVisibleFoldersBelowNode(state.sidebar.folders, 0, false))
|
| + .map((m) => m.id));
|
| +
|
| + action = bookmarks.actions.changeFolderOpen('1', false);
|
| + state = bookmarks.reduceAction(state, action);
|
| +
|
| + // Opening '3' should have no effect.
|
| + assertDeepEquals(
|
| + [],
|
| + Object.values(bookmarks.SidebarState
|
| + .updateVisibleFoldersBelowNode(state.sidebar.folders, 2, true)));
|
| +
|
| + action = bookmarks.actions.changeFolderOpen('3', true);
|
| + state = bookmarks.reduceAction(state, action);
|
| +
|
| + // Opening '1' should change '2', '3', and '4'.
|
| + assertDeepEquals(
|
| + ['2', '3', '4'],
|
| + Object.values(bookmarks.SidebarState
|
| + .updateVisibleFoldersBelowNode(state.sidebar.folders, 0, true))
|
| + .map((m) => m.id));
|
| +
|
| + action = bookmarks.actions.changeFolderOpen('1', true);
|
| + state = bookmarks.reduceAction(state, action);
|
| + });
|
| +});
|
|
|