Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Side by Side Diff: chrome/test/data/webui/settings/settings_main_test.js

Issue 2185493003: MD Settings: Adding some unit tests for <settings-main>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@search_no_results
Patch Set: Nit. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
14 TestSearchManager.prototype = {
15 /**
16 * @param {boolean} matchesFound
17 */
18 setMatchesFound: function(matchesFound) {
19 this.matchesFound_ = matchesFound;
20 },
21
22 /** @override */
23 search: function(text, page) {
24 var searchRequest = new settings.SearchRequest(text);
25 searchRequest.finished = true;
26 searchRequest.updateMatches(this.matchesFound_);
27 searchRequest.resolver.resolve(searchRequest);
28 return searchRequest.resolver.promise;
29 },
30 };
31
32 function registerTests() {
michaelpg 2016/07/30 05:38:44 nit: new tests shouldn't use the cr.define/registe
dpapad 2016/08/02 22:33:15 Unfortunately removing the registerTests() call, m
33 var settingsPrefs = null;
34
35 suiteSetup(function() {
36 settingsPrefs = document.createElement('settings-prefs');
37 });
38
39 suite('SearchTests', function() {
40 /** @type {?TestSearchManager} */
41 var searchManager = null;
42
43 /** @type {?SettingsMainElement} */
44 var page = null;
michaelpg 2016/07/30 05:38:44 nit: page already has too many meaninsg
dpapad 2016/08/02 22:33:15 Done.
45
46 // TODO(tommycli): Remove once settings.navigateTo is no longer a stub.
47 settings.navigateTo = function(route) {
48 page.currentRoute = route;
49 };
50
51 setup(function() {
52 searchManager = new TestSearchManager();
53 settings.setSearchManagerForTesting(searchManager);
54 PolymerTest.clearBody();
55 page = document.createElement('settings-main');
56 page.prefs = settingsPrefs.prefs;
57 page.toolbarSpinnerActive = false;
58 document.body.appendChild(page);
59 });
60
61 teardown(function() { page.remove(); });
62
63 test('NoResultsPageShowsHides', function() {
michaelpg 2016/07/30 05:38:44 nit... this is just a string, it doesn't have to b
dpapad 2016/08/02 22:33:15 Done.
64 var noSearchResults = page.$.noSearchResults;
65 assertTrue(!!noSearchResults);
66 assertTrue(noSearchResults.hidden);
67
68 searchManager.setMatchesFound(false);
69 return page.searchContents('foo').then(function() {
70 assertFalse(noSearchResults.hidden);
71
72 searchManager.setMatchesFound(true);
73 return page.searchContents('foo');
74 }).then(function() {
75 assertTrue(noSearchResults.hidden);
76 });
77 });
78
79 // Ensure that when the user clears the search box, the "no results" page
80 // is hidden.
81 test('NoResultsPageHidesOnClear', function() {
82 var noSearchResults = page.$.noSearchResults;
83 assertTrue(!!noSearchResults);
84 assertTrue(noSearchResults.hidden);
85 searchManager.setMatchesFound(false);
michaelpg 2016/07/30 05:38:44 assert first that noSearchResults is unhidden?
michaelpg 2016/08/02 20:45:20 ping, did you miss this file? this one is slightly
dpapad 2016/08/02 22:33:15 I don't fully understand your comment "to catch a
86
87 // Clearing the search box is effectively a search for the empty string.
88 return page.searchContents('').then(function() {
89 assertTrue(noSearchResults.hidden);
90 });
91 });
92 });
93 }
94
95 return {
96 registerTests: registerTests,
97 };
98 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698