Skip to content

Commit

Permalink
Fixed signup problems
Browse files Browse the repository at this point in the history
  • Loading branch information
AoifeHughes committed Oct 19, 2023
1 parent 2fe7697 commit 7307483
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
11 changes: 7 additions & 4 deletions frontend/src/components/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ const Signup = () => {

return (
<Box width={{ max: "large" }} gap="medium" pad="medium" overflow="auto">
{loading === false && <Heading level={2}>Sign up</Heading>}
{loading === false && <Heading level={2}>Sign up for an account</Heading>}
{errors === true && (
<Heading level={2}>Cannot sign up with provided credentials</Heading>
)}
<Form onSubmit={onSubmit}>
<FormField htmlFor="username" label="User name">
<FormField label="User name" htmlFor="usernameInput">
<TextInput
id="usernameInput"
name="username"
type="text"
value={username}
Expand All @@ -97,20 +98,22 @@ const Signup = () => {
/>
</FormField>
<FormField
htmlFor="password1"
label="Password"
info="At least 8 characters"
htmlFor="password1Input"
>
<TextInput
id="password1Input"
name="password1"
type="password"
value={password1}
onChange={(e) => setPassword1(e.target.value)}
required
/>
</FormField>
<FormField htmlFor="password2" label="Confirm password">
<FormField label="Confirm password" htmlFor="password2Input">
<TextInput
id="password2Input"
name="password2"
type="password"
value={password2}
Expand Down
34 changes: 0 additions & 34 deletions frontend/src/components/tests/CaseContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "regenerator-runtime/runtime";
import React from "react";
import "@testing-library/jest-dom";
import fetchMock from "jest-fetch-mock";
import { fireEvent } from "@testing-library/react";

import CaseContainer from "../CaseContainer.js";

Expand Down Expand Up @@ -42,36 +41,3 @@ test("renders case view", async () => {
expect(screen.getByDisplayValue("Test case")).toBeInTheDocument(),
);
});

test("displays 'Submit' button", () => {
render(<CaseCreator />);
const button = screen.getByText("Submit");
expect(button).toBeInTheDocument();
});

test("displays 'Import' button", () => {
render(<CaseCreator />);
const button = screen.getByText("Import");
expect(button).toBeInTheDocument();
});

test("displays 'Load JSON from URL' button", () => {
render(<CaseCreator />);
const button = screen.getByText("Load JSON from URL");
expect(button).toBeInTheDocument();
});

test("shows dialog when 'Load JSON from URL' button is clicked", () => {
render(<CaseCreator />);
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(<CaseCreator />);
const fileInput = screen.getByLabelText(/Choose a file/i);
expect(fileInput).toBeInTheDocument();
});
24 changes: 20 additions & 4 deletions frontend/src/components/tests/Signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Signup />);
Expand All @@ -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(<Signup />);
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.

0 comments on commit 7307483

Please sign in to comment.