|
| 1 | +import {eventMap, eventAliasMap} from '../event-map' |
1 | 2 | import {fireEvent} from '..'
|
2 | 3 |
|
3 | 4 | const eventTypes = [
|
4 | 5 | {
|
5 | 6 | type: 'Clipboard',
|
6 |
| - events: ['copy', 'paste'], |
| 7 | + events: ['copy', 'cut', 'paste'], |
7 | 8 | elementType: 'input',
|
8 | 9 | },
|
9 | 10 | {
|
@@ -137,92 +138,19 @@ const eventTypes = [
|
137 | 138 | },
|
138 | 139 | ]
|
139 | 140 |
|
140 |
| -const bubblingEvents = [ |
141 |
| - 'copy', |
142 |
| - 'cut', |
143 |
| - 'paste', |
144 |
| - 'compositionEnd', |
145 |
| - 'compositionStart', |
146 |
| - 'compositionUpdate', |
147 |
| - 'keyDown', |
148 |
| - 'keyPress', |
149 |
| - 'keyUp', |
150 |
| - 'focusIn', |
151 |
| - 'focusOut', |
152 |
| - 'change', |
153 |
| - 'input', |
154 |
| - 'submit', |
155 |
| - 'reset', |
156 |
| - 'click', |
157 |
| - 'contextMenu', |
158 |
| - 'dblClick', |
159 |
| - 'drag', |
160 |
| - 'dragEnd', |
161 |
| - 'dragEnter', |
162 |
| - 'dragExit', |
163 |
| - 'dragLeave', |
164 |
| - 'dragOver', |
165 |
| - 'dragStart', |
166 |
| - 'drop', |
167 |
| - 'mouseDown', |
168 |
| - 'mouseMove', |
169 |
| - 'mouseOut', |
170 |
| - 'mouseOver', |
171 |
| - 'mouseUp', |
172 |
| - 'select', |
173 |
| - 'touchCancel', |
174 |
| - 'touchEnd', |
175 |
| - 'touchMove', |
176 |
| - 'touchStart', |
177 |
| - 'wheel', |
178 |
| - 'animationStart', |
179 |
| - 'animationEnd', |
180 |
| - 'animationIteration', |
181 |
| - 'transitionEnd', |
182 |
| - 'pointerOver', |
183 |
| - 'pointerDown', |
184 |
| - 'pointerMove', |
185 |
| - 'pointerUp', |
186 |
| - 'pointerCancel', |
187 |
| - 'pointerOut', |
188 |
| -] |
| 141 | +const allEvents = Object.keys(eventMap) |
189 | 142 |
|
190 |
| -const nonBubblingEvents = [ |
191 |
| - 'focus', |
192 |
| - 'blur', |
193 |
| - 'invalid', |
194 |
| - 'mouseEnter', |
195 |
| - 'mouseLeave', |
196 |
| - 'scroll', |
197 |
| - 'abort', |
198 |
| - 'canPlay', |
199 |
| - 'canPlayThrough', |
200 |
| - 'durationChange', |
201 |
| - 'emptied', |
202 |
| - 'encrypted', |
203 |
| - 'ended', |
204 |
| - 'loadedData', |
205 |
| - 'loadedMetadata', |
206 |
| - 'loadStart', |
207 |
| - 'pause', |
208 |
| - 'play', |
209 |
| - 'playing', |
210 |
| - 'progress', |
211 |
| - 'rateChange', |
212 |
| - 'seeked', |
213 |
| - 'seeking', |
214 |
| - 'stalled', |
215 |
| - 'suspend', |
216 |
| - 'timeUpdate', |
217 |
| - 'volumeChange', |
218 |
| - 'waiting', |
219 |
| - 'load', |
220 |
| - 'error', |
221 |
| - 'pointerEnter', |
222 |
| - 'pointerLeave', |
223 |
| - 'gotPointerCapture', |
224 |
| - 'lostPointerCapture', |
225 |
| -] |
| 143 | +const bubblingEvents = allEvents |
| 144 | + .filter(eventName => eventMap[eventName].defaultInit.bubbles) |
| 145 | + |
| 146 | +const composedEvents = allEvents |
| 147 | + .filter(eventName => eventMap[eventName].defaultInit.composed) |
| 148 | + |
| 149 | +const nonBubblingEvents = allEvents |
| 150 | + .filter(eventName => !bubblingEvents.includes(eventName)) |
| 151 | + |
| 152 | +const nonComposedEvents = allEvents |
| 153 | + .filter(eventName => !composedEvents.includes(eventName)) |
226 | 154 |
|
227 | 155 | eventTypes.forEach(({type, events, elementType}) => {
|
228 | 156 | describe(`${type} Events`, () => {
|
@@ -268,13 +196,48 @@ describe(`Bubbling Events`, () => {
|
268 | 196 | )
|
269 | 197 | })
|
270 | 198 |
|
| 199 | +describe(`Composed Events`, () => { |
| 200 | + composedEvents.forEach(event => |
| 201 | + it(`${event} crosses shadow DOM boundary`, () => { |
| 202 | + const node = document.createElement('div') |
| 203 | + const spy = jest.fn() |
| 204 | + node.addEventListener(event.toLowerCase(), spy) |
| 205 | + |
| 206 | + const shadowRoot = node.attachShadow({ mode: 'closed' }) |
| 207 | + const innerNode = document.createElement('div') |
| 208 | + shadowRoot.appendChild(innerNode) |
| 209 | + |
| 210 | + fireEvent[event](innerNode) |
| 211 | + expect(spy).toHaveBeenCalledTimes(1) |
| 212 | + }), |
| 213 | + ) |
| 214 | + |
| 215 | + nonComposedEvents.forEach(event => |
| 216 | + it(`${event} does not cross shadow DOM boundary`, () => { |
| 217 | + const node = document.createElement('div') |
| 218 | + const spy = jest.fn() |
| 219 | + node.addEventListener(event.toLowerCase(), spy) |
| 220 | + |
| 221 | + const shadowRoot = node.attachShadow({ mode: 'closed' }) |
| 222 | + const innerNode = document.createElement('div') |
| 223 | + shadowRoot.appendChild(innerNode) |
| 224 | + |
| 225 | + fireEvent[event](innerNode) |
| 226 | + expect(spy).not.toHaveBeenCalled() |
| 227 | + }), |
| 228 | + ) |
| 229 | +}) |
| 230 | + |
271 | 231 | describe(`Aliased Events`, () => {
|
272 |
| - it(`fires doubleClick`, () => { |
273 |
| - const node = document.createElement('div') |
274 |
| - const spy = jest.fn() |
275 |
| - node.addEventListener('dblclick', spy) |
276 |
| - fireEvent.doubleClick(node) |
277 |
| - expect(spy).toHaveBeenCalledTimes(1) |
| 232 | + Object.keys(eventAliasMap).forEach(eventAlias => { |
| 233 | + it(`fires ${eventAlias}`, () => { |
| 234 | + const node = document.createElement('div') |
| 235 | + const spy = jest.fn() |
| 236 | + node.addEventListener(eventAliasMap[eventAlias].toLowerCase(), spy) |
| 237 | + |
| 238 | + fireEvent[eventAlias](node) |
| 239 | + expect(spy).toHaveBeenCalledTimes(1) |
| 240 | + }) |
278 | 241 | })
|
279 | 242 | })
|
280 | 243 |
|
|
0 commit comments