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

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

Issue 2888863002: [MD Bookmarks] Refine mouse selection (Closed)
Patch Set: address comments Created 3 years, 7 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 suite('<bookmarks-list>', function() { 5 suite('<bookmarks-list>', function() {
6 var list; 6 var list;
7 var store; 7 var store;
8 8
9 setup(function() { 9 setup(function() {
10 store = new bookmarks.TestStore({ 10 store = new bookmarks.TestStore({
11 nodes: testTree(createFolder( 11 nodes: testTree(createFolder(
12 '0', 12 '10',
13 [ 13 [
14 createItem('1'), 14 createItem('1'),
15 createFolder('3', []), 15 createFolder('3', []),
16 createItem('5'), 16 createItem('5'),
17 createItem('7'), 17 createItem('7'),
18 ])), 18 ])),
19 selectedFolder: '0', 19 selectedFolder: '10',
20 }); 20 });
21 bookmarks.Store.instance_ = store; 21 bookmarks.Store.instance_ = store;
22 22
23 list = document.createElement('bookmarks-list'); 23 list = document.createElement('bookmarks-list');
24 list.style.height = '100%'; 24 list.style.height = '100%';
25 list.style.width = '100%'; 25 list.style.width = '100%';
26 list.style.position= 'absolute'; 26 list.style.position= 'absolute';
27 27
28 replaceBody(list); 28 replaceBody(list);
29 Polymer.dom.flush(); 29 Polymer.dom.flush();
30 }); 30 });
31 31
32 test('renders correct <bookmark-item> elements', function() { 32 test('renders correct <bookmark-item> elements', function() {
33 var items = list.root.querySelectorAll('bookmarks-item'); 33 var items = list.root.querySelectorAll('bookmarks-item');
34 var ids = Array.from(items).map((item) => item.itemId); 34 var ids = Array.from(items).map((item) => item.itemId);
35 35
36 assertDeepEquals(['1', '3', '5', '7'], ids); 36 assertDeepEquals(['1', '3', '5', '7'], ids);
37 }); 37 });
38 38
39 test('shift-selects multiple items', function() { 39 test('shift-selects multiple items', function() {
40 var items = list.root.querySelectorAll('bookmarks-item'); 40 var items = list.root.querySelectorAll('bookmarks-item');
41 41
42 customClick(items[0]); 42 customClick(items[0]);
43 43
44 assertEquals('select-items', store.lastAction.name); 44 assertEquals('select-items', store.lastAction.name);
45 assertFalse(store.lastAction.add); 45 assertTrue(store.lastAction.clear);
46 assertEquals('1', store.lastAction.anchor); 46 assertEquals('1', store.lastAction.anchor);
47 assertDeepEquals(['1'], store.lastAction.items); 47 assertDeepEquals(['1'], store.lastAction.items);
48 48
49 store.data.selection.anchor = '1'; 49 store.data.selection.anchor = '1';
50 customClick(items[2], {shiftKey: true, ctrlKey: true}); 50 customClick(items[2], {shiftKey: true, ctrlKey: true});
51 51
52 assertEquals('select-items', store.lastAction.name); 52 assertEquals('select-items', store.lastAction.name);
53 assertTrue(store.lastAction.add); 53 assertFalse(store.lastAction.clear);
54 assertEquals('1', store.lastAction.anchor); 54 assertEquals('1', store.lastAction.anchor);
55 assertDeepEquals(['1', '3', '5'], store.lastAction.items); 55 assertDeepEquals(['1', '3', '5'], store.lastAction.items);
56 }); 56 });
57 57
58 test('deselects items on click outside of card', function() { 58 test('deselects items on click outside of card', function() {
59 customClick(list); 59 customClick(list);
60 assertEquals('deselect-items', store.lastAction.name); 60 assertEquals('deselect-items', store.lastAction.name);
61 }); 61 });
62 62
63 test('adds, deletes, and moves update displayedList_', function() { 63 test('adds, deletes, and moves update displayedList_', function() {
64 list.displayedIds_ = ['1', '7', '3', '5']; 64 list.displayedIds_ = ['1', '7', '3', '5'];
65 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id)); 65 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id));
66 66
67 list.displayedIds_ = ['1', '3', '5']; 67 list.displayedIds_ = ['1', '3', '5'];
68 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id)); 68 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id));
69 69
70 list.displayedIds_ = ['1', '3', '7', '5']; 70 list.displayedIds_ = ['1', '3', '7', '5'];
71 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id)); 71 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id));
72 }); 72 });
73 }); 73 });
74
75 suite('<bookmarks-list> integration test', function() {
76 var list;
77 var store;
78 var items;
79
80 setup(function() {
81 store = new bookmarks.TestStore({
82 nodes: testTree(createFolder(
83 '10',
84 [
85 createItem('1'),
86 createFolder('3', []),
87 createItem('5'),
88 createItem('7'),
89 createItem('9'),
90 ])),
91 selectedFolder: '10',
92 });
93 bookmarks.Store.instance_ = store;
94 store.setReducersEnabled(true);
95
96 list = document.createElement('bookmarks-list');
97 list.style.height = '100%';
98 list.style.width = '100%';
99 list.style.position = 'absolute';
100
101 replaceBody(list);
102 Polymer.dom.flush();
103
104 items = list.root.querySelectorAll('bookmarks-item');
105 });
106
107 test('shift-selects multiple items', function() {
108 customClick(items[1]);
109 assertDeepEquals(['3'], normalizeSet(store.data.selection.items));
110 assertDeepEquals('3', store.data.selection.anchor);
111
112 customClick(items[3], {shiftKey: true});
113 assertDeepEquals(['3', '5', '7'], normalizeSet(store.data.selection.items));
114 assertDeepEquals('3', store.data.selection.anchor);
115
116 customClick(items[0], {shiftKey: true});
117 assertDeepEquals(['1', '3'], normalizeSet(store.data.selection.items));
118 assertDeepEquals('3', store.data.selection.anchor);
119 });
120
121 test('ctrl toggles multiple items', function() {
122 customClick(items[1]);
123 assertDeepEquals(['3'], normalizeSet(store.data.selection.items));
124 assertDeepEquals('3', store.data.selection.anchor);
125
126 customClick(items[3], {ctrlKey: true});
127 assertDeepEquals(['3', '7'], normalizeSet(store.data.selection.items));
128 assertDeepEquals('7', store.data.selection.anchor);
129
130 customClick(items[1], {ctrlKey: true});
131 assertDeepEquals(['7'], normalizeSet(store.data.selection.items));
132 assertDeepEquals('3', store.data.selection.anchor);
133 });
134
135 test('ctrl+shift adds ranges to selection', function() {
136 customClick(items[0]);
137 assertDeepEquals(['1'], normalizeSet(store.data.selection.items));
138 assertDeepEquals('1', store.data.selection.anchor);
139
140 customClick(items[2], {ctrlKey: true});
141 assertDeepEquals(['1', '5'], normalizeSet(store.data.selection.items));
142 assertDeepEquals('5', store.data.selection.anchor);
143
144 customClick(items[4], {ctrlKey: true, shiftKey: true});
145 assertDeepEquals(
146 ['1', '5', '7', '9'], normalizeSet(store.data.selection.items));
147 assertDeepEquals('5', store.data.selection.anchor);
148
149 customClick(items[0], {ctrlKey: true, shiftKey: true});
150 assertDeepEquals(
151 ['1', '3', '5', '7', '9'], normalizeSet(store.data.selection.items));
152 assertDeepEquals('5', store.data.selection.anchor);
153 });
154 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/item_test.js ('k') | chrome/test/data/webui/md_bookmarks/reducers_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698