From b21d91a53f08c6d9834eda9940445910178a5add Mon Sep 17 00:00:00 2001 From: Maharshi Alpesh Date: Fri, 27 Dec 2024 12:22:26 +0530 Subject: [PATCH] chore: adding the tests --- .../components/toast/__tests__/toast.test.tsx | 66 ++++++++++++++++++- packages/components/toast/src/use-toast.ts | 2 +- .../toast/stories/toast.stories.tsx | 2 +- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/packages/components/toast/__tests__/toast.test.tsx b/packages/components/toast/__tests__/toast.test.tsx index 332570a564..201614cc05 100644 --- a/packages/components/toast/__tests__/toast.test.tsx +++ b/packages/components/toast/__tests__/toast.test.tsx @@ -1,9 +1,12 @@ import * as React from "react"; -import {render} from "@testing-library/react"; +import {render, screen} from "@testing-library/react"; import userEvent, {UserEvent} from "@testing-library/user-event"; import {addToast, ToastProvider} from "../src"; +const title = "Testing Title"; +const description = "Testing Description"; + describe("Toast", () => { let user: UserEvent; @@ -57,4 +60,65 @@ describe("Toast", () => { await user.click(button); expect(ref.current).not.toBeNull(); }); + + it("should display title and description when component is rendered", async () => { + const wrapper = render( + <> + + + , + ); + + const button = wrapper.getByTestId("button"); + + await user.click(button); + + const region = screen.getByRole("region"); + + expect(region).toContainHTML(title); + expect(region).toContainHTML(description); + }); + + it("should close", async () => { + const wrapper = render( + <> + + + , + ); + + const button = wrapper.getByTestId("button"); + + await user.click(button); + + const initialCloseButtons = wrapper.getAllByRole("button"); + const initialButtonLength = initialCloseButtons.length; + + await user.click(initialCloseButtons[initialButtonLength - 1]); + + const finalCloseButtons = wrapper.getAllByRole("button"); + const finalButtonLength = finalCloseButtons.length; + + expect(initialButtonLength).toEqual(finalButtonLength + 1); + }); }); diff --git a/packages/components/toast/src/use-toast.ts b/packages/components/toast/src/use-toast.ts index 7e534b2357..8190b620ac 100644 --- a/packages/components/toast/src/use-toast.ts +++ b/packages/components/toast/src/use-toast.ts @@ -206,7 +206,7 @@ export function useToast(originalProps: UseToastProps) (props = {}) => ({ className: slots.closeButton({class: classNames?.closeButton}), "aria-label": "close-button", - ...mergeProps(props, otherProps, closeButtonProps, {onPress: props.onClose}), + ...mergeProps(props, closeButtonProps, {onPress: originalProps.onClose}), }), [closeButtonProps], ); diff --git a/packages/components/toast/stories/toast.stories.tsx b/packages/components/toast/stories/toast.stories.tsx index 105b9b4d08..fd735c8908 100644 --- a/packages/components/toast/stories/toast.stories.tsx +++ b/packages/components/toast/stories/toast.stories.tsx @@ -283,6 +283,6 @@ export const WithEndContent = { }, }; -export const CustomTemplate = { +export const CustomStyles = { render: CustomToastTemplate, };