Skip to content

Commit 0adaa91

Browse files
committed
Added unit tests.
1 parent ddec3d2 commit 0adaa91

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/avatar/__tests__/avatar.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Avatar, { AvatarProps } from "../../../lib/components/avatar";
99
import createWrapper from "../../../lib/components/test-utils/dom";
1010

1111
import loadingDotsStyles from "../../../lib/components/avatar/loading-dots/styles.selectors.js";
12+
import avatarStyles from "../../../lib/components/avatar/styles.selectors.js";
1213

1314
const defaultAvatarProps: AvatarProps = { ariaLabel: "Avatar" };
1415

@@ -30,6 +31,15 @@ describe("Avatar", () => {
3031
expect(wrapper.getElement().textContent).toBe(initials);
3132
});
3233

34+
test("Renders avatar with image", () => {
35+
const imgUrl =
36+
"https://static1.colliderimages.com/wordpress/wp-content/uploads/2024/08/deadpool-wolverine-hugh-jackman-mask-reveal.jpg";
37+
const wrapper = renderAvatar({ ...defaultAvatarProps, imgUrl });
38+
39+
const image = wrapper.findByClassName(avatarStyles.image)?.getElement();
40+
expect(image).toBeInTheDocument();
41+
});
42+
3343
test("Shows tooltip on focus", () => {
3444
const tooltipText = "Jane Doe";
3545
const wrapper = renderAvatar({ ...defaultAvatarProps, color: "default", tooltipText });
@@ -75,6 +85,15 @@ describe("Avatar", () => {
7585
expect(loading).toBeInTheDocument();
7686
});
7787

88+
test("Loading takes precedence over image", () => {
89+
const imgUrl =
90+
"https://static1.colliderimages.com/wordpress/wp-content/uploads/2024/08/deadpool-wolverine-hugh-jackman-mask-reveal.jpg";
91+
const wrapper = renderAvatar({ ...defaultAvatarProps, imgUrl, loading: true });
92+
93+
const loading = wrapper.findByClassName(loadingDotsStyles.root)?.getElement();
94+
expect(loading).toBeInTheDocument();
95+
});
96+
7897
test("Shows warning when initials length is longer than 2", () => {
7998
const warnOnce = vi.spyOn(ComponentToolkitInternal, "warnOnce");
8099

src/avatar/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const AvatarContent = ({
3434
}
3535

3636
if (imgUrl) {
37-
return <img src={imgUrl} style={{ height: width, width: width }} />;
37+
return <img className={styles.image} src={imgUrl} style={{ height: width, width: width }} />;
3838
}
3939

4040
if (initials) {

src/avatar/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ $avatar-size: 28px;
4848
inline-size: inherit;
4949
overflow: hidden;
5050

51-
img {
51+
.image {
5252
@include mixins.border-radius-avatar;
5353
block-size: $avatar-size;
5454
inline-size: $avatar-size;

0 commit comments

Comments
 (0)