Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 suite('closed folder state', function() { | |
| 6 var nodes; | |
| 7 var initialState; | |
| 8 | |
| 9 setup(function() { | |
| 10 nodes = testTree(createFolder('0', [ | |
| 11 createFolder('1', []), | |
| 12 ])); | |
| 13 initialState = {}; | |
| 14 }); | |
| 15 | |
| 16 test('toggle folder open state', function() { | |
| 17 var action = bookmarks.actions.changeFolderOpen('1', false); | |
| 18 var nextState = bookmarks.ClosedFolderState.updateClosedFolders( | |
| 19 initialState, action, nodes); | |
| 20 assertTrue(nextState['1']); | |
| 21 assertFalse(!!nextState['0']); | |
| 22 }); | |
| 23 | |
| 24 test('select folder with closed parent', function() { | |
| 25 var action; | |
| 26 var nextState; | |
| 27 // Close '0' | |
| 28 action = bookmarks.actions.changeFolderOpen('0', false); | |
| 29 nextState = bookmarks.ClosedFolderState.updateClosedFolders( | |
| 30 initialState, action, nodes); | |
| 31 assertTrue(nextState['0']); | |
| 32 | |
| 33 // Should re-open when '1' is selected. | |
| 34 action = bookmarks.actions.selectFolder('1'); | |
| 35 nextState = bookmarks.ClosedFolderState.updateClosedFolders( | |
| 36 nextState, action, nodes); | |
| 37 assertFalse(nextState['0']); | |
| 38 }); | |
| 39 }); | |
| 40 | |
| 41 suite('selected folder', function() { | |
| 42 var nodes; | |
| 43 var initialState; | |
| 44 | |
| 45 setup(function() { | |
| 46 nodes = testTree(createFolder('0', [ | |
| 47 createFolder('1', []), | |
| 48 ])); | |
| 49 | |
| 50 initialState = '0'; | |
| 51 }); | |
| 52 | |
| 53 test('updates from selectFolder action', function() { | |
| 54 var action = bookmarks.actions.selectFolder('1'); | |
| 55 var newState = bookmarks.SelectedFolderState.updateSelectedFolder( | |
| 56 initialState, action, nodes); | |
| 57 assertEquals('1', newState); | |
| 58 }); | |
| 59 | |
| 60 test('updates when parent of selected folder is closed', function() { | |
| 61 var action; | |
| 62 var newState; | |
| 63 | |
| 64 action = bookmarks.actions.selectFolder('1'); | |
| 65 newState = bookmarks.SelectedFolderState.updateSelectedFolder( | |
| 66 initialState, action, nodes); | |
| 67 | |
| 68 action = bookmarks.actions.changeFolderOpen('0', false); | |
| 69 newState = bookmarks.SelectedFolderState.updateSelectedFolder( | |
| 70 newState, action, nodes); | |
| 71 assertEquals('0', newState); | |
| 72 }); | |
| 73 }); | |
| 74 | |
| 75 suite('node state', function() { | |
| 76 var initialState; | |
| 77 | |
| 78 setup(function() { | |
| 79 initialState = testTree(createFolder('0', [ | |
| 80 createFolder( | |
| 81 '1', | |
| 82 [ | |
| 83 createItem('2', {title: 'a', url: 'a.com'}), | |
| 84 createItem('3'), | |
| 85 createFolder('4', []), | |
| 86 ]), | |
| 87 createFolder('5', []), | |
| 88 ])); | |
| 89 }); | |
| 90 | |
| 91 test('updates when a node is edited', function() { | |
|
calamity
2017/03/07 07:27:35
Does this include folders? If so, add an edit test
tsergeant
2017/03/08 02:47:11
Done. I've also added a check to make sure that fo
| |
| 92 var action = bookmarks.actions.editBookmark('2', {title: 'b'}); | |
| 93 var nextState = bookmarks.NodeState.updateNodes(initialState, action); | |
| 94 | |
| 95 assertEquals('b', nextState['2'].title); | |
| 96 assertEquals('a.com', nextState['2'].url); | |
| 97 | |
| 98 action = bookmarks.actions.editBookmark('2', {title: 'c', url: 'c.com'}); | |
| 99 nextState = bookmarks.NodeState.updateNodes(nextState, action); | |
| 100 | |
| 101 assertEquals('c', nextState['2'].title); | |
| 102 assertEquals('c.com', nextState['2'].url); | |
| 103 }); | |
| 104 | |
| 105 test('updates when a node is deleted', function() { | |
| 106 var action = bookmarks.actions.removeBookmark('3', '1', 1); | |
| 107 var nextState = bookmarks.NodeState.updateNodes(initialState, action); | |
| 108 | |
| 109 assertDeepEquals(['2', '4'], nextState['1'].children); | |
| 110 | |
| 111 // TODO(tsergeant): Deleted nodes should be removed from the nodes map | |
| 112 // entirely. | |
| 113 }); | |
| 114 }); | |
| OLD | NEW |