Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional login page test #91

Merged
merged 14 commits into from
Apr 16, 2024
Merged
2 changes: 0 additions & 2 deletions app/src/pages/login/Login.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import styles from "./Login.css"
import axios from "axios"
import { useState } from 'react';
import { useNavigate } from "react-router-dom";

const Login = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const navigate = useNavigate()

async function sendSubmit(foo) {

Expand Down
46 changes: 32 additions & 14 deletions app/src/tests/LoginPage.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import LoginPage from '../pages/login/Login.js';
import {
Routes,
Route,
BrowserRouter
} from "react-router-dom";
import { Routes, Route, BrowserRouter } from "react-router-dom";


describe('LoginPage', () => {
it('renders without crashing', () => {
const {getByPlaceholderText} = render(
<BrowserRouter>
<Routes>
<Route path="/" element={<LoginPage />} />
</Routes>
</BrowserRouter>
);

const {getByPlaceholderText, getByText} = render(<LoginPage />);

//Check that the h1 title is there
expect(getByText('LifeQuest')).toBeInTheDocument();

//Check that there is an email input field
const emailInput = getByPlaceholderText(/Email/i);
expect(emailInput).toHaveAttribute('type', 'email');

//Check that there is a password input field
const passwordInput = getByPlaceholderText(/Password/i);
expect(passwordInput).toHaveAttribute('type', 'password');

//Check that the login and signup buttons are there
expect(getByText('Login')).toBeInTheDocument();
expect(getByText('Signup')).toBeInTheDocument();

});

it('input field updates value with current input', () => {

const {getByPlaceholderText} = render(<LoginPage />);
const emailInput = getByPlaceholderText(/Email/i);
const passwordInput = getByPlaceholderText(/Password/i);

// ai-gen start (ChatGPT-3.5, 1)
// Simulate typing into the input field
fireEvent.change(emailInput, { target: { value: 'TestUserName' } });
fireEvent.change(passwordInput, { target: { value: 'Pa$$w0rd' } });

// Ensure that the state has been updated correctly
expect(emailInput.value).toBe('TestUserName');
expect(passwordInput.value).toBe('Pa$$w0rd');

// ai-gen end

});

});
Loading