Skip to content

Commit

Permalink
fix(TimeAgo): justText value
Browse files Browse the repository at this point in the history
  • Loading branch information
zettca committed Jun 23, 2023
1 parent b2b0128 commit 4b3d159
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/core/src/components/TimeAgo/TimeAgo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,20 @@ describe("TimeAgo with custom Button element", () => {
expect(screen.getByRole("button")).toBeVisible();
});
});

describe("TimeAgo with justText", () => {
it("should render the text", () => {
const timestamp = Date.now();
render(<HvTimeAgo justText timestamp={timestamp} />);

expect(screen.getByText("a few seconds")).toBeInTheDocument();
});

it("should not render the custom component", () => {
const timestamp = Date.now();
render(<HvTimeAgo justText timestamp={timestamp} component="button" />);

expect(screen.getByText("a few seconds")).toBeInTheDocument();
expect(screen.queryByRole("button")).toBeNull();
});
});
7 changes: 4 additions & 3 deletions packages/core/src/components/TimeAgo/TimeAgo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ export const HvTimeAgo = ({
showSeconds,
});

return justText && timestamp ? (
<>timeAgo</>
) : (
// eslint-disable-next-line react/jsx-no-useless-fragment
if (justText && timestamp) return <>{timeAgo}</>;

return (
<Component className={clsx(classes?.root, timeAgoClasses.root)} {...others}>
{!timestamp ? emptyElement : timeAgo}
</Component>
Expand Down

0 comments on commit 4b3d159

Please sign in to comment.