| Jack Steinberg | 17de974 | 2019-06-19 06:22:24 | [diff] [blame] | 1 | <!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"> |
| 11 | import { testToastElement, assertToastShown, assertToastNotShown, testToastElementAsync } from './resources/helpers.js'; |
| 12 | |
| 13 | testToastElement((toast) => { |
| 14 | toast.setAttribute('open', ''); |
| 15 | assertToastShown(toast); |
| 16 | }, 'setting `open` on a hidden toast shows the toast'); |
| 17 | |
| 18 | testToastElement((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 | |
| 23 | testToastElement((toast) => { |
| 24 | toast.show(); |
| 25 | toast.setAttribute('open', 'test'); |
| 26 | assertToastShown(toast); |
| 27 | }, 'setting `open` on a shown toast does nothing'); |
| 28 | |
| 29 | testToastElement((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 | |
| 36 | testToastElement((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 | |
| 42 | testToastElement((toast) => { |
| 43 | toast.show(); |
| 44 | toast.removeAttribute('open'); |
| 45 | assertToastNotShown(toast); |
| 46 | }, 'removing `open` hides the toast'); |
| 47 | |
| 48 | testToastElement((toast) => { |
| 49 | toast.show(); |
| 50 | assert_true(toast.hasAttribute('open')); |
| 51 | }, 'showing the toast adds open attribute'); |
| 52 | |
| 53 | testToastElement((toast) => { |
| 54 | toast.show(); |
| 55 | toast.hide(); |
| 56 | assert_false(toast.hasAttribute('open')); |
| 57 | }, 'hiding the toast removes open attribute'); |
| 58 | |
| 59 | testToastElement((toast) => { |
| 60 | toast.toggleAttribute('open'); |
| 61 | assert_true(toast.hasAttribute('open')); |
| 62 | }, 'toggling `open` on a hidden toast sets the open attribute'); |
| 63 | |
| 64 | testToastElement((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 | |
| 70 | testToastElement((toast) => { |
| 71 | assert_false(toast.open); |
| 72 | }, 'the `toast.open` boolean is false for a hidden toast'); |
| 73 | |
| 74 | testToastElement((toast) => { |
| 75 | toast.show(); |
| 76 | assert_true(toast.open); |
| 77 | }, 'the `toast.open` boolean is true for a shown toast'); |
| 78 | |
| 79 | testToastElement((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 | |
| 85 | testToastElement((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 | |
| 91 | testToastElement((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 | |
| 97 | testToastElement((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 Steinberg | 17de974 | 2019-06-19 06:22:24 | [diff] [blame] | 103 | testToastElementAsync((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 Steinberg | ad56cbc | 2019-06-28 01:11:56 | [diff] [blame] | 111 | |
| 112 | testToastElement((toast) => { |
| Jack Steinberg | 109a7d1 | 2019-07-23 18:45:11 | [diff] [blame] | 113 | const permitted_properties = ['constructor', 'show', 'hide', 'toggle', 'open', 'action', 'closeButton', 'type']; |
| Jack Steinberg | ad56cbc | 2019-06-28 01:11:56 | [diff] [blame] | 114 | assert_array_equals(permitted_properties.sort(), Object.getOwnPropertyNames(toast.__proto__).sort()); |
| 115 | }, 'toast only exposes certain properties'); |
| Jack Steinberg | 109a7d1 | 2019-07-23 18:45:11 | [diff] [blame] | 116 | |
| 117 | testToastElement((toast) => { |
| 118 | assert_false(toast.hasAttribute('type')); |
| 119 | assert_equals(toast.type, ''); |
| 120 | }, 'default type is empty string without attribute present'); |
| 121 | |
| 122 | testToastElement((toast) => { |
| Jack Steinberg | 109a7d1 | 2019-07-23 18:45:11 | [diff] [blame] | 123 | 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 Steinberg | 17de974 | 2019-06-19 06:22:24 | [diff] [blame] | 127 | </script> |