-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Avatar): allow control over alt text (#4939)
* feat(Avatar): allow control over alt text * Build out tests
- Loading branch information
1 parent
def3feb
commit 9952feb
Showing
3 changed files
with
83 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kaizen/components": minor | ||
--- | ||
|
||
Avatar: allow control over alt property |
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 |
---|---|---|
|
@@ -23,4 +23,67 @@ describe("<Avatar />", () => { | |
expect(screen.getByText("JWAVLN")).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe("alt text", () => { | ||
describe("providing alt text, overriding fullName", () => { | ||
it("uses alt prop over full name when using initials", () => { | ||
render(<Avatar fullName="Jane Doe" alt="alt override" />) | ||
expect(screen.getByTitle("alt override")).toBeInTheDocument() | ||
}) | ||
|
||
it("uses alt prop over full name when using fallback img", () => { | ||
render( | ||
<Avatar fullName="Jane Doe" alt="alt override" disableInitials /> | ||
) | ||
expect(screen.getByRole("img")).toHaveAccessibleName("alt override") | ||
}) | ||
|
||
it("uses alt prop over full name when supplying an img", () => { | ||
render( | ||
<Avatar | ||
fullName="Jane Doe" | ||
alt="alt override" | ||
avatarSrc="https://www.cultureampcom-preview-1.usw2.wp-dev-us.cultureamp-cdn.com/assets/slices/main/assets/public/media/[email protected]" | ||
/> | ||
) | ||
expect(screen.getByRole("img")).toHaveAccessibleName("alt override") | ||
}) | ||
}) | ||
|
||
describe("providing fullName, no alt prop", () => { | ||
it("uses the fullName when using initials", () => { | ||
render(<Avatar fullName="Jane Doe" />) | ||
expect(screen.getByTitle("Jane Doe")).toBeInTheDocument() | ||
}) | ||
|
||
it("uses the fullName when using fallback img", () => { | ||
render(<Avatar fullName="Jane Doe" disableInitials />) | ||
expect(screen.getByRole("img")).toHaveAccessibleName("Jane Doe") | ||
}) | ||
|
||
it("uses alt prop over full name when supplying an img", () => { | ||
render( | ||
<Avatar | ||
fullName="Jane Doe" | ||
avatarSrc="https://www.cultureampcom-preview-1.usw2.wp-dev-us.cultureamp-cdn.com/assets/slices/main/assets/public/media/[email protected]" | ||
/> | ||
) | ||
expect(screen.getByRole("img")).toHaveAccessibleName("Jane Doe") | ||
}) | ||
}) | ||
|
||
describe("not providing fullName or alt text", () => { | ||
it("makes the img presentational on the fallback img", () => { | ||
render(<Avatar />) | ||
expect(screen.queryByRole("img")).not.toBeInTheDocument() | ||
}) | ||
|
||
it("has blank alt text when img provided", () => { | ||
render( | ||
<Avatar avatarSrc="https://www.cultureampcom-preview-1.usw2.wp-dev-us.cultureamp-cdn.com/assets/slices/main/assets/public/media/[email protected]" /> | ||
) | ||
expect(screen.queryByRole("img")).not.toBeInTheDocument() | ||
}) | ||
}) | ||
}) | ||
}) |
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