test: Create unit tests for react components in packages/ui/components/scrollable (#10489)

Co-authored-by: gitstart-calcom <gitstart@users.noreply.github.com>
pull/10448/head
GitStart-Cal.com 2023-08-02 07:11:37 +01:00 committed by GitHub
parent a97e145cdb
commit c8beb6fba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View File

@ -35,7 +35,7 @@ const ScrollableArea = ({ children, className }: PropsWithChildren<{ className?:
className // Pass in your max-w / max-h
)}>
{children}
{isOverflowingY && <div style={overflowIndicatorStyles} />}
{isOverflowingY && <div style={overflowIndicatorStyles} data-testid="overflow-indicator" />}
</div>
);
};

View File

@ -0,0 +1,48 @@
import { render } from "@testing-library/react";
import { vi } from "vitest";
import { ScrollableArea } from "./ScrollableArea";
describe("Tests for ScrollableArea Component", () => {
const toJSONMock = vi.fn();
test("Should render children inside the scrollable area", () => {
const { getByText } = render(
<ScrollableArea>
<div>Child 1</div>
<div>Child 2</div>
</ScrollableArea>
);
expect(getByText("Child 1")).toBeInTheDocument();
expect(getByText("Child 2")).toBeInTheDocument();
});
test("Shouldn't show the overflow indicator when content does not overflow vertically", () => {
const mockScrollHeight = 50;
const { queryByTestId } = render(
<ScrollableArea>
<div style={{ height: `${mockScrollHeight}px` }}>Non-Overflowing Content</div>
</ScrollableArea>
);
expect(queryByTestId("overflow-indicator")).not.toBeInTheDocument();
});
test("Should show the overflow indicator when content overflows vertically", () => {
const mockScrollHeight = 100;
Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
value: mockScrollHeight,
writable: true,
});
const { getByTestId } = render(
<ScrollableArea>
<div>Overflowing Content</div>
</ScrollableArea>
);
expect(getByTestId("overflow-indicator")).toBeInTheDocument();
});
});