OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Test suite for action creators that depend on the page state | 6 * @fileoverview Test suite for action creators that depend on the page state |
7 * and/or have non-trivial logic. | 7 * and/or have non-trivial logic. |
8 */ | 8 */ |
9 | 9 |
10 suite('selectItem', function() { | 10 suite('selectItem', function() { |
11 var store; | 11 var store; |
12 var action; | 12 var action; |
13 | 13 |
14 setup(function() { | 14 setup(function() { |
15 store = new bookmarks.TestStore({ | 15 store = new bookmarks.TestStore({ |
16 nodes: testTree(createFolder( | 16 nodes: testTree(createFolder( |
17 '1', | 17 '1', |
18 [ | 18 [ |
19 createItem('2'), | 19 createItem('2'), |
20 createItem('8'), | 20 createItem('8'), |
21 createFolder('4', []), | 21 createFolder('4', []), |
22 createItem('6'), | 22 createItem('6'), |
23 ])), | 23 ])), |
24 selectedFolder: '1', | 24 selectedFolder: '1', |
25 }); | 25 }); |
26 }); | 26 }); |
27 | 27 |
28 test('can select single item', function() { | 28 test('can select single item', function() { |
29 action = bookmarks.actions.selectItem('2', true, false, store.data); | 29 action = bookmarks.actions.selectItem('2', store.data, { |
| 30 clear: false, |
| 31 range: false, |
| 32 toggle: false, |
| 33 }); |
30 var expected = { | 34 var expected = { |
31 name: 'select-items', | 35 name: 'select-items', |
32 items: ['2'], | 36 items: ['2'], |
33 add: true, | 37 clear: false, |
| 38 toggle: false, |
34 anchor: '2', | 39 anchor: '2', |
35 }; | 40 }; |
36 assertDeepEquals(expected, action); | 41 assertDeepEquals(expected, action); |
37 }); | 42 }); |
38 | 43 |
39 test('can shift-select in regular list', function() { | 44 test('can shift-select in regular list', function() { |
40 store.data.selection.anchor = '2'; | 45 store.data.selection.anchor = '2'; |
41 action = bookmarks.actions.selectItem('4', false, true, store.data); | 46 action = bookmarks.actions.selectItem('4', store.data, { |
| 47 clear: true, |
| 48 range: true, |
| 49 toggle: false, |
| 50 }); |
42 | 51 |
43 assertDeepEquals(['2', '8', '4'], action.items); | 52 assertDeepEquals(['2', '8', '4'], action.items); |
44 // Shift-selection doesn't change anchor. | 53 // Shift-selection doesn't change anchor. |
45 assertDeepEquals('2', action.anchor); | 54 assertDeepEquals('2', action.anchor); |
46 }); | 55 }); |
47 | 56 |
48 test('can shift-select in search results', function() { | 57 test('can shift-select in search results', function() { |
49 store.data.selectedFolder = null; | 58 store.data.selectedFolder = null; |
50 store.data.search = { | 59 store.data.search = { |
51 term: 'test', | 60 term: 'test', |
52 results: ['1', '4', '8'], | 61 results: ['1', '4', '8'], |
53 inProgress: false, | 62 inProgress: false, |
54 }; | 63 }; |
55 store.data.selection.anchor = '8'; | 64 store.data.selection.anchor = '8'; |
56 | 65 |
57 action = bookmarks.actions.selectItem('4', false, true, store.data); | 66 action = bookmarks.actions.selectItem('4', store.data, { |
| 67 clear: true, |
| 68 range: true, |
| 69 toggle: false, |
| 70 }); |
58 | 71 |
59 assertDeepEquals(['4', '8'], action.items); | 72 assertDeepEquals(['4', '8'], action.items); |
60 }); | 73 }); |
61 | 74 |
62 test('selects the item when the anchor is missing', function() { | 75 test('selects the item when the anchor is missing', function() { |
63 // Anchor hasn't been set yet. | 76 // Anchor hasn't been set yet. |
64 store.data.selection.anchor = null; | 77 store.data.selection.anchor = null; |
65 | 78 |
66 action = bookmarks.actions.selectItem('4', true, true, store.data); | 79 action = bookmarks.actions.selectItem('4', store.data, { |
| 80 clear: false, |
| 81 range: true, |
| 82 toggle: false, |
| 83 }); |
67 assertEquals('4', action.anchor); | 84 assertEquals('4', action.anchor); |
68 assertDeepEquals(['4'], action.items); | 85 assertDeepEquals(['4'], action.items); |
69 | 86 |
70 // Anchor set to an item which doesn't exist. | 87 // Anchor set to an item which doesn't exist. |
71 store.data.selection.anchor = '42'; | 88 store.data.selection.anchor = '42'; |
72 | 89 |
73 action = bookmarks.actions.selectItem('8', true, true, store.data); | 90 action = bookmarks.actions.selectItem('8', store.data, { |
| 91 clear: false, |
| 92 range: true, |
| 93 toggle: false, |
| 94 }); |
74 assertEquals('8', action.anchor); | 95 assertEquals('8', action.anchor); |
75 assertDeepEquals(['8'], action.items); | 96 assertDeepEquals(['8'], action.items); |
76 }); | 97 }); |
77 }); | 98 }); |
78 | 99 |
79 test('selectFolder prevents selecting invalid nodes', function() { | 100 test('selectFolder prevents selecting invalid nodes', function() { |
80 var nodes = testTree(createFolder('1', [ | 101 var nodes = testTree(createFolder('1', [ |
81 createItem('2'), | 102 createItem('2'), |
82 ])); | 103 ])); |
83 | 104 |
84 var action = bookmarks.actions.selectFolder(ROOT_NODE_ID, nodes); | 105 var action = bookmarks.actions.selectFolder(ROOT_NODE_ID, nodes); |
85 assertEquals(null, action); | 106 assertEquals(null, action); |
86 | 107 |
87 action = bookmarks.actions.selectFolder('2', nodes); | 108 action = bookmarks.actions.selectFolder('2', nodes); |
88 assertEquals(null, action); | 109 assertEquals(null, action); |
89 | 110 |
90 action = bookmarks.actions.selectFolder('42', nodes); | 111 action = bookmarks.actions.selectFolder('42', nodes); |
91 assertEquals(null, action); | 112 assertEquals(null, action); |
92 | 113 |
93 action = bookmarks.actions.selectFolder('1', nodes); | 114 action = bookmarks.actions.selectFolder('1', nodes); |
94 assertEquals('select-folder', action.name); | 115 assertEquals('select-folder', action.name); |
95 assertEquals('1', action.id); | 116 assertEquals('1', action.id); |
96 }); | 117 }); |
OLD | NEW |