-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49bb9d1
commit 5262602
Showing
7 changed files
with
96 additions
and
12 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
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
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
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,2 +1,6 @@ | ||
export * from "./Avatar.tsx"; | ||
export * from "./AnonymousAvatar.tsx"; | ||
export * from "./DeletedAvatar.tsx"; | ||
export * from "./RichIconAvatarImage.tsx"; | ||
export * from "./AvatarContext.ts"; | ||
export * from "./RichIconAvatarImageContext.ts"; |
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
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,10 +1,85 @@ | ||
import { render, screen } from "@hopper-ui/test-utils"; | ||
import { createRef } from "react"; | ||
|
||
import { Avatar } from "../../src/Avatar.tsx"; | ||
import { AvatarContext } from "../../src/AvatarContext.ts"; | ||
|
||
describe("Avatar", () => { | ||
it("should render a span with default class", () => { | ||
it("should render with default class", () => { | ||
render(<Avatar name="John Doe" />); | ||
|
||
const element = screen.getByRole("img", { hidden: true }); | ||
|
||
expect(element).toHaveClass("hop-RichIcon"); | ||
}); | ||
|
||
it("should support custom class", () => { | ||
render(<Avatar name="John Doe" className="test" />); | ||
|
||
const element = screen.getByRole("img", { hidden: true }); | ||
|
||
expect(element).toHaveClass("hop-RichIcon"); | ||
expect(element).toHaveClass("test"); | ||
}); | ||
|
||
it("should support custom style", () => { | ||
render(<Avatar name="John Doe" marginTop="stack-sm" style={{ marginBottom: "13px" }} />); | ||
|
||
const element = screen.getByRole("img", { hidden: true }); | ||
|
||
expect(element).toHaveStyle({ marginTop: "var(--hop-space-stack-sm)", marginBottom: "13px" }); | ||
}); | ||
|
||
it("should support DOM props", () => { | ||
render(<Avatar name="John Doe" data-foo="bar" />); | ||
|
||
const element = screen.getByRole("img", { hidden: true }); | ||
|
||
expect(element).toHaveAttribute("data-foo", "bar"); | ||
}); | ||
|
||
it("should support slots", () => { | ||
render( | ||
<AvatarContext.Provider value={{ slots: { test: { "aria-label": "test", "name": "test" } } }}> | ||
<Avatar name="John Doe" slot="test" /> | ||
</AvatarContext.Provider> | ||
); | ||
|
||
const element = screen.getByRole("img", { hidden: true }); | ||
expect(element).not.toHaveAttribute("slot", "test"); // svg doesn't have slot attribute | ||
expect(element).toHaveAttribute("aria-label", "test"); | ||
}); | ||
|
||
it("should support refs", () => { | ||
const ref = createRef<HTMLDivElement>(); | ||
render(<Avatar name="John Doe" ref={ref} />); | ||
|
||
const element = screen.getByRole("img", { hidden: true }); | ||
|
||
expect(ref.current).toBe(element); | ||
expect(ref.current instanceof HTMLDivElement).toBeTruthy(); | ||
expect(ref.current?.tagName.toUpperCase()).toBe("div"); | ||
}); | ||
|
||
it("should apply default displayName", () => { | ||
expect(Avatar.displayName).toBe("Avatar"); | ||
}); | ||
|
||
it("should apply aria-label and aria-hidden attributes", () => { | ||
render(<Avatar name="John Doe" aria-label="Test Icon" />); | ||
|
||
const icon = screen.getByRole("img"); | ||
|
||
expect(icon).toHaveAttribute("aria-label", "Test Icon"); | ||
expect(icon).not.toHaveAttribute("aria-hidden"); | ||
}); | ||
|
||
it("should apply aria-hidden attributes when no aria-label is provided", () => { | ||
render(<Avatar name="John Doe" />); | ||
|
||
const icon = screen.getByRole("img", { hidden: true }); | ||
|
||
expect(icon).not.toHaveAttribute("aria-label"); | ||
expect(icon).toHaveAttribute("aria-hidden", "true"); | ||
}); | ||
}); |
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