4
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8
Code distributed by Google as part of the polymer project is also
9
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
16
<title>paper-toast-basic</title>
17
<meta charset="utf-8">
18
<meta name="viewport" content="width=device-width, initial-scale=1.0">
20
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
21
<script src="../../web-component-tester/browser.js"></script>
23
<link rel="import" href="../paper-toast.html">
35
<test-fixture id="basic">
37
<paper-toast></paper-toast>
41
<test-fixture id="show">
43
<paper-toast opened></paper-toast>
47
<test-fixture id="contained">
49
<paper-toast class="fit-bottom"></paper-toast>
50
<div style="margin: 50px; width: 100px; height: 100px; background-color: orange;"></div>
56
suite('basic', function() {
60
test('is hidden', function() {
61
toast = fixture('basic');
62
assert.isFalse(toast.opened, '`opened` is false');
65
test('is visible', function() {
66
toast = fixture('show');
67
assert.isTrue(toast.opened, '`opened` is true');
70
test('show() will open toast', function() {
71
toast = fixture('basic');
73
assert.isTrue(toast.opened, '`opened` is true');
76
test('hide() will close toast', function() {
77
toast = fixture('show');
79
assert.isFalse(toast.opened, '`opened` is false');
82
test('toast auto-close after 10ms', function(done) {
83
toast = fixture('basic');
86
setTimeout(function() {
87
assert.isFalse(toast.opened, '`opened` is false');
92
test('toast fires opened event', function(done) {
93
toast = fixture('show');
94
toast.addEventListener('iron-overlay-opened', function() {
99
test('toast does not get focused', function(done) {
100
toast = fixture('show');
101
var spy = sinon.spy(toast, 'focus');
102
assert.isTrue(toast.noAutoFocus, 'no-auto-focus is true');
103
toast.addEventListener('iron-overlay-opened', function() {
104
assert.isFalse(spy.called, 'toast is not focused');
109
test('toast fires closed event', function(done) {
110
toast = fixture('basic');
111
toast.show({duration: 350});
112
toast.addEventListener('iron-overlay-closed', function() {
117
test('show() accepts valid properties', function() {
118
toast = fixture('basic');
119
toast.show({text: 'hello world', duration: 20});
120
assert.isTrue(toast.opened, '`opened` is true');
121
assert.equal(toast.text, 'hello world', '`text` is correct');
122
assert.equal(toast.duration, 20, '`duration` is correct');
125
test('show() does not accept invalid properties', function() {
126
toast = fixture('basic');
127
toast.show({foo: 'bar'});
128
assert.isUndefined(toast.foo, '`foo` is not a valid property and will not be set');
129
assert.isTrue(toast.opened, '`opened` is true');
132
test('show() does not accept private properties', function() {
133
toast = fixture('basic');
134
var temp = toast._manager;
135
toast.show({_manager: 'bar'});
136
assert.equal(toast._manager, temp, '`_manager` is a private property and will not be set');
137
assert.isTrue(toast.opened, '`opened` is true');
140
test('show() accepts a string argument as the text parameter', function() {
141
toast = fixture('basic');
142
toast.show('hello world 2');
143
assert.equal(toast.text, 'hello world 2', '`text is correct`');
146
suite('disable auto-close', function() {
149
toast = fixture('basic');
150
spy = sinon.spy(toast, 'async');
152
test('duration = Infinity', function() {
153
toast.duration = Infinity;
155
assert.isFalse(spy.calledWith(toast.close), '`async` was not called with `close()`');
156
assert.isFalse(spy.calledWith(toast.hide), '`async` was not called with `hide()`');
159
test('duration = 0', function() {
162
assert.isFalse(spy.calledWith(toast.close), '`async` was not called with `close()`');
163
assert.isFalse(spy.calledWith(toast.hide), '`async` was not called with `hide()`');
166
test('duration = -10', function() {
167
toast.duration = -10;
169
assert.isFalse(spy.calledWith(toast.close), '`async` was not called with `close()`');
170
assert.isFalse(spy.calledWith(toast.hide), '`async` was not called with `hide()`');
174
test('there is only 1 toast opened', function() {
175
var toast1 = fixture('basic');
176
var toast2 = fixture('show');
179
assert.isTrue(toast1.opened, 'toast1 is opened');
180
assert.isFalse(toast2.opened, 'toast2 is not opened');
182
assert.isFalse(toast1.opened, 'toast1 is now not opened');
183
assert.isTrue(toast2.opened, 'toast2 is now opened');
186
test('auto-close is correctly reset', function(done) {
187
toast = fixture('basic');
190
// a bit later (before the auto-close), toast is reset
191
setTimeout(function() {
196
setTimeout(function() {
197
assert.isTrue(toast.opened, 'toast is still open');
203
test('toast is positioned according at the bottom left of its fitInto', function() {
204
var f = fixture('contained');
206
var container = f[1];
207
toast.fitInto = container;
209
var style = getComputedStyle(toast);
210
assert.equal(style.left, '50px', 'left');
211
// Should be 150px from top, (100px of height + 50px of margin-top)
212
// aka window height - 150 from bottom.
213
assert.equal(style.bottom, (window.innerHeight - 150) + 'px', 'bottom');
216
suite('a11y', function() {
217
test('show() will announce text', function() {
218
toast = fixture('basic');
219
var spy = sinon.spy(toast, 'fire');
220
toast.text = 'announce!';
222
assert.isTrue(spy.calledWith('iron-announce', {
224
}), 'text announced');
227
test('hide() will not announce text', function() {
228
toast = fixture('show');
229
var spy = sinon.spy(toast, 'fire');
231
assert.isFalse(spy.calledWith('iron-announce'), 'text not announced');