-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #759 from COS301-SE-2024/development
Development
- Loading branch information
Showing
76 changed files
with
5,189 additions
and
3,379 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,12 +1,11 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { render } from '@testing-library/react'; | ||
import About from '@/app/about/page'; | ||
import '@testing-library/jest-dom'; | ||
|
||
describe('About Page', () => { | ||
// Test "About Us" heading | ||
test('should display "About Us" heading', () => { | ||
// Simple test to check if the About component renders successfully | ||
test('should render the About page without crashing', () => { | ||
render(<About />); | ||
const aboutUsHeading = screen.getByRole('heading', { name: /about us/i }); | ||
expect(aboutUsHeading).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 |
---|---|---|
@@ -1,16 +1,33 @@ | ||
import CitizenSignup from "@/components/Signup/CitizenSignup"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
import * as AuthService from "../../../src/services/auth.service"; | ||
import { useRouter } from "next/router"; | ||
|
||
// Mock handleSignUp | ||
jest.mock("../../../src/services/auth.service", () => ({ | ||
handleSignUp: jest.fn(), | ||
})); | ||
|
||
describe("Citizen Signup", () => { | ||
|
||
/*it("renders an email input", () => { | ||
render(<CitizenSignup />); | ||
const emailInput = screen.getByLabelText("Email"); | ||
beforeEach(() => { | ||
// Reset mocks before each test | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
expect(emailInput).toBeInTheDocument(); | ||
expect(emailInput).toHaveAttribute("type", "email"); | ||
});*/ | ||
/* Test 1: Renders form fields */ | ||
it("renders the necessary form fields", () => { | ||
render(<CitizenSignup />); | ||
|
||
expect(screen.getByTestId("email-input")).toBeInTheDocument(); | ||
expect(screen.getByTestId("password-input")).toBeInTheDocument(); | ||
expect(screen.getByTestId("confirm-password-input")).toBeInTheDocument(); | ||
expect(screen.getByTestId("firstname-input")).toBeInTheDocument(); | ||
expect(screen.getByTestId("surname-input")).toBeInTheDocument(); | ||
//expect(screen.getAllByPlaceholderText("Select a municipality")[0]).toBeInTheDocument(); | ||
}); | ||
|
||
/* Test 2: Renders email input correctly */ | ||
it("renders an email input", () => { | ||
render(<CitizenSignup />); | ||
// Use getByPlaceholderText if the placeholder is unique | ||
|
@@ -20,32 +37,66 @@ describe("Citizen Signup", () => { | |
expect(emailInput).toHaveAttribute("type", "email"); | ||
}); | ||
|
||
// it("renders a password input", () => { | ||
// render(<CitizenSignup />); | ||
// const passwordInput = screen.getByLabelText("Create Password"); | ||
/* Test 3: Email validation should show an error for invalid email format */ | ||
it("shows error for invalid email format", async () => { | ||
render(<CitizenSignup />); | ||
// Find the email input field by placeholder text | ||
const emailInputs = screen.getAllByPlaceholderText("[email protected]"); | ||
const emailInput = emailInputs[0]; | ||
|
||
// expect(passwordInput).toBeInTheDocument(); | ||
// expect(passwordInput).toHaveAttribute("type", "password"); | ||
// }); | ||
const submitButtons = screen.getAllByTestId("signup-submit-btn"); | ||
const submitButton = submitButtons[0]; | ||
|
||
// Simulate typing an invalid email | ||
fireEvent.change(emailInput, { target: { value: "invalidemail" } }); | ||
await waitFor(() => { | ||
expect(submitButton).toBeDisabled(); | ||
}); | ||
}); | ||
|
||
|
||
/* Test 4: Successful signup should call handleSignUp and redirect to dashboard */ | ||
// This will done with integration testing | ||
|
||
// it("renders a submit button", () => { | ||
// render(<CitizenSignup />); | ||
// const submitButton = screen.getByText("Submit"); | ||
/* Test 5: Displays error message on failed signup */ | ||
it("displays error message if signup fails", async () => { | ||
const handleSignUp = AuthService.handleSignUp; | ||
|
||
// expect(submitButton).toBeInTheDocument(); | ||
// }); | ||
render(<CitizenSignup />); | ||
|
||
// Fill in form data | ||
fireEvent.change(screen.getByTestId("email-input"), { target: { value: "[email protected]" } }); | ||
fireEvent.change(screen.getByTestId("password-input"), { target: { value: "Password123!" } }); | ||
fireEvent.change(screen.getByTestId("confirm-password-input"), { target: { value: "Password123!" } }); | ||
fireEvent.change(screen.getByTestId("firstname-input"), { target: { value: "Dominique" } }); | ||
fireEvent.change(screen.getByTestId("surname-input"), { target: { value: "Da Silva" } }); | ||
//fireEvent.change(screen.getAllByPlaceholderText("Select a municipality")[0], { target: { value: "Ingquza Hill" } }); | ||
|
||
// test("handler function is called after clicking submit button", () => { | ||
// render(<CitizenSignup />); | ||
// const mockFunction = jest.fn(); | ||
// const loginForm = screen.getByTestId("citizen-signup-form"); | ||
// loginForm.addEventListener("submit", mockFunction); | ||
// Submit form | ||
const submitButtons = screen.getAllByTestId("signup-submit-btn"); | ||
const submitButton = submitButtons[0] | ||
fireEvent.click(submitButton); | ||
|
||
// fireEvent.submit(loginForm) | ||
// expect(mockFunction).toHaveBeenCalledTimes(1); | ||
// }); | ||
expect(handleSignUp).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
/* Test 6: Submit button displays and works*/ | ||
it("renders a submit button", () => { | ||
render(<CitizenSignup />); | ||
const submitButtons = screen.getAllByText("Submit"); | ||
const submitButton = submitButtons[0]; | ||
|
||
expect(submitButton).toBeInTheDocument(); | ||
}); | ||
|
||
test("handler function is called after clicking submit button", () => { | ||
render(<CitizenSignup />); | ||
const mockFunction = jest.fn(); | ||
const loginForm = screen.getByTestId("citizen-signup-form"); | ||
loginForm.addEventListener("submit", mockFunction); | ||
|
||
fireEvent.submit(loginForm) | ||
expect(mockFunction).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}) |
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
Oops, something went wrong.