@@ -4,22 +4,40 @@ import * as assert from "uvu/assert";
44import { serializeEvent } from "../src/event-to-object.js" ;
55import "./tooling/setup.js" ;
66
7- function assertEqualSerializedEventData ( eventData , expectedSerializedData ) {
8- const mockBoundingRect = {
9- left : 0 ,
10- top : 0 ,
11- right : 0 ,
12- bottom : 0 ,
13- x : 0 ,
14- y : 0 ,
15- width : 0 ,
16- } ;
7+ const mockBoundingRect = {
8+ left : 0 ,
9+ top : 0 ,
10+ right : 0 ,
11+ bottom : 0 ,
12+ x : 0 ,
13+ y : 0 ,
14+ width : 0 ,
15+ } ;
1716
18- const mockElement = {
19- tagName : null ,
20- getBoundingClientRect : ( ) => mockBoundingRect ,
21- } ;
17+ const mockElement = {
18+ tagName : null ,
19+ getBoundingClientRect : ( ) => mockBoundingRect ,
20+ } ;
21+
22+ const allTargetData = {
23+ files : [
24+ {
25+ lastModified : 0 ,
26+ name : "something" ,
27+ type : "some-type" ,
28+ size : 0 ,
29+ } ,
30+ ] ,
31+ value : "something" ,
32+ currentTime : 35 ,
33+ tagName : null , // overwritten in tests
34+ elements : [
35+ { ...mockElement , tagName : "INPUT" , value : "first" } ,
36+ { ...mockElement , tagName : "INPUT" , value : "second" } ,
37+ ] ,
38+ } ;
2239
40+ function assertEqualSerializedEventData ( eventData , expectedSerializedData ) {
2341 const commonEventData = {
2442 target : mockElement ,
2543 currentTarget : mockElement ,
@@ -38,20 +56,6 @@ function assertEqualSerializedEventData(eventData, expectedSerializedData) {
3856 ) ;
3957}
4058
41- const allTargetData = {
42- files : [
43- {
44- lastModified : 0 ,
45- name : "something" ,
46- type : "some-type" ,
47- size : 0 ,
48- } ,
49- ] ,
50- value : "something" ,
51- currentTime : 35 ,
52- tagName : null , // overwritten in tests
53- } ;
54-
5559[
5660 {
5761 case : "adds 'files' and 'value' attributes for INPUT if type=file" ,
@@ -77,9 +81,22 @@ const allTargetData = {
7781 output : { target : { currentTime : allTargetData . currentTime } } ,
7882 } ) ) ,
7983 ...[ "FORM" ] . map ( ( tagName ) => ( {
80- case : `adds 'value ' attribute for ${ tagName } element` ,
84+ case : `adds 'elements ' attribute for ${ tagName } element` ,
8185 tagName,
82- output : { target : { value : allTargetData . value } } ,
86+ output : {
87+ target : {
88+ elements : [
89+ {
90+ value : "first" ,
91+ boundingClientRect : mockBoundingRect ,
92+ } ,
93+ {
94+ value : "second" ,
95+ boundingClientRect : mockBoundingRect ,
96+ } ,
97+ ] ,
98+ } ,
99+ } ,
83100 } ) ) ,
84101] . forEach ( ( expectation ) => {
85102 test ( `serializeEvent() ${ expectation . case } ` , ( ) => {
0 commit comments