Skip to content

Commit

Permalink
test: functions in file
Browse files Browse the repository at this point in the history
  • Loading branch information
LeleDallas committed May 2, 2023
1 parent a6edeaa commit 9b4cd2d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/Components/SignInForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SignIn from "../../src/Components/SignInForm"
import React from 'react';
import { expect, describe, it } from 'vitest'
import { expect, describe, it, vi } from 'vitest'
import { fireEvent, render } from '@testing-library/react';
import '@testing-library/jest-dom';
import { BrowserRouter } from "react-router-dom";
Expand Down Expand Up @@ -40,11 +40,11 @@ describe('SignIn', () => {
fireEvent.click(buttonSU)
expect(getByText("Building Owner")).toBeInTheDocument()
const buttonSubLog = queryAllByText("Sign In")
buttonSubLog.map(el => {fireEvent.click(el)})
buttonSubLog.map(el => { fireEvent.click(el) })
expect(getByText("Building Owner")).toBeInTheDocument()
const buttonSubSig = queryAllByText("Sign Up")
buttonSubSig.map(el => {fireEvent.click(el)})
buttonSubSig.map(el => { fireEvent.click(el) })
expect(getByText("Building Owner")).toBeInTheDocument()
});

});
});
69 changes: 69 additions & 0 deletions test/componentsFunctions.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { handleLoginSubmit, handleSignUpSubmit, signInButton, signUpButton } from "../src/componentsFunctions";

describe('Authentication functions', () => {
describe('signUpButton', () => {
it('should call the setError and setSwapPanel functions with the correct arguments', () => {
const setError = jest.fn();
const setSwapPanel = jest.fn();
signUpButton(setError, setSwapPanel);
expect(setError).toHaveBeenCalledWith([]);
expect(setSwapPanel).toHaveBeenCalledWith(true);
});
});

describe('signInButton', () => {
it('should call the setError and setSwapPanel functions with the correct arguments', () => {
const setError = jest.fn();
const setSwapPanel = jest.fn();
signInButton(setError, setSwapPanel);
expect(setError).toHaveBeenCalledWith([]);
expect(setSwapPanel).toHaveBeenCalledWith(false);
});
});

describe('handleLoginSubmit', () => {
it('should call setError with an error message if email or password is null', () => {
const setError = jest.fn();
handleLoginSubmit("", 'password', setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
handleLoginSubmit('email', "", setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
});

it('should not call setError if email and password are not null', () => {
const setError = jest.fn();
handleLoginSubmit('email', 'password', setError);
expect(setError).not.toHaveBeenCalled();
});
});

describe('handleSignUpSubmit', () => {
it('should call setError with an error message if any required fields are null', () => {
const setError = jest.fn();
handleSignUpSubmit(null, 'name', 'surname', 'password', 'password', 'email', 'type', setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
handleSignUpSubmit('event', "", 'surname', 'password', 'password', 'email', 'type', setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
handleSignUpSubmit('event', 'name', "", 'password', 'password', 'email', 'type', setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
handleSignUpSubmit('event', 'name', 'surname', "", 'password', 'email', 'type', setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
handleSignUpSubmit('event', 'name', 'surname', 'password', "", 'email', 'type', setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
handleSignUpSubmit('event', 'name', 'surname', 'password', 'password', "", 'type', setError);
expect(setError).toHaveBeenCalledWith(['Fill the form to continue']);
});

it('should call setError with an error message if password and passwordConf do not match', () => {
const setError = jest.fn();
handleSignUpSubmit('event', 'name', 'surname', 'password', 'different', 'email', 'type', setError);
expect(setError).toHaveBeenCalledWith(['Typed Password are different']);
});

it('should not call setError if all required fields are present and password and passwordConf match', () => {
const setError = jest.fn();
handleSignUpSubmit('event', 'name', 'surname', 'password', 'password', 'email', 'type', setError);
expect(setError).not.toHaveBeenCalled();
});
});
});

0 comments on commit 9b4cd2d

Please sign in to comment.