-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
312 refactor add some tests and documention (#313)
* add tests for pagination and validators helper util functions * add tests for about me page
- Loading branch information
1 parent
0a66f56
commit e74d52b
Showing
6 changed files
with
95 additions
and
23 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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
// import { render } from "../../../../utilities"; | ||
// import { screen } from "@testing-library/react"; | ||
// import AboutMeHeroSection from "../_components/AboutMeHero"; | ||
import { render } from "../../../../utilities"; | ||
import { screen } from "@testing-library/react"; | ||
import AboutMeHeroSection from "../_components/AboutMeHero"; | ||
|
||
describe("About Me Hero Component Tests Suite", () => { | ||
it("should render the component properly with static header texts", () => { | ||
// render(<AboutMeHeroSection />); | ||
// expect(screen.getByRole("heading", { name: /arman/i })).toBeInTheDocument(); | ||
// expect(screen.getByTestId("about-me-subtitle")).toBeInTheDocument(); | ||
render(<AboutMeHeroSection />); | ||
|
||
expect(screen.getByRole("heading", { name: /arman/i })).toBeInTheDocument(); | ||
expect(screen.getByTestId("about-me-subtitle")).toBeInTheDocument(); | ||
}); | ||
}); |
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,28 @@ | ||
import { render } from "../../../../utilities"; | ||
import { screen } from "@testing-library/react"; | ||
import Page, { metadata } from "../about-me/page"; | ||
|
||
describe("About me page test suite", () => { | ||
it("should render the page properly", () => { | ||
render(<Page />); | ||
const pageMainSection = screen.getByTestId("about-me-page"); | ||
|
||
// sections | ||
const aboutMeHeroSection = screen.getByTestId("about-me-hero-section"); | ||
|
||
expect(pageMainSection).toBeInTheDocument(); | ||
|
||
expect(aboutMeHeroSection).toBeInTheDocument(); | ||
}); | ||
|
||
it("should have correct metadata", () => { | ||
// You might need to test this indirectly or through a utility | ||
expect(metadata).toEqual( | ||
expect.objectContaining({ | ||
title: "Arman Ahmadi - About me", | ||
description: | ||
"Hi, I'm Arman! I'm based in the Netherlands and work as a backend engineer at Onefit/Urban Sports Club.", | ||
}), | ||
); | ||
}); | ||
}); |
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
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
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,33 @@ | ||
import getTotalArticlesPage from "../pagination-utils"; | ||
|
||
describe("Pagination utils tests suite", () => { | ||
it("should return correct number of pages when totalArticles divides evenly by showPerPage", () => { | ||
expect(getTotalArticlesPage(100, 10)).toBe(10); | ||
expect(getTotalArticlesPage(50, 25)).toBe(2); | ||
expect(getTotalArticlesPage(30, 15)).toBe(2); | ||
}); | ||
|
||
it("should return correct number of pages when totalArticles does not divide evenly by showPerPage", () => { | ||
expect(getTotalArticlesPage(101, 10)).toBe(11); // Rounded up | ||
expect(getTotalArticlesPage(55, 25)).toBe(3); | ||
expect(getTotalArticlesPage(31, 15)).toBe(3); | ||
}); | ||
|
||
it("should return 0 when totalArticles is 0", () => { | ||
expect(getTotalArticlesPage(0, 10)).toBe(0); | ||
}); | ||
|
||
it("should return totalArticles as the number of pages when showPerPage is 1", () => { | ||
expect(getTotalArticlesPage(100, 1)).toBe(100); | ||
expect(getTotalArticlesPage(25, 1)).toBe(25); | ||
}); | ||
|
||
it("should handle large numbers correctly", () => { | ||
expect(getTotalArticlesPage(1000000, 1000)).toBe(1000); | ||
expect(getTotalArticlesPage(1000000, 3)).toBe(333334); // Rounded up | ||
}); | ||
|
||
it("should handle case when showPerPage is larger than totalArticles", () => { | ||
expect(getTotalArticlesPage(5, 10)).toBe(1); // Even though we can fit all articles in one page | ||
}); | ||
}); |
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,16 @@ | ||
import { emailValidateHandler } from "../validators"; | ||
|
||
describe("VALIDATORS TESTS SUITE", () => { | ||
describe("emailValidateHandler tests suite", () => { | ||
it("should return true if email is valid", () => { | ||
const validEmail = "[email protected]"; | ||
const result = emailValidateHandler(validEmail); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it("should return false if email is invalid", () => { | ||
const invalidEmail = "test@example"; | ||
expect(emailValidateHandler(invalidEmail)).toBe(false); | ||
}); | ||
}); | ||
}); |