| 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 /** |
| 6 * @fileoverview Test suite for action creators that depend on the page state |
| 7 * and have non-trivial logic. |
| 8 */ |
| 9 |
| 10 suite('selectItem', function() { |
| 11 var store; |
| 12 var action; |
| 13 |
| 14 setup(function() { |
| 15 store = new bookmarks.TestStore({ |
| 16 nodes: testTree(createFolder( |
| 17 '1', |
| 18 [ |
| 19 createItem('2'), |
| 20 createItem('8'), |
| 21 createFolder('4', []), |
| 22 createItem('6'), |
| 23 ])), |
| 24 selectedFolder: '1', |
| 25 }); |
| 26 bookmarks.Store.instance_ = store; |
| 27 }); |
| 28 |
| 29 test('can select single item', function() { |
| 30 action = bookmarks.actions.selectItem('2', true, false); |
| 31 var expected = { |
| 32 name: 'select-items', |
| 33 items: ['2'], |
| 34 add: true, |
| 35 anchor: '2', |
| 36 }; |
| 37 assertDeepEquals(expected, action); |
| 38 }); |
| 39 |
| 40 test('can shift-select in regular list', function() { |
| 41 store.data.selection.anchor = '2'; |
| 42 action = bookmarks.actions.selectItem('4', false, true); |
| 43 |
| 44 assertDeepEquals(['2', '8', '4'], action.items); |
| 45 assertDeepEquals('4', action.anchor); |
| 46 }); |
| 47 |
| 48 test('can shift-select in search results', function() { |
| 49 store.data.selectedFolder = null; |
| 50 store.data.search = { |
| 51 term: 'test', |
| 52 results: ['1', '4', '8'], |
| 53 inProgress: false, |
| 54 }; |
| 55 store.data.selection.anchor = '8'; |
| 56 |
| 57 action = bookmarks.actions.selectItem('4', false, true); |
| 58 |
| 59 assertDeepEquals(['4', '8'], action.items); |
| 60 }); |
| 61 |
| 62 test('selects the item when the anchor is missing', function() { |
| 63 // Anchor hasn't been set yet. |
| 64 store.data.selection.anchor = null; |
| 65 |
| 66 action = bookmarks.actions.selectItem('4', true, true); |
| 67 assertEquals('4', action.anchor); |
| 68 assertDeepEquals(['4'], action.items); |
| 69 |
| 70 // Anchor set to an item which doesn't exist. |
| 71 store.data.selection.anchor = '42'; |
| 72 |
| 73 action = bookmarks.actions.selectItem('8', true, true); |
| 74 assertEquals('8', action.anchor); |
| 75 assertDeepEquals(['8'], action.items); |
| 76 }); |
| 77 }); |
| OLD | NEW |