-
Notifications
You must be signed in to change notification settings - Fork 611
test(e2e): add unit tests for card, dropdown, discussion, feed, footer, events and form selector components #2252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LucasEdwa
wants to merge
4
commits into
activist-org:main
Choose a base branch
from
LucasEdwa:test/add-more-unit-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0ce9134
test(frontend): add unit tests for Collapsable, EmptyState, BtnRoadMa…
LucasEdwa 1406804
test(e2e): add unit tests for CardGetInvolved components and auth pages
LucasEdwa 4e113cf
test(frontend): add unit tests for card, dropdown, and discussion com…
LucasEdwa 24d6180
test(frontend): add unit tests for Feed, FooterWebsite, Events compon…
LucasEdwa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, please return the file on the previous state |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -55,8 +55,13 @@ | |
| </p> | ||
| <div class="mt-1 flex gap-10 sm:mt-0 sm:flex-col sm:gap-0"> | ||
| <template v-for="(connect, index) in links.connectLinks"> | ||
| <!-- aria-label uses `connect.ariaLabel`, not `connect.name` (the | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this comment, its too long and unnecessary |
||
| visible label): each link defines its own descriptive | ||
| `ariaLabel` text, which was previously being shadowed by a | ||
| redundant repeat of the visible "GitHub"/"Matrix"/"Instagram" | ||
| label. --> | ||
| <a | ||
| :aria-label="$t(connect.name)" | ||
| :aria-label="$t(connect.ariaLabel)" | ||
| class="mt-2 flex items-center space-x-2 text-base text-primary-text focus-brand hover:text-distinct-text" | ||
| :class="{ 'mt-3': index === 0 }" | ||
| :href="connect.url" | ||
|
|
||
This file contains hidden or 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,91 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| import { fireEvent, screen } from "@testing-library/vue"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import Collapsable from "../../app/components/Collapsable.vue"; | ||
| import render from "../render"; | ||
|
|
||
| const stubs = { | ||
| Icon: { | ||
| template: '<span :class="$attrs.class" />', | ||
| }, | ||
| }; | ||
|
|
||
| describe("Collapsable", () => { | ||
| it("renders the label on the button", async () => { | ||
| await render(Collapsable, { | ||
| props: { label: "Section title" }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| expect(screen.getByRole("button", { name: /section title/i })).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("hides slot content by default", async () => { | ||
| await render(Collapsable, { | ||
| props: { label: "Section title" }, | ||
| slots: { default: "<p>Hidden content</p>" }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| expect(screen.queryByText("Hidden content")).toBeNull(); | ||
| }); | ||
|
|
||
| it("shows slot content when isOpen prop is true", async () => { | ||
| await render(Collapsable, { | ||
| props: { label: "Section title", isOpen: true }, | ||
| slots: { default: "<p>Visible content</p>" }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| expect(screen.getByText("Visible content")).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("toggles slot content open on button click", async () => { | ||
| await render(Collapsable, { | ||
| props: { label: "Section title" }, | ||
| slots: { default: "<p>Toggle content</p>" }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| expect(screen.queryByText("Toggle content")).toBeNull(); | ||
|
|
||
| await fireEvent.click(screen.getByRole("button")); | ||
|
|
||
| expect(screen.getByText("Toggle content")).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("toggles slot content closed on second button click", async () => { | ||
| await render(Collapsable, { | ||
| props: { label: "Section title" }, | ||
| slots: { default: "<p>Toggle content</p>" }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| await fireEvent.click(screen.getByRole("button")); | ||
| expect(screen.getByText("Toggle content")).toBeTruthy(); | ||
|
|
||
| await fireEvent.click(screen.getByRole("button")); | ||
| expect(screen.queryByText("Toggle content")).toBeNull(); | ||
| }); | ||
|
|
||
| it("applies rotate class to icon when open", async () => { | ||
| const { container } = await render(Collapsable, { | ||
| props: { label: "Section title", isOpen: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const icon = container.querySelector("span"); | ||
| expect(icon?.classList.contains("rotate-180")).toBe(true); | ||
| }); | ||
|
|
||
| it("does not apply rotate class to icon when closed", async () => { | ||
| const { container } = await render(Collapsable, { | ||
| props: { label: "Section title", isOpen: false }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const icon = container.querySelector("span"); | ||
| expect(icon?.classList.contains("rotate-180")).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or 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,127 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| import { screen } from "@testing-library/vue"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import EmptyState from "../../app/components/EmptyState.vue"; | ||
| import render from "../render"; | ||
|
|
||
| const stubs = { | ||
| PageContent: { | ||
| template: "<div><slot /></div>", | ||
| }, | ||
| PageCommunityFooter: { | ||
| template: "<div><slot /></div>", | ||
| }, | ||
| BtnRouteInternal: { | ||
| template: '<a :href="linkTo" :aria-label="ariaLabel" />', | ||
| props: ["linkTo", "ariaLabel", "label", "cta", "fontSize"], | ||
| }, | ||
| }; | ||
|
|
||
| describe("EmptyState", () => { | ||
| it("renders the empty state container", async () => { | ||
| await render(EmptyState, { | ||
| props: { pageType: "organizations", permission: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| expect(screen.getByTestId("empty-state")).toBeTruthy(); | ||
| }); | ||
|
|
||
| describe("pageType headers", () => { | ||
| const pageTypes = [ | ||
| "organizations", | ||
| "groups", | ||
| "events", | ||
| "resources", | ||
| "faq", | ||
| "team", | ||
| "affiliates", | ||
| "tasks", | ||
| "discussions", | ||
| ] as const; | ||
|
|
||
| it.each(pageTypes)( | ||
| 'renders a heading for pageType "%s"', | ||
| async (pageType) => { | ||
| await render(EmptyState, { | ||
| props: { pageType, permission: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| expect(screen.getByRole("heading", { level: 2 })).toBeTruthy(); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| describe("permission prop", () => { | ||
| it("shows return home link when permission is false", async () => { | ||
| await render(EmptyState, { | ||
| props: { pageType: "organizations", permission: false }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const links = screen.getAllByRole("link"); | ||
| expect(links.some((l) => l.getAttribute("href") === "/home")).toBe(true); | ||
| }); | ||
|
|
||
| it("shows create organization link when pageType is organizations and has permission", async () => { | ||
| await render(EmptyState, { | ||
| props: { pageType: "organizations", permission: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const links = screen.getAllByRole("link"); | ||
| expect( | ||
| links.some((l) => l.getAttribute("href") === "/organizations/create") | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("shows create group link when pageType is groups and has permission", async () => { | ||
| await render(EmptyState, { | ||
| props: { pageType: "groups", permission: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const links = screen.getAllByRole("link"); | ||
| expect( | ||
| links.some((l) => l.getAttribute("href") === "/groups/create") | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("shows create event link when pageType is events and has permission", async () => { | ||
| await render(EmptyState, { | ||
| props: { pageType: "events", permission: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const links = screen.getAllByRole("link"); | ||
| expect( | ||
| links.some((l) => l.getAttribute("href") === "/events/create") | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("shows create resource link when pageType is resources and has permission", async () => { | ||
| await render(EmptyState, { | ||
| props: { pageType: "resources", permission: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const links = screen.getAllByRole("link"); | ||
| expect( | ||
| links.some((l) => l.getAttribute("href") === "/resources/create") | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("does not show a create link when pageType has no create action", async () => { | ||
| await render(EmptyState, { | ||
| props: { pageType: "faq", permission: true }, | ||
| global: { stubs }, | ||
| }); | ||
|
|
||
| const links = screen.getAllByRole("link"); | ||
| expect(links).toHaveLength(1); | ||
| expect(links[0].getAttribute("href")).toBe("/home"); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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,30 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| import { screen } from "@testing-library/vue"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import BtnRoadMap from "../../../app/components/btn/BtnRoadMap.vue"; | ||
| import render from "../../render"; | ||
|
|
||
| const stubs = { | ||
| NuxtLink: { | ||
| template: '<a :id="$attrs.id" :href="to" :aria-label="$attrs[\'aria-label\']"><slot /></a>', | ||
| props: ["to"], | ||
| }, | ||
| }; | ||
|
|
||
| describe("BtnRoadMap", () => { | ||
| it("renders with the correct id", async () => { | ||
| await render(BtnRoadMap, { global: { stubs } }); | ||
|
|
||
| expect(document.getElementById("btn-roadmap")).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("links to the roadmap URL", async () => { | ||
| await render(BtnRoadMap, { global: { stubs } }); | ||
|
|
||
| const link = screen.getByRole("link"); | ||
| expect(link.getAttribute("href")).toBe( | ||
| "https://docs.activist.org/activist/product/about/roadmap" | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put back the changes from this file. Its a component not being used but will be