Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnCh committed Sep 16, 2024
1 parent c408a44 commit 795085c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/inputs/SelectField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function Template(args: SelectFieldProps<any, any>) {
{o.name ?? "None"}
</div>
)}
onAddNew={(v) => alert("Got " + v)}
/>
<TestSelectField
{...args}
Expand Down
21 changes: 20 additions & 1 deletion src/inputs/SelectField.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clickAndWait } from "@homebound/rtl-utils";
import { clickAndWait, type } from "@homebound/rtl-utils";
import { fireEvent } from "@testing-library/react";
import { useState } from "react";
import { SelectField, SelectFieldProps, Value } from "src/inputs";
Expand Down Expand Up @@ -472,6 +472,25 @@ describe("SelectFieldTest", () => {
expect(onSelect.mock.calls[2][0]).toBe(undefined);
});

it("allows to add a new option", async () => {
// Given a SelectField
const onAddNew = jest.fn();
const r = await render(
<TestSelectField
label="Age"
value={undefined}
options={options}
getOptionLabel={(o) => o.name}
getOptionValue={(o) => o.id}
onAddNew={onAddNew}
/>,
);
// When we select Add New option
select(r.age, "Add New");
// Then onAddNew was called
expect(onAddNew).toHaveBeenCalledTimes(1);
});

// Used to validate the `unset` option can be applied to non-`HasIdAndName` options
type HasLabelAndValue = {
label: string;
Expand Down

0 comments on commit 795085c

Please sign in to comment.