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