Skip to content

Commit

Permalink
add tests for mt-avatar component
Browse files Browse the repository at this point in the history
  • Loading branch information
Haberkamp committed Sep 19, 2024
1 parent 6632a92 commit eaf90b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { render, screen } from "@testing-library/vue";
import MtAvatar from "./mt-avatar.vue";

describe("mt-avatar", () => {
it("shows only a placeholder", () => {
render(MtAvatar, { props: { placeholder: true } });

const result = screen.getByTestId("mt-avatar-placeholder");

expect(result).toBeInTheDocument();

expect(screen.queryByTestId("mt-avatar-initials")).not.toBeInTheDocument();
});

it("shows only initials", () => {
render(MtAvatar, { props: { firstName: "John", lastName: "Doe" } });

const result = screen.getByTestId("mt-avatar-initials");

expect(result).toBeInTheDocument();
expect(result).toHaveTextContent("JD");

expect(screen.queryByTestId("mt-avatar-placeholder")).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
role="img"
>
<slot>
<span v-if="showInitials" class="mt-avatar__initials">
<span v-if="showInitials" class="mt-avatar__initials" data-testid="mt-avatar-initials">
{{ avatarInitials }}
</span>

<span v-if="showPlaceholder">
<mt-icon name="regular-user" />
</span>
<mt-icon
v-if="showPlaceholder"
aria-hidden
name="regular-user"
data-testid="mt-avatar-placeholder"
/>
</slot>
</span>
</template>
Expand Down

0 comments on commit eaf90b8

Please sign in to comment.