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

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

Issue 2888863002: [MD Bookmarks] Refine mouse selection (Closed)
Patch Set: 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() {
40 var items = list.root.querySelectorAll('bookmarks-item');
41
42 customClick(items[0]);
43
44 assertEquals('select-items', store.lastAction.name);
45 assertFalse(store.lastAction.add);
46 assertEquals('1', store.lastAction.anchor);
47 assertDeepEquals(['1'], store.lastAction.items);
48
49 store.data.selection.anchor = '1';
50 customClick(items[2], {shiftKey: true, ctrlKey: true});
51
52 assertEquals('select-items', store.lastAction.name);
53 assertTrue(store.lastAction.add);
54 assertEquals('5', store.lastAction.anchor);
55 assertDeepEquals(['1', '3', '5'], store.lastAction.items);
56 });
57
58 test('deselects items on click outside of card', function() { 39 test('deselects items on click outside of card', function() {
59 customClick(list); 40 customClick(list);
60 assertEquals('deselect-items', store.lastAction.name); 41 assertEquals('deselect-items', store.lastAction.name);
61 }); 42 });
62 43
63 test('adds, deletes, and moves update displayedList_', function() { 44 test('adds, deletes, and moves update displayedList_', function() {
64 list.displayedIds_ = ['1', '7', '3', '5']; 45 list.displayedIds_ = ['1', '7', '3', '5'];
65 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id)); 46 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id));
66 47
67 list.displayedIds_ = ['1', '3', '5']; 48 list.displayedIds_ = ['1', '3', '5'];
68 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id)); 49 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id));
69 50
70 list.displayedIds_ = ['1', '3', '7', '5']; 51 list.displayedIds_ = ['1', '3', '7', '5'];
71 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id)); 52 assertDeepEquals(list.displayedIds_, list.displayedList_.map(n => n.id));
72 }); 53 });
73 }); 54 });
55
56 suite('<bookmarks-list> integration test', function() {
57 var list;
58 var store;
59 var items;
60
61 setup(function() {
62 store = new bookmarks.TestStore({
63 nodes: testTree(createFolder(
64 '10',
65 [
66 createItem('1'),
67 createFolder('3', []),
68 createItem('5'),
69 createItem('7'),
70 createItem('9'),
71 ])),
72 selectedFolder: '10',
73 });
74 bookmarks.Store.instance_ = store;
75 store.setReducersEnabled(true);
76
77 list = document.createElement('bookmarks-list');
78 list.style.height = '100%';
79 list.style.width = '100%';
80 list.style.position= 'absolute';
81
82 replaceBody(list);
83 Polymer.dom.flush();
84
85 items = list.root.querySelectorAll('bookmarks-item');
86 });
87
88 test('shift-selects multiple items', function() {
89 customClick(items[1]);
90 assertDeepEquals(['3'], normalizeSet(store.data.selection.items));
91 assertDeepEquals('3', store.data.selection.anchor);
92
93 customClick(items[3], {shiftKey: true});
94 assertDeepEquals(['3', '5', '7'], normalizeSet(store.data.selection.items));
95 assertDeepEquals('3', store.data.selection.anchor);
96
97 customClick(items[0], {shiftKey: true});
98 assertDeepEquals(['1', '3'], normalizeSet(store.data.selection.items));
99 assertDeepEquals('3', store.data.selection.anchor);
100 });
101
102 test('ctrl toggles multiple items', function() {
103 customClick(items[1]);
104 assertDeepEquals(['3'], normalizeSet(store.data.selection.items));
105 assertDeepEquals('3', store.data.selection.anchor);
106
107 customClick(items[3], {ctrlKey: true});
108 assertDeepEquals(['3', '7'], normalizeSet(store.data.selection.items));
109 assertDeepEquals('7', store.data.selection.anchor);
110
111 customClick(items[1], {ctrlKey: true});
112 assertDeepEquals(['7'], normalizeSet(store.data.selection.items));
113 assertDeepEquals('3', store.data.selection.anchor);
114 });
115
116 test('ctrl+shift adds ranges to selection', function() {
117 customClick(items[0]);
118 assertDeepEquals(['1'], normalizeSet(store.data.selection.items));
119 assertDeepEquals('1', store.data.selection.anchor);
120
121 customClick(items[2], {ctrlKey: true});
122 assertDeepEquals(['1', '5'], normalizeSet(store.data.selection.items));
123 assertDeepEquals('5', store.data.selection.anchor);
124
125 customClick(items[4], {ctrlKey: true, shiftKey: true});
126 assertDeepEquals(
127 ['1', '5', '7', '9'], normalizeSet(store.data.selection.items));
128 assertDeepEquals('5', store.data.selection.anchor);
129
130 customClick(items[0], {ctrlKey: true, shiftKey: true});
131 assertDeepEquals(
132 ['1', '3', '5', '7', '9'], normalizeSet(store.data.selection.items));
133 assertDeepEquals('5', store.data.selection.anchor);
134 });
135 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698