Skip to content

Commit

Permalink
chore: add test and changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo-manba committed May 26, 2024
1 parent 3cb2e51 commit 6993190
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-baboons-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/select": patch
---

Fix: display placeholder text when unselected for controlled (#3062)
41 changes: 41 additions & 0 deletions packages/components/select/__tests__/select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,47 @@ describe("Select", () => {
// assert that the second select listbox is open
expect(select2).toHaveAttribute("aria-expanded", "true");
});

it("should display placeholder text when unselected", async () => {
const wrapper = render(
<Select
aria-label="Favorite Animal"
data-testid="test-select"
label="Favorite Animal"
placeholder="Select an animal"
>
<SelectItem key="penguin">Penguin</SelectItem>
<SelectItem key="zebra">Zebra</SelectItem>
<SelectItem key="shark">Shark</SelectItem>
</Select>,
);

const select = wrapper.getByTestId("test-select");

expect(select).toHaveTextContent("Select an animal");
});

it("should display placeholder text when unselected (controlled)", async () => {
const onSelectionChange = jest.fn();
const wrapper = render(
<Select
isOpen
aria-label="Favorite Animal"
data-testid="test-select"
placeholder="Select an animal"
selectedKeys={[]}
onSelectionChange={onSelectionChange}
>
<SelectItem key="penguin">Penguin</SelectItem>
<SelectItem key="zebra">Zebra</SelectItem>
<SelectItem key="shark">Shark</SelectItem>
</Select>,
);

const select = wrapper.getByTestId("test-select");

expect(select).toHaveTextContent("Select an animal");
});
});

describe("Select with React Hook Form", () => {
Expand Down

0 comments on commit 6993190

Please sign in to comment.