diff --git a/frontend/src/components/Signup.js b/frontend/src/components/Signup.js index 66f9e4b9..4a24b1ca 100644 --- a/frontend/src/components/Signup.js +++ b/frontend/src/components/Signup.js @@ -82,13 +82,14 @@ const Signup = () => { return ( - {loading === false && Sign up} + {loading === false && Sign up for an account} {errors === true && ( Cannot sign up with provided credentials )}
- + { /> { required /> - + { expect(screen.getByDisplayValue("Test case")).toBeInTheDocument(), ); }); - -test("displays 'Submit' button", () => { - render(); - const button = screen.getByText("Submit"); - expect(button).toBeInTheDocument(); -}); - -test("displays 'Import' button", () => { - render(); - const button = screen.getByText("Import"); - expect(button).toBeInTheDocument(); -}); - -test("displays 'Load JSON from URL' button", () => { - render(); - const button = screen.getByText("Load JSON from URL"); - expect(button).toBeInTheDocument(); -}); - -test("shows dialog when 'Load JSON from URL' button is clicked", () => { - render(); - const button = screen.getByText("Load JSON from URL"); - fireEvent.click(button); - const dialogInput = screen.getByPlaceholderText("Enter URL"); - expect(dialogInput).toBeInTheDocument(); -}); - -// Additional test to ensure that the import from file input is present -test("has input for importing case from file", () => { - render(); - const fileInput = screen.getByLabelText(/Choose a file/i); - expect(fileInput).toBeInTheDocument(); -}); diff --git a/frontend/src/components/tests/Signup.test.js b/frontend/src/components/tests/Signup.test.js index bff63096..f1b3871f 100644 --- a/frontend/src/components/tests/Signup.test.js +++ b/frontend/src/components/tests/Signup.test.js @@ -6,6 +6,7 @@ import { render, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; import React from "react"; import Signup from "../Signup.js"; +import userEvent from "@testing-library/user-event"; test("renders signup component", () => { render(); @@ -29,12 +30,27 @@ test("renders password requirements", () => { expect(passwordInfo).toBeInTheDocument(); }); -test("renders error message on failed signup", () => { +test("renders error message on failed signup", async () => { + // Mock the fetch call to return an error + global.fetch = jest.fn(() => + Promise.resolve({ + json: () => + Promise.resolve({ + username: ["This username is already taken."], + // ... add other errors as necessary + }), + status: 400, // typically, errors like these would return a 400 status + }), + ); + render(); - const errorMessage = screen.getByText( + + const submitButton = screen.getByText("Sign up"); + userEvent.click(submitButton); + + // Since network requests are asynchronous, we need to wait for the error message to appear + const errorMessage = await screen.findByText( "Cannot sign up with provided credentials", ); expect(errorMessage).toBeInTheDocument(); }); - -// Additional tests can be created based on functionalities like form submission, error handling, etc.