| 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', [], null), |
| 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']; |
| 41 // TODO(tsergeant): Avoid overwriting these functions directly. |
| 29 chrome.bookmarks.update = function(id, edit) { | 42 chrome.bookmarks.update = function(id, edit) { |
| 30 assertEquals(menuItem.id, id); | 43 assertEquals(menuItem.id, id); |
| 31 assertEquals(menuItem.url, edit.url); | 44 assertEquals(menuItem.url, edit.url); |
| 32 assertEquals(menuItem.title, edit.title); | 45 assertEquals(menuItem.title, edit.title); |
| 33 }; | 46 }; |
| 34 list.menuItem_ = menuItem; | 47 list.menuItem_ = menuItem; |
| 35 list.$.editBookmark.showModal(); | 48 list.$.editBookmark.showModal(); |
| 36 MockInteractions.tap(list.$.saveButton); | 49 MockInteractions.tap(list.$.saveButton); |
| 37 | 50 |
| 38 // Saving folder rename. | 51 // Saving folder rename. |
| 39 menuItem = TEST_LIST[2]; | 52 menuItem = store.data.nodes['3']; |
| 40 chrome.bookmarks.update = function(id, edit) { | 53 chrome.bookmarks.update = function(id, edit) { |
| 41 assertEquals(menuItem.id, id); | 54 assertEquals(menuItem.id, id); |
| 42 assertEquals(menuItem.title, edit.title); | 55 assertEquals(menuItem.title, edit.title); |
| 43 assertEquals(undefined, edit.url); | 56 assertEquals(undefined, edit.url); |
| 44 }; | 57 }; |
| 45 list.menuItem_ = menuItem; | 58 list.menuItem_ = menuItem; |
| 46 list.$.editBookmark.showModal(); | 59 list.$.editBookmark.showModal(); |
| 47 MockInteractions.tap(list.$.saveButton); | 60 MockInteractions.tap(list.$.saveButton); |
| 48 }); | 61 }); |
| 62 |
| 63 test('renders correct <bookmark-item> elements', function() { |
| 64 var items = list.root.querySelectorAll('bookmarks-item'); |
| 65 var ids = Array.from(items).map((item) => item.itemId); |
| 66 |
| 67 assertDeepEquals(['1', '3', '5', '7'], ids); |
| 68 }); |
| 69 |
| 70 test('selects individual items', function() { |
| 71 var items = list.root.querySelectorAll('bookmarks-item'); |
| 72 |
| 73 customClick(items[0]); |
| 74 var expected = { |
| 75 name: 'select-items', |
| 76 add: false, |
| 77 anchor: '1', |
| 78 items: ['1'], |
| 79 }; |
| 80 assertDeepEquals(expected, store.lastAction); |
| 81 |
| 82 customClick(items[2], {ctrlKey: true}); |
| 83 expected.add = true; |
| 84 expected.anchor = '5'; |
| 85 expected.items = ['5']; |
| 86 assertDeepEquals(expected, store.lastAction); |
| 87 }); |
| 88 |
| 89 test('shift-selects multiple items', function() { |
| 90 var items = list.root.querySelectorAll('bookmarks-item'); |
| 91 store.data.selection.anchor = '1'; |
| 92 |
| 93 customClick(items[2], {shiftKey: true}); |
| 94 |
| 95 assertEquals('select-items', store.lastAction.name); |
| 96 assertFalse(store.lastAction.add); |
| 97 assertEquals('5', store.lastAction.anchor); |
| 98 assertDeepEquals(['1', '3', '5'], store.lastAction.items); |
| 99 }); |
| 49 }); | 100 }); |
| OLD | NEW |