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

Frontend create event unit test #243

Merged
merged 3 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/Tests/__mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = 'test-file-stub';

44 changes: 44 additions & 0 deletions frontend/src/Tests/createevent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {checkIfDateIsLater,checkIfNumber} from "../Views/Create Event/CreateEventPage";

test("Check if dates are compared correctly. First argument must be before the second one.",()=>{
expect(checkIfDateIsLater("2014-11-30T23:00:00-08:00","2014-11-30T23:01:00-08:00")).toBe(true)
expect(checkIfDateIsLater("2021-01-12T13:42:00+03:00","2021-01-12T13:41:00+03:00")).toBe(false)

expect(checkIfDateIsLater("2014-11-30T22:00:00-08:00","2014-11-30T23:00:00-08:00")).toBe(true)
expect(checkIfDateIsLater("2021-01-12T15:42:00+03:00","2021-01-12T14:42:00+03:00")).toBe(false)

expect(checkIfDateIsLater("Sat Nov 13 10:45:00 2021","Sat Nov 14 10:45:00 2021")).toBe(true)
expect(checkIfDateIsLater("12/17/1997 07:37:16.00 PST","12/16/1997 07:37:16.00 PST")).toBe(false)

expect(checkIfDateIsLater("2014-11-30T23:00:00-08:00","2014-12-30T23:00:00-08:00")).toBe(true)
expect(checkIfDateIsLater("2021-02-12T13:41:00+03:00","2021-01-12T13:41:00+03:00")).toBe(false)

expect(checkIfDateIsLater("2014-11-30T23:00:00-08:00","2015-11-30T23:00:00-08:00")).toBe(true)
expect(checkIfDateIsLater("2021-01-12T13:42:00+03:00","2020-01-12T13:42:00+03:00")).toBe(false)
})

test("Check if integer strings are identified correctly",()=>{
expect(checkIfNumber(1)).toBe(true)
expect(checkIfNumber(12)).toBe(true)
expect(checkIfNumber(100)).toBe(true)
expect(checkIfNumber(1.0)).toBe(true)
expect(checkIfNumber(1.00001)).toBe(true)
expect(checkIfNumber(0.900000)).toBe(true)

expect(checkIfNumber("1")).toBe(true)
expect(checkIfNumber("10")).toBe(true)
expect(checkIfNumber("110")).toBe(true)
expect(checkIfNumber("0.9")).toBe(true)
expect(checkIfNumber("1.0")).toBe(true)
expect(checkIfNumber("1.0000001")).toBe(true)
expect(checkIfNumber("12.0 ")).toBe(true)


expect(checkIfNumber("11a")).toBe(false)
expect(checkIfNumber("berkay123")).toBe(false)
expect(checkIfNumber("a12.3")).toBe(false)
expect(checkIfNumber("12.3a")).toBe(false)
expect(checkIfNumber("12 3")).toBe(false)
expect(checkIfNumber("11. 34")).toBe(false)
expect(checkIfNumber("a12")).toBe(false)
})