Skip to content

Commit

Permalink
Merge pull request #759 from COS301-SE-2024/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Tinogwanz authored Sep 26, 2024
2 parents b7dc854 + 3cafabc commit c5b2e9c
Show file tree
Hide file tree
Showing 76 changed files with 5,189 additions and 3,379 deletions.
9 changes: 4 additions & 5 deletions frontend/__tests__/components/About/aboutpage.test.tsx
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();
});
});

103 changes: 77 additions & 26 deletions frontend/__tests__/components/Signup/CitizenSignup.test.tsx
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
Expand All @@ -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);
});

})
39 changes: 16 additions & 23 deletions frontend/__tests__/components/Signup/MunicipalitySignup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { fireEvent, render, screen } from "@testing-library/react";

describe("Municipality Signup", () => {

/*it("renders an email input", () => {
render(<MunicipalitySignup />);
const emailInput = screen.getByLabelText("Email");
expect(emailInput).toBeInTheDocument();
expect(emailInput).toHaveAttribute("type", "email");
});*/

/* Test 1: Renders email input correctly */
it("renders an email input", () => {
render(<MunicipalitySignup />);
// Use getByPlaceholderText if the placeholder is unique
Expand All @@ -30,23 +23,23 @@ describe("Municipality Signup", () => {
// });


// it("renders a submit button", () => {
// render(<MunicipalitySignup />);
// const submitButton = screen.getByRole("button", {name:/submit/i});

// expect(submitButton).toBeInTheDocument();
// expect(submitButton).toHaveTextContent("Submit");
// });
/* Test : Submit button displays and works*/
it("renders a submit button", () => {
render(<MunicipalitySignup />);
const submitButtons = screen.getAllByText("Submit");
const submitButton = submitButtons[0];

expect(submitButton).toBeInTheDocument();
});

// test("handler function is called after clicking submit button", () => {
// render(<MunicipalitySignup />);
// const mockFunction = jest.fn();
// const loginForm = screen.getByTestId("municipality-signup-form");
// loginForm.addEventListener("submit", mockFunction);
test("handler function is called after clicking submit button", () => {
render(<MunicipalitySignup />);
const mockFunction = jest.fn();
const loginForm = screen.getByTestId("municipality-signup-form");
loginForm.addEventListener("submit", mockFunction);

// fireEvent.submit(loginForm)
// expect(mockFunction).toHaveBeenCalledTimes(1);
// });
fireEvent.submit(loginForm)
expect(mockFunction).toHaveBeenCalledTimes(1);
});

})
41 changes: 16 additions & 25 deletions frontend/__tests__/components/Signup/ServiceProviderSignup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { fireEvent, render, screen } from "@testing-library/react";

describe("Service Provider Signup", () => {

/*it("renders an email input", () => {
render(<ServiceProviderSignup />);
const emailInput = screen.getByLabelText("Email");
expect(emailInput).toBeInTheDocument();
expect(emailInput).toHaveAttribute("type", "email");
});*/

/* Test 1: Renders email input correctly */
it("renders an email input", () => {
render(<ServiceProviderSignup />);
// Use getByPlaceholderText if the placeholder is unique
Expand All @@ -20,8 +13,6 @@ describe("Service Provider Signup", () => {
expect(emailInput).toHaveAttribute("type", "email");
});



// it("renders an input to fill in company name", () => {
// render(<ServiceProviderSignup />);

Expand Down Expand Up @@ -50,23 +41,23 @@ describe("Service Provider Signup", () => {
// });


// it("renders a submit button", () => {
// render(<ServiceProviderSignup />);
// const submitButton = screen.getByRole("button", {name:/submit/i});

// expect(submitButton).toBeInTheDocument();
// expect(submitButton).toHaveTextContent("Submit");
// });
/* Test : Submit button displays and works*/
it("renders a submit button", () => {
render(<ServiceProviderSignup />);
const submitButtons = screen.getAllByText("Submit");
const submitButton = submitButtons[0];

expect(submitButton).toBeInTheDocument();
});

// test("handler function is called after clicking submit button", () => {
// render(<ServiceProviderSignup />);
// const mockFunction = jest.fn();
// const loginForm = screen.getByTestId("service-provider-signup-form");
// loginForm.addEventListener("submit", mockFunction);
test("handler function is called after clicking submit button", () => {
render(<ServiceProviderSignup />);
const mockFunction = jest.fn();
const loginForm = screen.getByTestId("service-provider-signup-form");
loginForm.addEventListener("submit", mockFunction);

// fireEvent.submit(loginForm)
// expect(mockFunction).toHaveBeenCalledTimes(1);
// });
fireEvent.submit(loginForm)
expect(mockFunction).toHaveBeenCalledTimes(1);
});

})
3 changes: 3 additions & 0 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ const nextConfig = {
FIREBASE_MESSAGING_SENDER_ID: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
FIREBASE_APP_ID: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
FIREBASE_MEASUREMENT_ID: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,

NODEAPI_URL: process.env.NEXT_PUBLIC_NODEAPI_URL,

},
webpack(config) {
// SVG handling configuration
Expand Down
Loading

0 comments on commit c5b2e9c

Please sign in to comment.