OLD | NEW |
---|---|
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-sidebar>', function() { | 5 suite('<bookmarks-folder-node>', function() { |
tsergeant
2017/04/19 07:39:28
Looks like this file didn't get deleted when it sh
calamity
2017/04/26 08:03:54
Done.
tsergeant
2017/04/26 23:47:55
This file still shows up as 'M' in Rietveld instea
| |
6 var sidebar; | 6 var rootNode; |
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( | 11 nodes: testTree( |
12 createFolder( | 12 createFolder( |
13 '1', | 13 '1', |
14 [ | 14 [ |
15 createFolder( | 15 createFolder( |
16 '2', | 16 '2', |
17 [ | 17 [ |
18 createFolder('3', []), | 18 createFolder('3', []), |
19 createFolder('4', []), | 19 createFolder('4', []), |
20 ]), | 20 ]), |
21 createItem('5'), | 21 createItem('5'), |
22 ]), | 22 ]), |
23 createFolder('7', [])), | 23 createFolder('7', [])), |
24 }); | 24 }); |
25 bookmarks.Store.instance_ = store; | 25 bookmarks.Store.instance_ = store; |
26 | 26 |
27 sidebar = document.createElement('bookmarks-sidebar'); | 27 rootNode = document.createElement('bookmarks-folder-node'); |
28 replaceBody(sidebar); | 28 rootNode.itemId = '0'; |
29 rootNode.depth = -1; | |
30 replaceBody(rootNode); | |
29 Polymer.dom.flush(); | 31 Polymer.dom.flush(); |
30 }); | 32 }); |
31 | 33 |
32 test('selecting and deselecting folders dispatches action', function() { | 34 test('selecting and deselecting folders dispatches action', function() { |
33 var rootFolders = | 35 var rootFolders = rootNode.root.querySelectorAll('bookmarks-folder-node'); |
34 sidebar.$['folder-tree'].querySelectorAll('bookmarks-folder-node'); | |
35 var firstGen = rootFolders[0].$['descendants'].querySelectorAll( | 36 var firstGen = rootFolders[0].$['descendants'].querySelectorAll( |
36 'bookmarks-folder-node'); | 37 'bookmarks-folder-node'); |
37 var secondGen = | 38 var secondGen = |
38 firstGen[0].$['descendants'].querySelectorAll('bookmarks-folder-node'); | 39 firstGen[0].$['descendants'].querySelectorAll('bookmarks-folder-node'); |
39 | 40 |
40 // Select nested folder. | 41 // Select nested folder. |
41 firedId = ''; | 42 firedId = ''; |
42 MockInteractions.tap(secondGen[0].$['folder-label']); | 43 MockInteractions.tap(secondGen[0].$['folder-label']); |
43 assertEquals('select-folder', store.lastAction.name); | 44 assertEquals('select-folder', store.lastAction.name); |
44 assertEquals(secondGen[0].itemId, store.lastAction.id); | 45 assertEquals(secondGen[0].itemId, store.lastAction.id); |
45 | 46 |
46 // Select folder in a separate subtree. | 47 // Select folder in a separate subtree. |
47 firedId = ''; | 48 firedId = ''; |
48 MockInteractions.tap(rootFolders[1].$['folder-label']); | 49 MockInteractions.tap(rootFolders[1].$['folder-label']); |
49 assertEquals('select-folder', store.lastAction.name); | 50 assertEquals('select-folder', store.lastAction.name); |
50 assertEquals(rootFolders[1].itemId, store.lastAction.id); | 51 assertEquals(rootFolders[1].itemId, store.lastAction.id); |
51 }); | 52 }); |
52 | 53 |
53 test('depth calculation', function() { | 54 test('depth calculation', function() { |
54 var rootFolders = | 55 var rootFolders = rootNode.root.querySelectorAll('bookmarks-folder-node'); |
55 sidebar.$['folder-tree'].querySelectorAll('bookmarks-folder-node'); | |
56 var firstGen = rootFolders[0].$['descendants'].querySelectorAll( | 56 var firstGen = rootFolders[0].$['descendants'].querySelectorAll( |
57 'bookmarks-folder-node'); | 57 'bookmarks-folder-node'); |
58 var secondGen = | 58 var secondGen = |
59 firstGen[0].$['descendants'].querySelectorAll('bookmarks-folder-node'); | 59 firstGen[0].$['descendants'].querySelectorAll('bookmarks-folder-node'); |
60 | 60 |
61 Array.prototype.forEach.call(rootFolders, function(f) { | 61 Array.prototype.forEach.call(rootFolders, function(f) { |
62 assertEquals(0, f.depth); | 62 assertEquals(0, f.depth); |
63 assertEquals('0', f.style.getPropertyValue('--node-depth')); | 63 assertEquals('0', f.style.getPropertyValue('--node-depth')); |
64 }); | 64 }); |
65 Array.prototype.forEach.call(firstGen, function(f) { | 65 Array.prototype.forEach.call(firstGen, function(f) { |
66 assertEquals(1, f.depth); | 66 assertEquals(1, f.depth); |
67 assertEquals('1', f.style.getPropertyValue('--node-depth')); | 67 assertEquals('1', f.style.getPropertyValue('--node-depth')); |
68 }); | 68 }); |
69 Array.prototype.forEach.call(secondGen, function(f) { | 69 Array.prototype.forEach.call(secondGen, function(f) { |
70 assertEquals(2, f.depth); | 70 assertEquals(2, f.depth); |
71 assertEquals('2', f.style.getPropertyValue('--node-depth')); | 71 assertEquals('2', f.style.getPropertyValue('--node-depth')); |
72 }); | 72 }); |
73 }); | 73 }); |
74 | 74 |
75 test('doesn\'t highlight selected folder while searching', function() { | 75 test('doesn\'t highlight selected folder while searching', function() { |
76 var rootFolders = | 76 var rootFolders = rootNode.root.querySelectorAll('bookmarks-folder-node'); |
77 sidebar.$['folder-tree'].querySelectorAll('bookmarks-folder-node'); | |
78 | 77 |
79 store.data.selectedFolder = '1'; | 78 store.data.selectedFolder = '1'; |
80 store.notifyObservers(); | 79 store.notifyObservers(); |
81 | 80 |
82 assertEquals('1', rootFolders['0'].itemId); | 81 assertEquals('1', rootFolders['0'].itemId); |
83 assertTrue(rootFolders['0'].isSelectedFolder_); | 82 assertTrue(rootFolders['0'].isSelectedFolder_); |
84 | 83 |
85 store.data.search = { | 84 store.data.search = { |
86 term: 'test', | 85 term: 'test', |
87 inProgress: false, | 86 inProgress: false, |
88 results: ['3'], | 87 results: ['3'], |
89 }; | 88 }; |
90 store.notifyObservers(); | 89 store.notifyObservers(); |
91 | 90 |
92 assertFalse(rootFolders['0'].isSelectedFolder_); | 91 assertFalse(rootFolders['0'].isSelectedFolder_); |
93 }); | 92 }); |
94 }); | 93 }); |
OLD | NEW |