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

Side by Side Diff: chrome/test/data/webui/md_bookmarks/actions_test.js

Issue 2813503002: MD Bookmarks: Prevent navigating to invalid folders (Closed)
Patch Set: Add positive test case 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 unified diff | Download patch
OLDNEW
(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/or 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 });
27
28 test('can select single item', function() {
29 action = bookmarks.actions.selectItem('2', true, false, store.data);
30 var expected = {
31 name: 'select-items',
32 items: ['2'],
33 add: true,
34 anchor: '2',
35 };
36 assertDeepEquals(expected, action);
37 });
38
39 test('can shift-select in regular list', function() {
40 store.data.selection.anchor = '2';
41 action = bookmarks.actions.selectItem('4', false, true, store.data);
42
43 assertDeepEquals(['2', '8', '4'], action.items);
44 assertDeepEquals('4', action.anchor);
45 });
46
47 test('can shift-select in search results', function() {
48 store.data.selectedFolder = null;
49 store.data.search = {
50 term: 'test',
51 results: ['1', '4', '8'],
52 inProgress: false,
53 };
54 store.data.selection.anchor = '8';
55
56 action = bookmarks.actions.selectItem('4', false, true, store.data);
57
58 assertDeepEquals(['4', '8'], action.items);
59 });
60
61 test('selects the item when the anchor is missing', function() {
62 // Anchor hasn't been set yet.
63 store.data.selection.anchor = null;
64
65 action = bookmarks.actions.selectItem('4', true, true, store.data);
66 assertEquals('4', action.anchor);
67 assertDeepEquals(['4'], action.items);
68
69 // Anchor set to an item which doesn't exist.
70 store.data.selection.anchor = '42';
71
72 action = bookmarks.actions.selectItem('8', true, true, store.data);
73 assertEquals('8', action.anchor);
74 assertDeepEquals(['8'], action.items);
75 });
76 });
77
78 test('selectFolder prevents selecting invalid nodes', function() {
79 var nodes = testTree(createFolder('1', [
80 createItem('2'),
81 ]));
82
83 var action = bookmarks.actions.selectFolder(ROOT_NODE_ID, nodes);
84 assertEquals('no-op', action.name);
85
86 action = bookmarks.actions.selectFolder('2', nodes);
87 assertEquals('no-op', action.name);
88
89 action = bookmarks.actions.selectFolder('42', nodes);
90 assertEquals('no-op', action.name);
91
92 action = bookmarks.actions.selectFolder('1', nodes);
93 assertEquals('select-folder', action.name);
94 assertEquals('1', action.id);
95 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698