1 // Copyright 2015 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.
5 /** @fileoverview Suite of tests for issue-banner. */
6 cr
.define('issue_banner', function() {
7 function registerTests() {
8 suite('IssueBanner', function() {
10 * Issue Banner created before each test.
16 * Fake blocking issue with an optional action created before
18 * @type {media_router.Issue}
20 var fakeBlockingIssueOne
;
23 * Fake blocking issue without an optional action created before
25 * @type {media_router.Issue}
27 var fakeBlockingIssueTwo
;
30 * Fake non-blocking issue with an optional action created before
32 * @type {media_router.Issue}
34 var fakeNonBlockingIssueOne
;
37 * Fake non-blocking issue without an optional action created before
39 * @type {media_router.Issue}
41 var fakeNonBlockingIssueTwo
;
43 // Checks whether the 'issue-action-click' event was fired with the
45 var checkDataFromEventFiring = function(issue
, data
, isDefault
) {
46 assertEquals(issue
.id
, data
.detail
.id
);
48 assertEquals(issue
.defaultActionType
, data
.detail
.actionType
);
50 assertEquals(issue
.secondaryActionType
, data
.detail
.actionType
);
51 assertEquals(issue
.helpPageId
, data
.detail
.helpPageId
);
54 // Checks whether |expected| and the text in the |elementId| element
56 var checkElementText = function(expected
, elementId
) {
57 assertEquals(expected
.trim(), banner
.$[elementId
].textContent
.trim());
60 // Checks whether |issue| title are equal with the title text in the UI.
61 var checkIssueText = function(issue
) {
63 checkElementText(issue
.title
, 'title');
65 checkElementText(loadTimeData
.getString(
66 banner
.issueActionTypeToButtonTextResource_
[
67 issue
.defaultActionType
]), 'default-button');
69 if (issue
.secondaryActionType
) {
70 checkElementText(loadTimeData
.getString(
71 banner
.issueActionTypeToButtonTextResource_
[
72 issue
.secondaryActionType
]), 'opt-button');
75 checkElementText('', 'title');
76 checkElementText('', 'default-button');
77 checkElementText('', 'opt-button');
81 // Checks whether parts of the UI is visible.
82 var checkButtonVisibility = function(hasOptAction
) {
83 assertEquals(!hasOptAction
, banner
.$['buttons']
84 .querySelector('paper-button').hidden
);
87 // Import issue_banner.html before running suite.
88 suiteSetup(function() {
89 return PolymerTest
.importHtml(
90 'chrome://media-router/elements/issue_banner/' +
94 // Initialize an issue-banner before each test.
95 setup(function(done
) {
96 PolymerTest
.clearBody();
97 banner
= document
.createElement('issue-banner');
98 document
.body
.appendChild(banner
);
100 // Initialize issues.
101 fakeBlockingIssueOne
= new media_router
.Issue(
102 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1,
103 'route id 1', true, 1234);
104 fakeBlockingIssueTwo
= new media_router
.Issue(
105 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, null,
106 'route id 2', true, 1234);
107 fakeNonBlockingIssueOne
= new media_router
.Issue(
108 'issue id 3', 'Issue Title 3', 'Issue Message 3', 0, 1,
109 'route id 3', false, 1234);
110 fakeNonBlockingIssueTwo
= new media_router
.Issue(
111 'issue id 4', 'Issue Title 4', 'Issue Message 4', 0, null,
112 'route id 4', false, 1234);
114 // Allow for the issue banner to be created and attached.
118 // Tests for 'issue-action-click' event firing when a blocking issue
119 // default action is clicked.
120 test('blocking issue default action click', function(done
) {
121 banner
.issue
= fakeBlockingIssueOne
;
122 banner
.addEventListener('issue-action-click', function(data
) {
123 checkDataFromEventFiring(fakeBlockingIssueOne
,
127 MockInteractions
.tap(banner
.$['default-button']);
130 // Tests for 'issue-action-click' event firing when a blocking issue
131 // optional action is clicked.
132 test('blocking issue optional action click', function(done
) {
133 banner
.issue
= fakeBlockingIssueOne
;
134 banner
.addEventListener('issue-action-click', function(data
) {
135 checkDataFromEventFiring(fakeBlockingIssueOne
,
139 MockInteractions
.tap(banner
.$['opt-button']);
142 // Tests for 'issue-action-click' event firing when a non-blocking issue
143 // default action is clicked.
144 test('non-blocking issue default action click', function(done
) {
145 banner
.issue
= fakeNonBlockingIssueOne
;
146 banner
.addEventListener('issue-action-click', function(data
) {
147 checkDataFromEventFiring(fakeNonBlockingIssueOne
,
151 MockInteractions
.tap(banner
.$['default-button']);
154 // Tests for 'issue-action-click' event firing when a non-blocking issue
155 // optional action is clicked.
156 test('non-blocking issue optional action click', function(done
) {
157 banner
.issue
= fakeNonBlockingIssueOne
;
158 banner
.addEventListener('issue-action-click', function(data
) {
159 checkDataFromEventFiring(fakeNonBlockingIssueOne
,
163 MockInteractions
.tap(banner
.$['opt-button']);
166 // Tests the issue text. While the UI will show only the blocking or
167 // non-blocking interface, the issue's info will be set if specified.
168 test('issue text', function() {
169 // |issue| is null. Title text should be empty.
170 assertEquals(null, banner
.issue
);
171 checkIssueText(banner
.issue
);
173 // Set |issue| to be a blocking issue. Title text should be updated.
174 banner
.issue
= fakeBlockingIssueOne
;
175 checkIssueText(banner
.issue
);
177 // Set |issue| to be a non-blocking issue. Title text should be
179 banner
.issue
= fakeNonBlockingIssueOne
;
180 checkIssueText(banner
.issue
);
183 // Tests whether parts of the issue-banner is hidden based on the
185 test('hidden versus visible components', function() {
186 // The blocking UI should be shown along with an optional action.
187 banner
.issue
= fakeBlockingIssueOne
;
188 checkButtonVisibility(fakeBlockingIssueOne
.secondaryActionType
);
190 // The blocking UI should be shown without an optional action.
191 banner
.issue
= fakeBlockingIssueTwo
;
192 checkButtonVisibility(fakeBlockingIssueTwo
.secondaryActionType
);
194 // The non-blocking UI should be shown along with an optional action.
195 banner
.issue
= fakeNonBlockingIssueOne
;
196 checkButtonVisibility(fakeNonBlockingIssueOne
.secondaryActionType
);
198 // The non-blocking UI should be shown without an optional action.
199 banner
.issue
= fakeNonBlockingIssueTwo
;
200 checkButtonVisibility(fakeNonBlockingIssueTwo
.secondaryActionType
);
206 registerTests
: registerTests
,