blob: 9b87280b6688b3847401ea7b97ed63f6164bf70a [file] [log] [blame]
Jack Steinberg17de9742019-06-19 06:22:241<!DOCTYPE html>
2<meta charset="utf-8">
3<title>Toast: attribute tests</title>
4
5<script src="/resources/testharness.js"></script>
6<script src="/resources/testharnessreport.js"></script>
7
8<main></main>
9
10<script type="module">
11import { testToastElement, assertToastShown, assertToastNotShown, testToastElementAsync } from './resources/helpers.js';
12
13testToastElement((toast) => {
14 toast.setAttribute('open', '');
15 assertToastShown(toast);
16}, 'setting `open` on a hidden toast shows the toast');
17
18testToastElement((toast) => {
19 toast.setAttribute('open', false);
20 assertToastShown(toast);
21}, 'setting `open` to false on a hidden toast shows the toast, because of string conversion');
22
23testToastElement((toast) => {
24 toast.show();
25 toast.setAttribute('open', 'test');
26 assertToastShown(toast);
27}, 'setting `open` on a shown toast does nothing');
28
29testToastElement((toast) => {
30 toast.show();
31 toast.setAttribute('open', 'test');
32 toast.setAttribute('open', 'test');
33 assertToastShown(toast);
34}, 'resetting `open` on a shown toast does nothing');
35
36testToastElement((toast) => {
37 toast.show();
38 toast.setAttribute('open', false);
39 assertToastShown(toast);
40}, 'setting `open` to false on a shown toast does nothing, because of string conversion');
41
42testToastElement((toast) => {
43 toast.show();
44 toast.removeAttribute('open');
45 assertToastNotShown(toast);
46}, 'removing `open` hides the toast');
47
48testToastElement((toast) => {
49 toast.show();
50 assert_true(toast.hasAttribute('open'));
51}, 'showing the toast adds open attribute');
52
53testToastElement((toast) => {
54 toast.show();
55 toast.hide();
56 assert_false(toast.hasAttribute('open'));
57}, 'hiding the toast removes open attribute');
58
59testToastElement((toast) => {
60 toast.toggleAttribute('open');
61 assert_true(toast.hasAttribute('open'));
62}, 'toggling `open` on a hidden toast sets the open attribute');
63
64testToastElement((toast) => {
65 toast.toggleAttribute('open');
66 toast.toggleAttribute('open');
67 assert_false(toast.hasAttribute('open'));
68}, 'toggling `open` twice leaves the toast with no open attribute');
69
70testToastElement((toast) => {
71 assert_false(toast.open);
72}, 'the `toast.open` boolean is false for a hidden toast');
73
74testToastElement((toast) => {
75 toast.show();
76 assert_true(toast.open);
77}, 'the `toast.open` boolean is true for a shown toast');
78
79testToastElement((toast) => {
80 toast.open = true;
81 assertToastShown(toast);
82 assert_equals(toast.getAttribute('open'), '');
83}, 'setting `toast.open` to true on a hidden toast will show the toast');
84
85testToastElement((toast) => {
86 toast.show();
87 toast.open = false;
88 assertToastNotShown(toast);
89}, 'setting `toast.open` to false on a shown toast will hide the toast');
90
91testToastElement((toast) => {
92 toast.open = 'truthy!';
93 assertToastShown(toast);
94 assert_equals(toast.getAttribute('open'), '');
95}, 'setting `toast.open` to some truthy value on a hidden toast will show the toast');
96
97testToastElement((toast) => {
98 toast.show();
99 toast.open = '';
100 assertToastNotShown(toast);
101}, 'setting `toast.open` to some falsy value on a shown toast will hide the toast');
102
Jack Steinberg17de9742019-06-19 06:22:24103testToastElementAsync((t, toast) => {
104 toast.toggleAttribute('open', true);
105
106 t.step_timeout(() => {
107 assertToastShown(toast);
108 t.done();
109 }, 2000);
110}, 'toggling open attribute does not start timeout');
Jack Steinbergad56cbc2019-06-28 01:11:56111
112testToastElement((toast) => {
Jack Steinberg109a7d12019-07-23 18:45:11113 const permitted_properties = ['constructor', 'show', 'hide', 'toggle', 'open', 'action', 'closeButton', 'type'];
Jack Steinbergad56cbc2019-06-28 01:11:56114 assert_array_equals(permitted_properties.sort(), Object.getOwnPropertyNames(toast.__proto__).sort());
115}, 'toast only exposes certain properties');
Jack Steinberg109a7d12019-07-23 18:45:11116
117testToastElement((toast) => {
118 assert_false(toast.hasAttribute('type'));
119 assert_equals(toast.type, '');
120}, 'default type is empty string without attribute present');
121
122testToastElement((toast) => {
Jack Steinberg109a7d12019-07-23 18:45:11123 toast.type = 'info';
124 assert_equals(toast.type, '');
125 assert_equals(toast.getAttribute('type'), 'info');
126}, 'info was briefly a valid type, but no longer is, so it will return empty string');
Jack Steinberg17de9742019-06-19 06:22:24127</script>