| 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 /** @fileoverview Suite of tests for extension-item. */ | 5 /** @fileoverview Suite of tests for extension-item. */ |
| 6 cr.define('extension_item_list_tests', function() { | 6 cr.define('extension_item_list_tests', function() { |
| 7 /** @enum {string} */ | 7 /** @enum {string} */ |
| 8 var TestNames = { | 8 var TestNames = { |
| 9 ItemListFiltering: 'item list filtering', | 9 ItemListFiltering: 'item list filtering', |
| 10 ItemListNoItemsMsg: 'empty item list', |
| 11 ItemListNoSearchResultsMsg: 'empty item list filtering results', |
| 10 }; | 12 }; |
| 11 | 13 |
| 12 function registerTests() { | 14 function registerTests() { |
| 13 suite('ExtensionItemListTest', function() { | 15 suite('ExtensionItemListTest', function() { |
| 14 /** @type {extensions.ItemList} */ | 16 /** @type {extensions.ItemList} */ |
| 15 var itemList; | 17 var itemList; |
| 18 var testVisible; |
| 16 | 19 |
| 17 suiteSetup(function() { | 20 suiteSetup(function() { |
| 18 return PolymerTest.importHtml('chrome://extensions/item-list.html'); | 21 return PolymerTest.importHtml('chrome://extensions/item-list.html'); |
| 19 }); | 22 }); |
| 20 | 23 |
| 21 // Initialize an extension item before each test. | 24 // Initialize an extension item before each test. |
| 22 setup(function() { | 25 setup(function() { |
| 23 PolymerTest.clearBody(); | 26 PolymerTest.clearBody(); |
| 24 itemList = new extensions.ItemList(); | 27 itemList = new extensions.ItemList(); |
| 28 testVisible = extension_test_util.testVisible.bind(null, itemList); |
| 29 |
| 25 var createExt = extension_test_util.createExtensionInfo; | 30 var createExt = extension_test_util.createExtensionInfo; |
| 26 var items = | 31 var items = |
| 27 [createExt({name: 'Alpha', id: 'a'.repeat(32)}), | 32 [createExt({name: 'Alpha', id: 'a'.repeat(32)}), |
| 28 createExt({name: 'Bravo', id: 'b'.repeat(32)}), | 33 createExt({name: 'Bravo', id: 'b'.repeat(32)}), |
| 29 createExt({name: 'Charlie', id: 'c'.repeat(32)})]; | 34 createExt({name: 'Charlie', id: 'c'.repeat(32)})]; |
| 30 itemList.items = items; | 35 itemList.items = items; |
| 31 itemList.filter = ''; | 36 itemList.filter = ''; |
| 32 document.body.appendChild(itemList); | 37 document.body.appendChild(itemList); |
| 33 }); | 38 }); |
| 34 | 39 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 53 itemList.filter = 'lph'; | 58 itemList.filter = 'lph'; |
| 54 expectEquals(1, ironList.items.length); | 59 expectEquals(1, ironList.items.length); |
| 55 expectEquals('Alpha', ironList.items[0].name); | 60 expectEquals('Alpha', ironList.items[0].name); |
| 56 // Test string with no matching items. | 61 // Test string with no matching items. |
| 57 itemList.filter = 'z'; | 62 itemList.filter = 'z'; |
| 58 expectEquals(0, ironList.items.length); | 63 expectEquals(0, ironList.items.length); |
| 59 // A filter of '' should reset to show all items. | 64 // A filter of '' should reset to show all items. |
| 60 itemList.filter = ''; | 65 itemList.filter = ''; |
| 61 expectEquals(3, ironList.items.length); | 66 expectEquals(3, ironList.items.length); |
| 62 }); | 67 }); |
| 68 |
| 69 test(assert(TestNames.ItemListNoItemsMsg), function() { |
| 70 testVisible('#no-items', false); |
| 71 testVisible('#no-search-results', false); |
| 72 |
| 73 itemList.items = []; |
| 74 testVisible('#no-items', true); |
| 75 testVisible('#no-search-results', false); |
| 76 }); |
| 77 |
| 78 test(assert(TestNames.ItemListNoSearchResultsMsg), function() { |
| 79 testVisible('#no-items', false); |
| 80 testVisible('#no-search-results', false); |
| 81 |
| 82 itemList.filter = 'non-existent name'; |
| 83 testVisible('#no-items', false); |
| 84 testVisible('#no-search-results', true); |
| 85 }); |
| 63 }); | 86 }); |
| 64 } | 87 } |
| 65 | 88 |
| 66 return { | 89 return { |
| 67 registerTests: registerTests, | 90 registerTests: registerTests, |
| 68 TestNames: TestNames, | 91 TestNames: TestNames, |
| 69 }; | 92 }; |
| 70 }); | 93 }); |
| OLD | NEW |