From ec12cc0df204f596e8f92b6f21f39a20901ae468 Mon Sep 17 00:00:00 2001 From: WK Wong Date: Fri, 13 Dec 2024 14:16:26 +0800 Subject: [PATCH 1/7] refactor: use onPress event instead --- packages/components/alert/src/alert.tsx | 2 +- .../components/button/__tests__/button-group.test.tsx | 2 +- packages/components/button/__tests__/button.test.tsx | 8 ++++---- packages/components/button/stories/button.stories.tsx | 2 +- packages/components/card/__tests__/card.test.tsx | 8 ++++---- packages/components/dropdown/stories/dropdown.stories.tsx | 2 +- packages/components/link/__tests__/link.test.tsx | 8 ++++---- packages/components/link/stories/link.stories.tsx | 2 +- packages/components/listbox/stories/listbox.stories.tsx | 2 +- packages/components/menu/__tests__/menu.test.tsx | 6 ++---- packages/components/menu/stories/menu.stories.tsx | 2 +- 11 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/components/alert/src/alert.tsx b/packages/components/alert/src/alert.tsx index cc8c9a691d..84f77fd618 100644 --- a/packages/components/alert/src/alert.tsx +++ b/packages/components/alert/src/alert.tsx @@ -73,7 +73,7 @@ const Alert = forwardRef<"div", AlertProps>((props, ref) => { aria-label="Close" radius="full" variant="light" - onClick={handleClose} + onPress={handleClose} {...(getCloseButtonProps() as ButtonProps)} > diff --git a/packages/components/button/__tests__/button-group.test.tsx b/packages/components/button/__tests__/button-group.test.tsx index ce31a5b025..fe4569231f 100644 --- a/packages/components/button/__tests__/button-group.test.tsx +++ b/packages/components/button/__tests__/button-group.test.tsx @@ -26,7 +26,7 @@ describe("ButtonGroup", () => { const handler = jest.fn(); const wrapper = render( - , diff --git a/packages/components/button/__tests__/button.test.tsx b/packages/components/button/__tests__/button.test.tsx index e019b4dd23..963eb8db91 100644 --- a/packages/components/button/__tests__/button.test.tsx +++ b/packages/components/button/__tests__/button.test.tsx @@ -36,15 +36,15 @@ describe("Button", () => { expect(onPress).toHaveBeenCalled(); }); - it("should trigger onClick function", async () => { - const onClick = jest.fn(); - const {getByRole} = render( diff --git a/packages/components/card/__tests__/card.test.tsx b/packages/components/card/__tests__/card.test.tsx index ab0b9c642c..e963ca0673 100644 --- a/packages/components/card/__tests__/card.test.tsx +++ b/packages/components/card/__tests__/card.test.tsx @@ -41,15 +41,15 @@ describe("Card", () => { expect(onPress).toHaveBeenCalled(); }); - it("should trigger onClick function", async () => { - const onClick = jest.fn(); - const {getByRole} = render(); + it("should trigger onPress function", async () => { + const onPress = jest.fn(); + const {getByRole} = render(); const button = getByRole("button"); await user.click(button); - expect(onClick).toHaveBeenCalled(); + expect(onPress).toHaveBeenCalled(); }); it("should render correctly when nested", () => { diff --git a/packages/components/dropdown/stories/dropdown.stories.tsx b/packages/components/dropdown/stories/dropdown.stories.tsx index 12d1379d23..21e280b4a3 100644 --- a/packages/components/dropdown/stories/dropdown.stories.tsx +++ b/packages/components/dropdown/stories/dropdown.stories.tsx @@ -148,7 +148,7 @@ const Template = ({ - alert("New file")}> + alert("New file")}> New file Copy link diff --git a/packages/components/link/__tests__/link.test.tsx b/packages/components/link/__tests__/link.test.tsx index b9c5e92731..5f68c8de3f 100644 --- a/packages/components/link/__tests__/link.test.tsx +++ b/packages/components/link/__tests__/link.test.tsx @@ -51,15 +51,15 @@ describe("Link", () => { expect(onPress).toHaveBeenCalled(); }); - it("should trigger onClick function", async () => { - const onClick = jest.fn(); - const {getByRole} = render(); + it("should trigger onPress function", async () => { + const onPress = jest.fn(); + const {getByRole} = render(); const link = getByRole("link"); await user.click(link); - expect(onClick).toHaveBeenCalled(); + expect(onPress).toHaveBeenCalled(); }); it('should have target="_blank" and rel="noopener noreferrer" when "isExternal" is true', () => { diff --git a/packages/components/link/stories/link.stories.tsx b/packages/components/link/stories/link.stories.tsx index 9a56a60a42..578985704b 100644 --- a/packages/components/link/stories/link.stories.tsx +++ b/packages/components/link/stories/link.stories.tsx @@ -58,7 +58,7 @@ const PressableTemplate = (args: LinkProps) => { }; return ( - + {isOpen ? "Open" : "Close"} ); diff --git a/packages/components/listbox/stories/listbox.stories.tsx b/packages/components/listbox/stories/listbox.stories.tsx index 38fb8147e1..3369384bf6 100644 --- a/packages/components/listbox/stories/listbox.stories.tsx +++ b/packages/components/listbox/stories/listbox.stories.tsx @@ -174,7 +174,7 @@ const Template = ({color, variant, ...args}: ListboxProps) => ( onAction={(key: Key) => alert(key)} {...args} > - alert("[onClick] New file")}> + alert("[onPress] New file")}> New file Copy link diff --git a/packages/components/menu/__tests__/menu.test.tsx b/packages/components/menu/__tests__/menu.test.tsx index 698eaa59e4..9cc62cf51a 100644 --- a/packages/components/menu/__tests__/menu.test.tsx +++ b/packages/components/menu/__tests__/menu.test.tsx @@ -317,14 +317,13 @@ describe("Menu", () => { expect(onAction).toHaveBeenCalledTimes(0); }); - it("should dispatch onPress, onAction and onClick events", async () => { + it("should dispatch onPress, onAction", async () => { let onPress = jest.fn(); - let onClick = jest.fn(); let onAction = jest.fn(); const wrapper = render( - + New file Copy link @@ -341,7 +340,6 @@ describe("Menu", () => { expect(onAction).toHaveBeenCalledTimes(1); expect(onPress).toHaveBeenCalledTimes(1); - expect(onClick).toHaveBeenCalledTimes(1); }); it("should menuItem classNames work", () => { diff --git a/packages/components/menu/stories/menu.stories.tsx b/packages/components/menu/stories/menu.stories.tsx index 0b026b22f7..ec9560300c 100644 --- a/packages/components/menu/stories/menu.stories.tsx +++ b/packages/components/menu/stories/menu.stories.tsx @@ -45,7 +45,7 @@ const defaultProps = { const Template = ({color, variant, ...args}: MenuProps) => ( - alert("[onClick] New file")}> + alert("[onPress] New file")}> New file Copy link From afc5b8f60cd827857976ca6ad457dde1dd30618e Mon Sep 17 00:00:00 2001 From: WK Wong Date: Fri, 13 Dec 2024 18:49:44 +0800 Subject: [PATCH 2/7] chore(changeset): add changeset --- .changeset/two-ghosts-search.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/two-ghosts-search.md diff --git a/.changeset/two-ghosts-search.md b/.changeset/two-ghosts-search.md new file mode 100644 index 0000000000..93c016e26b --- /dev/null +++ b/.changeset/two-ghosts-search.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/alert": patch +--- + +replace decrepate onClick in Alert From 5186bdd0fceda0137bcd966d63258ba0ef374578 Mon Sep 17 00:00:00 2001 From: WK Wong Date: Fri, 13 Dec 2024 20:32:26 +0800 Subject: [PATCH 3/7] refactor(button): remove duplicate test case --- packages/components/button/__tests__/button.test.tsx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/components/button/__tests__/button.test.tsx b/packages/components/button/__tests__/button.test.tsx index 963eb8db91..b3fa1b899d 100644 --- a/packages/components/button/__tests__/button.test.tsx +++ b/packages/components/button/__tests__/button.test.tsx @@ -36,17 +36,6 @@ describe("Button", () => { expect(onPress).toHaveBeenCalled(); }); - it("should trigger onPress function", async () => { - const onPress = jest.fn(); - const {getByRole} = render(