Skip to content

Commit 1804d00

Browse files
authored
Fixes #236: (test) add unit and e2e tests to about us page components (#250)
* feat: add data-testid to About us hero * feat(test): write test for successful render of About us page * fix(test): rename hero section component test case * feat(test): define data-testid for mission section * feat(test): write test case for mission section * feat(test): define data-testid for leadership section * feat(test): write test case for leadership section * feat(test): define data-testid for reports section * feat(test): write test case for reports section * chore: rename test elements for clarity * feat(test): define data-testid for leadership carousel and elements * feat(test): write test case for carousel display * feat(test): define data-testid for partnership btn and modal * feat(test): write test case for partner with us modal in /about
1 parent a211f13 commit 1804d00

File tree

7 files changed

+136
-6
lines changed

7 files changed

+136
-6
lines changed

src/components/Caroussel.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ function Caroussel({ CarousselData }) {
1313
};
1414

1515
return (
16-
<section className="pt-4 sm:pt-16 pb-10 mx-auto w-full max-w-screen-2xl">
16+
<section
17+
className="pt-4 sm:pt-16 pb-10 mx-auto w-full max-w-screen-2xl"
18+
data-testid="carousel"
19+
>
1720
<div
1821
ref={carouselRef}
1922
className="py-6 grid grid-cols-1 md:grid-cols-2 gap-8 overflow-x-auto scrollbar-hide"
@@ -74,13 +77,15 @@ function Caroussel({ CarousselData }) {
7477
type="button"
7578
aria-label="back button"
7679
onClick={() => scroll(-400)}
80+
data-testid="previous"
7781
>
7882
<PiArrowCircleLeft className="text-green-header size-16" />
7983
</button>
8084
<button
8185
type="button"
8286
aria-label="forward button"
8387
onClick={() => scroll(400)}
88+
data-testid="next"
8489
>
8590
<PiArrowCircleRight className="text-green-header size-16" />
8691
</button>

src/pages/aboutUs/sections/HeroSection.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ function HeroSection() {
66
<div className="px-4 sm:px-14 xl:px-28 sm:m-auto max-w-screen-2xl">
77
<div className="flex flex-col md:flex-row items-center pt-10 gap-4">
88
<div className="md:w-1/2">
9-
<h1 className="mb-2 md:text-[40px] leading-tight text-2xl font-medium text-gray-900">
9+
<h1
10+
className="mb-2 md:text-[40px] leading-tight text-2xl font-medium text-gray-900"
11+
data-testid="title"
12+
>
1013
Empowering <span className="text-primary">innovation</span> in the{" "}
1114
<span className="text-primary">African tech space</span>
1215
</h1>

src/pages/aboutUs/sections/LeadershipSection.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ function LeadershipSection() {
7575
<section className="pt-16 sm:pt-0 pb-10 mx-auto w-full max-w-screen-2xl sm:mt-24 px-4 md:px-0">
7676
<div className="mx-auto w-full flex flex-row items-center gap-2 md:gap-4 my-6">
7777
<div className="w-full h-0.5 rounded-sm bg-gray-300" />
78-
<h2 className="min-w-fit text-primary text-sm leading-loose px-4 bg-gradient-to-r from-[#D7F4EB] to-white py-2 rounded-full font-semibold border-2 border-gray-300 uppercase">
78+
<h2
79+
className="min-w-fit text-primary text-sm leading-loose px-4 bg-gradient-to-r from-[#D7F4EB] to-white py-2 rounded-full font-semibold border-2 border-gray-300 uppercase"
80+
data-testid="leadership"
81+
>
7982
Our leadership
8083
</h2>
8184
<div className="w-full h-0.5 bg-gray-300" />
@@ -119,6 +122,7 @@ function LeadershipSection() {
119122
aria-label="Partner with us"
120123
onClick={openModal}
121124
className="text-white bg-gradient-to-b to-primary from-green-dark border-0 py-3 px-4 md:px-8 focus:outline-none rounded-lg text-sm md:text-base w-fit text-center"
125+
data-testid="partner-with-us"
122126
>
123127
Partner with us
124128
</button>
@@ -139,7 +143,10 @@ function LeadershipSection() {
139143
leaveFrom="opacity-100"
140144
leaveTo="opacity-0"
141145
>
142-
<div className="fixed inset-0 bg-black/25" />
146+
<div
147+
className="fixed inset-0 bg-black/25"
148+
data-testid="partner-popup"
149+
/>
143150
</Transition.Child>
144151

145152
<div className="fixed inset-0 overflow-y-auto">

src/pages/aboutUs/sections/MissionVisionSection.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ function MissionVisionSection() {
55
<div className="max-w-screen-xl mx-auto mt-24 px-4 md:px-0">
66
<div className="mx-auto w-full flex flex-row items-center gap-2 md:gap-4 my-8">
77
<div className="w-full h-0.5 rounded-sm bg-gray-300" />
8-
<h2 className="min-w-fit text-primary text-sm leading-loose px-4 bg-gradient-to-r from-[#D7F4EB] to-white py-2 rounded-full font-semibold border-2 border-gray-300 uppercase">
8+
<h2
9+
className="min-w-fit text-primary text-sm leading-loose px-4 bg-gradient-to-r from-[#D7F4EB] to-white py-2 rounded-full font-semibold border-2 border-gray-300 uppercase"
10+
data-testid="mission"
11+
>
912
A bit more about us
1013
</h2>
1114
<div className="w-full h-0.5 bg-gray-300" />

src/pages/aboutUs/sections/PartnerCTA.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ function PartnerCTA() {
55
<section className="pt-16 pb-10 mx-auto w-full max-w-screen-2xl">
66
<div className="flex flex-col sm:flex-row justify-between px-4 sm:px-28">
77
<div className="space-y-4 mb-8 sm:mb-0">
8-
<h3 className="font-semibold text-md sm:text-xl">Our Reports</h3>
8+
<h3
9+
className="font-semibold text-md sm:text-xl"
10+
data-testid="reports"
11+
>
12+
Our Reports
13+
</h3>
914
<p>
1015
<a
1116
href={Report}

tests/pages/About.test.jsx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { HelmetProvider } from "react-helmet-async";
3+
import { BrowserRouter } from "react-router-dom";
4+
import { describe, expect, it } from "vitest";
5+
6+
import placeholder from "../../src/assets/images/sytLogo.png";
7+
import Caroussel from "../../src/components/Caroussel";
8+
import AboutUs from "../../src/pages/aboutUs/AboutUs";
9+
10+
const LeadershipData = [
11+
{
12+
name: "First User",
13+
title: "Founder",
14+
image: placeholder,
15+
linkedin: {
16+
href: "https://www.linkedin.com/",
17+
username: "First User",
18+
},
19+
twitter: {
20+
href: "https://twitter.com/x",
21+
username: "First User",
22+
},
23+
},
24+
{
25+
name: "Second User",
26+
title: "Dev Relations & Opensource Programs",
27+
image: placeholder,
28+
linkedin: {
29+
href: "https://www.linkedin.com",
30+
username: "Second User",
31+
},
32+
twitter: {
33+
href: "",
34+
username: "",
35+
},
36+
},
37+
{
38+
name: "Third User",
39+
title: "Community Manager",
40+
image: placeholder,
41+
linkedin: {
42+
href: "https://www.linkedin.com",
43+
username: "Third User",
44+
},
45+
twitter: {
46+
href: "",
47+
username: "",
48+
},
49+
},
50+
];
51+
52+
describe("About us page unit tests", () => {
53+
const renderWithRouter = (ui) =>
54+
render(
55+
<HelmetProvider>
56+
<BrowserRouter>{ui}</BrowserRouter>
57+
</HelmetProvider>
58+
);
59+
60+
it("should render Hero Section successfully", () => {
61+
renderWithRouter(<AboutUs />);
62+
const titleElement = screen.getByTestId("title");
63+
expect(titleElement).toBeTruthy();
64+
});
65+
66+
it("should render Mission/Vision Section successfully", () => {
67+
renderWithRouter(<AboutUs />);
68+
const testElement = screen.getByTestId("mission");
69+
expect(testElement).toBeTruthy();
70+
});
71+
72+
it("should render Leadership Section successfully", () => {
73+
renderWithRouter(<AboutUs />);
74+
const testElement = screen.getByTestId("leadership");
75+
expect(testElement).toBeTruthy();
76+
});
77+
78+
it("should render Reports Section successfully", () => {
79+
renderWithRouter(<AboutUs />);
80+
const testElement = screen.getByTestId("reports");
81+
expect(testElement).toBeTruthy();
82+
});
83+
84+
it("should render leadership carousel successfully", () => {
85+
renderWithRouter(<Caroussel CarousselData={LeadershipData} />);
86+
const carouselElement = screen.getByTestId("carousel");
87+
expect(carouselElement).toBeTruthy();
88+
});
89+
});

tests/pages/about-page.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.beforeEach(async ({ page }) => {
4+
await page.goto("http://localhost:5173/about-us");
5+
});
6+
7+
test("should render partnership modal when partner with us btn is clicked", async ({
8+
page,
9+
}) => {
10+
const testId = "partner-with-us";
11+
// click Partner with us button
12+
await page.click(`button[data-testid="${testId}"]`);
13+
14+
// Check if the popup is visible
15+
const popupTestId = "partner-popup";
16+
const popup = await page.locator(`div[data-testid="${popupTestId}"]`);
17+
await expect(popup).toBeVisible();
18+
});

0 commit comments

Comments
 (0)