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-list>', function() { | 5 suite('<bookmarks-list>', function() { |
6 var list; | 6 var list; |
7 var TEST_LIST = | 7 var store; |
8 [createItem('0'), createItem('1'), createFolder('2', [], null)]; | |
9 | 8 |
10 setup(function() { | 9 setup(function() { |
| 10 store = new bookmarks.TestStore({ |
| 11 nodes: testTree(createFolder( |
| 12 '0', |
| 13 [ |
| 14 createItem('1'), |
| 15 createFolder('3', []), |
| 16 createItem('5'), |
| 17 createItem('7'), |
| 18 ])), |
| 19 selectedFolder: '0', |
| 20 }); |
| 21 bookmarks.Store.instance_ = store; |
| 22 |
11 list = document.createElement('bookmarks-list'); | 23 list = document.createElement('bookmarks-list'); |
12 replaceBody(list); | 24 replaceBody(list); |
13 list.displayedList = TEST_LIST; | 25 Polymer.dom.flush(); |
14 }); | 26 }); |
15 | 27 |
16 test('folder menu item hides the url field', function() { | 28 test('folder menu item hides the url field', function() { |
17 // Bookmark editor shows the url field. | 29 // Bookmark editor shows the url field. |
18 list.menuItem_ = TEST_LIST[0]; | 30 list.menuItem_ = store.data.nodes['1']; |
19 assertFalse(list.$['url'].hidden); | 31 assertFalse(list.$['url'].hidden); |
20 | 32 |
21 // Folder editor hides the url field. | 33 // Folder editor hides the url field. |
22 list.menuItem_ = TEST_LIST[2]; | 34 list.menuItem_ = store.data.nodes['3']; |
23 assertTrue(list.$['url'].hidden); | 35 assertTrue(list.$['url'].hidden); |
24 }); | 36 }); |
25 | 37 |
26 test('saving edit passes correct details to the update', function() { | 38 test('saving edit passes correct details to the update', function() { |
27 // Saving bookmark edit. | 39 // Saving bookmark edit. |
28 var menuItem = TEST_LIST[0]; | 40 var menuItem = store.data.nodes['1']; |
29 chrome.bookmarks.update = function(id, edit) { | 41 chrome.bookmarks.update = function(id, edit) { |
30 assertEquals(menuItem.id, id); | 42 assertEquals(menuItem.id, id); |
31 assertEquals(menuItem.url, edit.url); | 43 assertEquals(menuItem.url, edit.url); |
32 assertEquals(menuItem.title, edit.title); | 44 assertEquals(menuItem.title, edit.title); |
33 }; | 45 }; |
34 list.menuItem_ = menuItem; | 46 list.menuItem_ = menuItem; |
35 list.$.editBookmark.showModal(); | 47 list.$.editBookmark.showModal(); |
36 MockInteractions.tap(list.$.saveButton); | 48 MockInteractions.tap(list.$.saveButton); |
37 | 49 |
38 // Saving folder rename. | 50 // Saving folder rename. |
39 menuItem = TEST_LIST[2]; | 51 menuItem = store.data.nodes['3']; |
40 chrome.bookmarks.update = function(id, edit) { | 52 chrome.bookmarks.update = function(id, edit) { |
41 assertEquals(menuItem.id, id); | 53 assertEquals(menuItem.id, id); |
42 assertEquals(menuItem.title, edit.title); | 54 assertEquals(menuItem.title, edit.title); |
43 assertEquals(undefined, edit.url); | 55 assertEquals(undefined, edit.url); |
44 }; | 56 }; |
45 list.menuItem_ = menuItem; | 57 list.menuItem_ = menuItem; |
46 list.$.editBookmark.showModal(); | 58 list.$.editBookmark.showModal(); |
47 MockInteractions.tap(list.$.saveButton); | 59 MockInteractions.tap(list.$.saveButton); |
48 }); | 60 }); |
| 61 |
| 62 test('renders correct <bookmark-item> elements', function() { |
| 63 var items = list.root.querySelectorAll('bookmarks-item'); |
| 64 var ids = Array.from(items).map((item) => item.itemId); |
| 65 |
| 66 assertDeepEquals(['1', '3', '5', '7'], ids); |
| 67 }); |
49 }); | 68 }); |
OLD | NEW |