-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
345 write component test for pageheader (#346)
* test(frontend): 🧪 write component test for sharebuttons * test(frontend): 🧪 write test for slicepreviewtest to check if the component slices the 100 first chars in the first paragraph * test(frontend): 🧪 write component test for fullBlogCard and check if the content is rendered correctly * test(frontend): 🧪 Write component test for pageheader and check if the title and subtitle is rendered correctly --------- Co-authored-by: Mats <64415243+mnyflot@users.noreply.github.com>
- Loading branch information
2 people
authored and
GitHub
committed
Apr 21, 2024
1 parent
0c06127
commit d99e7e6
Showing
2 changed files
with
112 additions
and
0 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,61 @@ | ||
| import { test, expect } from "@playwright/experimental-ct-react"; | ||
| import FullBlogCard from "@/components/fullBlogCard"; | ||
| import { BlogPost } from "@/app/blog/page"; | ||
| import { Enum_Article_Tag } from "@/__generated__/graphql"; | ||
|
|
||
| test("FullBlogCard renders correctly", async ({ mount }) => { | ||
| const mockArticle: BlogPost = { | ||
| key: "mock-key", | ||
| title: "Mock Article Title", | ||
| content: [ | ||
| { | ||
| type: "paragraph", | ||
| children: [ | ||
| { | ||
| type: "text", | ||
| text: "Mock article content preview text...", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| coverImage: "mock-cover-image.jpg", | ||
| datePublished: "2024-04-13", | ||
| tag: Enum_Article_Tag.Projects, | ||
| slug: "mock-article-slug", | ||
| }; | ||
| // Mount the FullBlogCard component with mock data | ||
| const component = await mount(<FullBlogCard article={mockArticle} />); | ||
|
|
||
| //Check if the component is visible | ||
| await expect(component).toBeVisible(); | ||
|
|
||
| //Check if title is correct | ||
| await expect(component.getByTestId("blogCardLink")).toContainText( | ||
| "Mock Article Title", | ||
| ); | ||
|
|
||
| //Check if preview text for blog is visible | ||
| await expect( | ||
| component.getByText("Mock article content preview text..."), | ||
| ).toBeVisible(); | ||
|
|
||
| //Check if the image is visible | ||
| await expect(component.getByRole("img")).toBeVisible(); | ||
|
|
||
| //Check if datePublished is visible | ||
| await expect(component.getByText("April 13, 2024")).toBeVisible(); | ||
|
|
||
| //Check if the tag is correct | ||
| await expect(component.getByTestId("articleTag")).toHaveText("Projects"); | ||
|
|
||
| //Check if the urls on the links are correct | ||
| await expect(component.getByTestId("blogCardLink")).toHaveAttribute( | ||
| "href", | ||
| "/blog/mock-article-slug", | ||
| ); | ||
|
|
||
| await expect(component.getByText("Read more")).toHaveAttribute( | ||
| "href", | ||
| "/blog/mock-article-slug", | ||
| ); | ||
| }); |
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,51 @@ | ||
| import { test, expect } from "@playwright/experimental-ct-react"; | ||
| import { | ||
| PageHeader, | ||
| PageHeaderAndSubtitle, | ||
| PageSubtitle, | ||
| } from "@/components/PageHeader"; | ||
|
|
||
| // Mock data | ||
| const headerText = "Welcome to our Page"; | ||
| const subtitleText = "Explore our content"; | ||
|
|
||
| test("PageHeader renders correctly", async ({ mount }) => { | ||
| // Mount the PageHeader component with mock data | ||
| const component = await mount(<PageHeader>{headerText}</PageHeader>); | ||
|
|
||
| // Check if the component is visible | ||
| await expect(component).toBeVisible(); | ||
|
|
||
| // Check if the header text is correct | ||
| await expect(component).toContainText(headerText); | ||
| }); | ||
|
|
||
| test("PageSubtitle renders correctly", async ({ mount }) => { | ||
| // Mount the PageSubtitle component with mock data | ||
| const component = await mount(<PageSubtitle>{subtitleText}</PageSubtitle>); | ||
|
|
||
| // Check if the component is visible | ||
| await expect(component).toBeVisible(); | ||
|
|
||
| // Check if the subtitle text is correct | ||
| await expect(component).toContainText(subtitleText); | ||
| }); | ||
|
|
||
| test("PageHeaderAndSubtitle renders correctly", async ({ mount }) => { | ||
| // Mount the PageHeaderAndSubtitle component with mock data | ||
| const component = await mount( | ||
| <PageHeaderAndSubtitle> | ||
| <PageHeader>{headerText}</PageHeader> | ||
| <PageSubtitle>{subtitleText}</PageSubtitle> | ||
| </PageHeaderAndSubtitle>, | ||
| ); | ||
|
|
||
| // Check if the component is visible | ||
| await expect(component).toBeVisible(); | ||
|
|
||
| // Check if the header text is correct | ||
| await expect(component).toContainText(headerText); | ||
|
|
||
| // Check if the subtitle text is correct | ||
| await expect(component).toContainText(subtitleText); | ||
| }); |