|
1 | 1 | import { expect } from '@open-wc/testing';
|
2 | 2 |
|
3 |
| -import { WithModal } from './modal-controller'; |
4 |
| - |
5 |
| -const Modal = WithModal<string>(HTMLElement); |
6 |
| -customElements.define('modal-controller-test', Modal); |
| 3 | +import { ModalController, WithModal } from './modal-controller'; |
7 | 4 |
|
8 | 5 | describe('ModalController', () => {
|
| 6 | + it('should apply a modal controller with Mixin', async () => { |
| 7 | + const Modal = WithModal<string>(HTMLElement); |
| 8 | + customElements.define('modal-controller-test', Modal); |
| 9 | + |
| 10 | + const { controller } = new Modal(); |
| 11 | + |
| 12 | + controller.open(); |
| 13 | + controller.close('Hello World'); |
| 14 | + |
| 15 | + const res = await controller.result; |
| 16 | + |
| 17 | + expect(res).to.equal('Hello World'); |
| 18 | + }); |
| 19 | + |
9 | 20 | it('should resolve the result to the value passed when closing', async () => {
|
10 |
| - const modal = new Modal(); |
| 21 | + const modal = document.createElement('div'); |
11 | 22 |
|
12 |
| - modal.controller.open(); |
13 |
| - modal.controller.close('Hello World'); |
| 23 | + const controller = new ModalController(modal); |
| 24 | + controller.open(); |
| 25 | + controller.close('Hello World'); |
14 | 26 |
|
15 |
| - const res = await modal.controller.result; |
| 27 | + const res = await controller.result; |
16 | 28 |
|
17 | 29 | expect(res).to.equal('Hello World');
|
18 | 30 | });
|
19 | 31 |
|
20 | 32 | it('should dispatch modalopened event', async () => {
|
21 |
| - const modal = new Modal(); |
| 33 | + const modal = document.createElement('div'); |
| 34 | + modal.dataset.modal = 'true'; |
| 35 | + |
| 36 | + const controller = new ModalController(modal); |
22 | 37 |
|
23 | 38 | return new Promise((resolve) => {
|
24 | 39 | modal.addEventListener('modalopen', (e) => {
|
25 | 40 | const target = e.target as HTMLElement;
|
26 | 41 |
|
27 |
| - expect(target.tagName).to.equal('MODAL-CONTROLLER-TEST'); |
| 42 | + expect(target.dataset.modal).to.equal('true'); |
28 | 43 |
|
29 | 44 | resolve();
|
30 | 45 | });
|
31 | 46 |
|
32 |
| - modal.controller.open(); |
| 47 | + controller.open(); |
33 | 48 | });
|
34 | 49 | });
|
35 | 50 |
|
36 | 51 | it('should dispatch aftermodalopened event', async () => {
|
37 |
| - const modal = new Modal(); |
| 52 | + const modal = document.createElement('div'); |
| 53 | + modal.dataset.modal = 'true'; |
| 54 | + |
| 55 | + const controller = new ModalController(modal); |
38 | 56 |
|
39 | 57 | return new Promise((resolve) => {
|
40 | 58 | modal.addEventListener('modalafteropen', (e) => {
|
41 | 59 | const target = e.target as HTMLElement;
|
42 | 60 |
|
43 |
| - expect(target.tagName).to.equal('MODAL-CONTROLLER-TEST'); |
| 61 | + expect(target.dataset.modal).to.equal('true'); |
44 | 62 |
|
45 | 63 | resolve();
|
46 | 64 | });
|
47 | 65 |
|
48 |
| - modal.controller.open(); |
| 66 | + controller.open(); |
49 | 67 | });
|
50 | 68 | });
|
51 | 69 |
|
52 | 70 | it('should dispatch modalclosed event', async () => {
|
53 |
| - const modal = new Modal(); |
| 71 | + const modal = document.createElement('div'); |
| 72 | + modal.dataset.modal = 'true'; |
| 73 | + |
| 74 | + const controller = new ModalController(modal); |
54 | 75 |
|
55 | 76 | return new Promise((resolve) => {
|
56 | 77 | modal.addEventListener('modalclose', (e) => {
|
57 | 78 | const target = e.target as HTMLElement;
|
58 | 79 |
|
59 |
| - expect(target.tagName).to.equal('MODAL-CONTROLLER-TEST'); |
| 80 | + expect(target.dataset.modal).to.equal('true'); |
60 | 81 |
|
61 | 82 | resolve();
|
62 | 83 | });
|
63 | 84 |
|
64 |
| - modal.controller.open(); |
65 |
| - modal.controller.close(); |
| 85 | + controller.open(); |
| 86 | + controller.close(); |
66 | 87 | });
|
67 | 88 | });
|
68 | 89 | });
|
0 commit comments