|
| 1 | +import { |
| 2 | + dispatchMouseEvent, |
| 3 | + dispatchKeyboardEvent, |
| 4 | + dispatchPointerEvent, |
| 5 | + dispatchFakeEvent, |
| 6 | +} from './dispatch-events'; |
1 | 7 | import {createKeyboardEvent, createMouseEvent} from './event-objects';
|
2 | 8 |
|
3 | 9 | describe('event objects', () => {
|
@@ -40,4 +46,70 @@ describe('event objects', () => {
|
40 | 46 | expect(preventDefaultSpy).toHaveBeenCalledTimes(2);
|
41 | 47 | });
|
42 | 48 | });
|
| 49 | + |
| 50 | + describe('shadow DOM', () => { |
| 51 | + it('should allow dispatched mouse events to propagate through the shadow root', () => { |
| 52 | + if (!testElement.attachShadow) { |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + const spy = jasmine.createSpy('listener'); |
| 57 | + const shadowRoot = testElement.attachShadow({mode: 'open'}); |
| 58 | + const child = document.createElement('div'); |
| 59 | + shadowRoot.appendChild(child); |
| 60 | + |
| 61 | + testElement.addEventListener('mousedown', spy); |
| 62 | + dispatchMouseEvent(child, 'mousedown'); |
| 63 | + |
| 64 | + expect(spy).toHaveBeenCalled(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should allow dispatched keyboard events to propagate through the shadow root', () => { |
| 68 | + if (!testElement.attachShadow) { |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + const spy = jasmine.createSpy('listener'); |
| 73 | + const shadowRoot = testElement.attachShadow({mode: 'open'}); |
| 74 | + const child = document.createElement('div'); |
| 75 | + shadowRoot.appendChild(child); |
| 76 | + |
| 77 | + testElement.addEventListener('keydown', spy); |
| 78 | + dispatchKeyboardEvent(child, 'keydown'); |
| 79 | + |
| 80 | + expect(spy).toHaveBeenCalled(); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should allow dispatched pointer events to propagate through the shadow root', () => { |
| 84 | + if (!testElement.attachShadow) { |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + const spy = jasmine.createSpy('listener'); |
| 89 | + const shadowRoot = testElement.attachShadow({mode: 'open'}); |
| 90 | + const child = document.createElement('div'); |
| 91 | + shadowRoot.appendChild(child); |
| 92 | + |
| 93 | + testElement.addEventListener('pointerdown', spy); |
| 94 | + dispatchPointerEvent(child, 'pointerdown'); |
| 95 | + |
| 96 | + expect(spy).toHaveBeenCalled(); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should allow dispatched fake events to propagate through the shadow root', () => { |
| 100 | + if (!testElement.attachShadow) { |
| 101 | + return; |
| 102 | + } |
| 103 | + |
| 104 | + const spy = jasmine.createSpy('listener'); |
| 105 | + const shadowRoot = testElement.attachShadow({mode: 'open'}); |
| 106 | + const child = document.createElement('div'); |
| 107 | + shadowRoot.appendChild(child); |
| 108 | + |
| 109 | + testElement.addEventListener('fake', spy); |
| 110 | + dispatchFakeEvent(child, 'fake'); |
| 111 | + |
| 112 | + expect(spy).toHaveBeenCalled(); |
| 113 | + }); |
| 114 | + }); |
43 | 115 | });
|
0 commit comments