Skip to content

Commit

Permalink
add test for nested map
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTK committed Nov 8, 2023
1 parent 021c552 commit a5500de
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/core/src/AutoForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("AutoForm", () => {
).toEqual([{ children: [""] }]);
});

it('Add map item', async () => {
it('Add repeated item', async () => {
const namespace = protobuf.parse(`
syntax = "proto3";
Expand Down Expand Up @@ -104,4 +104,40 @@ describe("AutoForm", () => {
"repeated element with map should work"
).toEqual([{ children: [{ val: {} }] }]);
})


it('Add nested map', async () => {
const namespace = protobuf.parse(`
syntax = "proto3";
message Child {
map<string, string> val = 1;
}
message Parent {
map<string, Child> children = 1;
}
`).root;

const handleSubmit = vi.fn();
const dom = render(
<MockApp
onSubmit={handleSubmit}
namespace={namespace}
messageType="Parent"
>
<button id="submit" />
</MockApp>
);

fireEvent.click(dom.queryByTestId("add-btn")!);
await vi.waitUntil(() => dom.queryByTestId("delete-btn") !== null);
fireEvent.click(dom.container.querySelector("#submit")!);
await waitFor(() => handleSubmit.mock.calls.length === 1);

expect(
handleSubmit.mock.calls[0],
"repeated element with map should work"
).toEqual([{ children: {"": {"val": {}}} }]);
})
});

0 comments on commit a5500de

Please sign in to comment.