Skip to content

Commit

Permalink
345 write component test for pageheader (#346)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
61 changes: 61 additions & 0 deletions frontend/tests/componentTests/fullblogcard.spec.tsx
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",
);
});
51 changes: 51 additions & 0 deletions frontend/tests/componentTests/pageheader.spec.tsx
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);
});

0 comments on commit d99e7e6

Please sign in to comment.