-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6edeaa
commit 9b4cd2d
Showing
2 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |