| 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 cr.define('settings_main_page', function() { |
| 6 /** |
| 7 * @implements {SearchManager} |
| 8 */ |
| 9 var TestSearchManager = function() { |
| 10 /** @private {boolean} */ |
| 11 this.matchesFound_ = true; |
| 12 |
| 13 /** @private {?settings.SearchRequest} */ |
| 14 this.searchRequest_ = null; |
| 15 } |
| 16 |
| 17 TestSearchManager.prototype = { |
| 18 /** |
| 19 * @param {boolean} matchesFound |
| 20 */ |
| 21 setMatchesFound: function(matchesFound) { |
| 22 this.matchesFound_ = matchesFound; |
| 23 }, |
| 24 |
| 25 /** @override */ |
| 26 search: function(text, page) { |
| 27 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) { |
| 28 this.searchRequest_ = new settings.SearchRequest(text); |
| 29 this.searchRequest_.finished = true; |
| 30 this.searchRequest_.updateMatches(this.matchesFound_); |
| 31 this.searchRequest_.resolver.resolve(this.searchRequest_); |
| 32 } |
| 33 return this.searchRequest_.resolver.promise; |
| 34 }, |
| 35 }; |
| 36 |
| 37 function registerTests() { |
| 38 var settingsPrefs = null; |
| 39 |
| 40 suiteSetup(function() { |
| 41 settingsPrefs = document.createElement('settings-prefs'); |
| 42 }); |
| 43 |
| 44 suite('SearchTests', function() { |
| 45 /** @type {?TestSearchManager} */ |
| 46 var searchManager = null; |
| 47 |
| 48 /** @type {?SettingsMainElement} */ |
| 49 var settingsMain = null; |
| 50 |
| 51 // TODO(tommycli): Remove once settings.navigateTo is no longer a stub. |
| 52 settings.navigateTo = function(route) { |
| 53 settingsMain.currentRoute = route; |
| 54 }; |
| 55 |
| 56 setup(function() { |
| 57 searchManager = new TestSearchManager(); |
| 58 settings.setSearchManagerForTesting(searchManager); |
| 59 PolymerTest.clearBody(); |
| 60 settingsMain = document.createElement('settings-main'); |
| 61 settingsMain.prefs = settingsPrefs.prefs; |
| 62 settingsMain.toolbarSpinnerActive = false; |
| 63 document.body.appendChild(settingsMain); |
| 64 }); |
| 65 |
| 66 teardown(function() { settingsMain.remove(); }); |
| 67 |
| 68 test('no results page shows and hides', function() { |
| 69 var noSearchResults = settingsMain.$.noSearchResults; |
| 70 assertTrue(!!noSearchResults); |
| 71 assertTrue(noSearchResults.hidden); |
| 72 |
| 73 searchManager.setMatchesFound(false); |
| 74 return settingsMain.searchContents('Query1').then(function() { |
| 75 assertFalse(noSearchResults.hidden); |
| 76 |
| 77 searchManager.setMatchesFound(true); |
| 78 return settingsMain.searchContents('Query2'); |
| 79 }).then(function() { |
| 80 assertTrue(noSearchResults.hidden); |
| 81 }); |
| 82 }); |
| 83 |
| 84 // Ensure that when the user clears the search box, the "no results" page |
| 85 // is hidden. |
| 86 test('no results page hides on clear', function() { |
| 87 var noSearchResults = settingsMain.$.noSearchResults; |
| 88 assertTrue(!!noSearchResults); |
| 89 assertTrue(noSearchResults.hidden); |
| 90 searchManager.setMatchesFound(false); |
| 91 |
| 92 // Clearing the search box is effectively a search for the empty string. |
| 93 return settingsMain.searchContents('').then(function() { |
| 94 assertTrue(noSearchResults.hidden); |
| 95 }); |
| 96 }); |
| 97 }); |
| 98 } |
| 99 |
| 100 return { |
| 101 registerTests: registerTests, |
| 102 }; |
| 103 }); |
| OLD | NEW |