-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): update Chip.Prefix to accept more than Icon and Ava…
…tar (#2020) * feat(components): Update Chip.Prefix to accept more than Icon and Avatar as children * test: update tests for Chip.Prefix to cover new behavior * feat(components): Update Chip.Prefix to conditionally render based on content presence * Add Chip.Prefix behavior to the docs * refactor: use fragment isntead of casting and remove unnecessary guard
- Loading branch information
1 parent
e95e2f4
commit 1a6c72c
Showing
3 changed files
with
95 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
packages/components/src/Chip/components/ChipPrefix/Chip.Prefix.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { Chip } from "../../Chip"; | ||
import { Avatar } from "../../../Avatar"; | ||
import { Icon } from "../../../Icon"; | ||
|
||
describe("Chip.Prefix Component", () => { | ||
it("renders Prefix", () => { | ||
const { getByText } = render( | ||
render( | ||
<Chip.Prefix> | ||
<Avatar initials="DT" /> | ||
</Chip.Prefix>, | ||
); | ||
|
||
expect(getByText("DT")).toBeInTheDocument(); | ||
expect(screen.getByText("DT")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should hide prefix when passed bad child", () => { | ||
const { queryByText } = render(<Chip.Prefix>Hello!</Chip.Prefix>); | ||
expect(queryByText("Hello!")).not.toBeInTheDocument(); | ||
it("should show all children when icon or avatar isn't provided", () => { | ||
render( | ||
<Chip.Prefix> | ||
<p>First child</p> | ||
<p>Second child</p> | ||
</Chip.Prefix>, | ||
); | ||
expect(screen.getByText("First child")).toBeInTheDocument(); | ||
expect(screen.getByText("Second child")).toBeInTheDocument(); | ||
}); | ||
|
||
it("prefix renders only one valid child", () => { | ||
const { container } = render( | ||
render( | ||
<Chip.Prefix> | ||
<Icon name="cross" /> | ||
<Icon name="cross" /> | ||
</Chip.Prefix>, | ||
); | ||
expect(container.querySelectorAll("svg")).toHaveLength(1); | ||
expect(screen.getAllByTestId("cross")).toHaveLength(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters