Skip to content

Commit 2e9a91a

Browse files
committed
fix test
1 parent 2b070cb commit 2e9a91a

File tree

2 files changed

+67
-30
lines changed

2 files changed

+67
-30
lines changed

src/client/packages/idom-client-react/tests/event-to-object.test.js

+47-30
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,40 @@ import * as assert from "uvu/assert";
44
import { serializeEvent } from "../src/event-to-object.js";
55
import "./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}`, () => {

temp.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from idom import component, event, html, run
2+
3+
4+
@component
5+
def Form():
6+
@event(prevent_default=True)
7+
def handle_form(event):
8+
print(event["target"]["elements"])
9+
10+
return html.form(
11+
{"onSubmit": handle_form},
12+
html.input({"name": "firstname"}),
13+
html.p("test"),
14+
html.button({"type": "submit", "value": "Submit"}, "Submit"),
15+
html.input({"lastname": "lastname"}),
16+
html.p("tes2t"),
17+
)
18+
19+
20+
run(Form)

0 commit comments

Comments
 (0)