Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethasok committed Jan 29, 2025
1 parent 66a09e9 commit 4ff77a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/components/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@ import { Badge } from "./Badge";
import { renderCUI } from "@/utils/test-utils";

describe("Badge", () => {
test("given a text, should render it", () => {
test("given a text, should render ellipsed badge", () => {
const text = "text to render";
const rendered = renderCUI(<Badge text={text} />, "light");

expect(rendered.getByText(text).textContent).toEqual(text);
expect(rendered.queryByTestId("ellipsed-badge-content")).not.toBeNull();
expect(rendered.queryByTestId("ellipsed-icon-wrapper-text")).not.toBeNull();
expect(rendered.queryByTestId("normal-badge-content")).toBeNull();
expect(rendered.queryByTestId("normal-icon-wrapper-text")).toBeNull();
});
test("given a text, should render normal badge when ellipsisContent is false", () => {
const text = "text to render";
const rendered = renderCUI(
<Badge
text={text}
ellipsisContent={false}
/>,
"light"
);

expect(rendered.getByText(text).textContent).toEqual(text);
expect(rendered.queryByTestId("ellipsed-badge-content")).toBeNull();
expect(rendered.queryByTestId("ellipsed-icon-wrapper-text")).toBeNull();
expect(rendered.queryByTestId("normal-badge-content")).not.toBeNull();
expect(rendered.queryByTestId("normal-icon-wrapper-text")).not.toBeNull();
});
});
2 changes: 1 addition & 1 deletion src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const Badge = ({
$type={type}
{...props}
>
<Content>
<Content data-testid={`${ellipsisContent ? "ellipsed" : "normal"}-badge-content`}>
<BadgeContent
as={IconWrapper}
icon={icon}
Expand Down
6 changes: 5 additions & 1 deletion src/components/IconWrapper/IconWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const IconWrapper = ({
height={height}
/>
)}
<TextWrapper>{children}</TextWrapper>
<TextWrapper
data-testid={`${ellipsisContent ? "ellipsed" : "normal"}-icon-wrapper-text`}
>
{children}
</TextWrapper>
{icon && iconDir === "end" && (
<Icon
name={icon}
Expand Down

0 comments on commit 4ff77a9

Please sign in to comment.