From a211f13248866f2e688332413c02eb750dbdbb9f Mon Sep 17 00:00:00 2001
From: Alvin Wanjala <40637276+alvyynm@users.noreply.github.com>
Date: Tue, 15 Oct 2024 19:39:45 +0300
Subject: [PATCH] feat (test): write unit tests for Footer (#249)
* feat (test): write unit tests for Footer
* chore: update playwright config to only run *.spec.js files
---
playwright.config.cjs | 1 +
tests/components/Footer.test.jsx | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
create mode 100644 tests/components/Footer.test.jsx
diff --git a/playwright.config.cjs b/playwright.config.cjs
index 5966b5dd..6ed38d22 100644
--- a/playwright.config.cjs
+++ b/playwright.config.cjs
@@ -12,6 +12,7 @@ import { defineConfig, devices } from "@playwright/test";
*/
module.exports = defineConfig({
testDir: "./tests",
+ testMatch: "**/*.spec.js", // only run *.spec.js files
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
diff --git a/tests/components/Footer.test.jsx b/tests/components/Footer.test.jsx
new file mode 100644
index 00000000..8aaa8cae
--- /dev/null
+++ b/tests/components/Footer.test.jsx
@@ -0,0 +1,28 @@
+import { render, screen } from "@testing-library/react";
+import { BrowserRouter } from "react-router-dom";
+import { describe, expect, it } from "vitest";
+import Footer from "../../src/components/Footer";
+
+describe("Footer", () => {
+ const renderWithRouter = (ui) => render({ui});
+
+ it("should render successfully", () => {
+ renderWithRouter();
+ expect(screen.getByRole("contentinfo")).toBeTruthy();
+ });
+
+ it("displays correct copyright notice", () => {
+ renderWithRouter();
+ expect(
+ screen.getByText((content) =>
+ content.includes(" SpaceYaTech | All Rights Reserved")
+ )
+ ).toBeTruthy();
+ });
+
+ it("renders correct number of links", () => {
+ renderWithRouter();
+ const links = screen.getAllByRole("link");
+ expect(links).toHaveLength(15);
+ });
+});