| Jack Steinberg | 17de974 | 2019-06-19 06:22:24 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <meta charset="utf-8"> |
| Jack Steinberg | 0643b9f | 2019-07-10 15:07:41 | [diff] [blame] | 3 | <title>Toast: event (show/hide) tests</title> |
| Jack Steinberg | 17de974 | 2019-06-19 06:22:24 | [diff] [blame] | 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, EventCollector } from './resources/helpers.js'; |
| 12 | |
| 13 | testToastElement((toast) => { |
| 14 | const counter = new EventCollector(); |
| 15 | |
| 16 | toast.addEventListener('show', counter.getCallback()); |
| 17 | toast.show(); |
| 18 | |
| 19 | assert_equals(counter.getCount(), 1); |
| 20 | }, 'calling `show()` on a hidden toast triggers the `show` event'); |
| 21 | |
| 22 | testToastElement((toast) => { |
| 23 | const counter = new EventCollector(); |
| 24 | |
| 25 | toast.show(); |
| 26 | toast.addEventListener('show', counter.getCallback()); |
| 27 | toast.show(); |
| 28 | |
| 29 | assert_equals(counter.getCount(), 0); |
| 30 | }, 'calling `show()` on a shown toast does not trigger the `show` event'); |
| 31 | |
| 32 | testToastElement((toast) => { |
| 33 | const counter = new EventCollector(); |
| 34 | |
| 35 | toast.addEventListener('hide', counter.getCallback()); |
| 36 | toast.hide(); |
| 37 | |
| 38 | assert_equals(counter.getCount(), 0); |
| 39 | }, 'calling `hide()` on a hidden toast does not trigger the `hide` event'); |
| 40 | |
| 41 | testToastElement((toast) => { |
| 42 | const counter = new EventCollector(); |
| 43 | |
| 44 | toast.show(); |
| 45 | toast.addEventListener('hide', counter.getCallback()); |
| 46 | toast.hide(); |
| 47 | |
| 48 | assert_equals(counter.getCount(), 1); |
| 49 | }, 'calling `hide()` on a shown toast triggers the `hide` event'); |
| 50 | |
| 51 | testToastElement((toast) => { |
| 52 | const counter = new EventCollector(); |
| 53 | |
| 54 | toast.addEventListener('show', counter.getCallback()); |
| 55 | toast.show(); |
| 56 | toast.show(); |
| 57 | |
| 58 | assert_equals(counter.getCount(), 1); |
| 59 | }, 'calling `show()` twice only triggers the `show` event once'); |
| 60 | |
| 61 | testToastElement((toast) => { |
| 62 | const counter = new EventCollector(); |
| 63 | |
| 64 | toast.show(); |
| 65 | toast.addEventListener('hide', counter.getCallback()); |
| 66 | toast.hide(); |
| 67 | toast.hide(); |
| 68 | |
| 69 | assert_equals(counter.getCount(), 1); |
| 70 | }, 'calling `hide()` twice only triggers the `hide` event once'); |
| 71 | |
| 72 | testToastElement((toast) => { |
| 73 | const events = new EventCollector(); |
| 74 | |
| 75 | toast.addEventListener('show', events.getCallback()); |
| 76 | |
| 77 | toast.show(); |
| 78 | toast.hide(); |
| 79 | toast.show(); |
| 80 | |
| 81 | assert_equals(events.getCount(), 2); |
| 82 | assert_not_equals(events.getEvents()[0], events.getEvents()[1]); |
| 83 | }, "separate openings trigger different `show` events"); |
| 84 | |
| 85 | testToastElement((toast) => { |
| 86 | const events = new EventCollector(); |
| 87 | |
| 88 | toast.addEventListener('hide', events.getCallback()); |
| 89 | |
| 90 | toast.show(); |
| 91 | toast.hide(); |
| 92 | toast.show(); |
| 93 | toast.hide(); |
| 94 | |
| 95 | assert_equals(events.getCount(), 2); |
| 96 | assert_not_equals(events.getEvents()[0], events.getEvents()[1]); |
| 97 | }, "separate closings trigger different `hide` events"); |
| 98 | </script> |