-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adding new folders for utils to test, found one issue (#537)
* test: adding new folders for utils to test, found one issue * test: updated test to just pass * fix: prettier * test: added new test for unused string
- Loading branch information
1 parent
72277d0
commit 4dd7a6d
Showing
7 changed files
with
92 additions
and
39 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
14 changes: 14 additions & 0 deletions
14
src/components/AddContentModal/BudgetStep/__tests__/index.ts
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,14 @@ | ||
import { formatBudget } from '../utils' | ||
|
||
describe('formatBudget', () => { | ||
/** | ||
* @jest-environment jsdom | ||
* @jest-environment-options {"url": "https://jestjs.io/"} | ||
* */ | ||
it('should assert we format the budeget properly', async () => { | ||
expect(formatBudget(null)).toBe('?') | ||
expect(formatBudget(25)).toBe('25') | ||
expect(formatBudget(7000000)).toBe('7 000 000') | ||
expect(formatBudget('700000')).toBe('700000') | ||
}) | ||
}) |
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,11 @@ | ||
export function formatBudget(value: number | null) { | ||
if (value === null) { | ||
return '?' | ||
} | ||
|
||
const stringBudget = value.toLocaleString() | ||
|
||
const splittedBudget = stringBudget.split(',') | ||
|
||
return splittedBudget.join(' ') | ||
} |
36 changes: 36 additions & 0 deletions
36
src/components/AddContentModal/LocationStep/__tests__/index.ts
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,36 @@ | ||
import { validateLatitude, validateLongitude } from '../utils' | ||
|
||
describe('validateLongitude', () => { | ||
/** | ||
* @jest-environment jsdom | ||
* @jest-environment-options {"url": "https://jestjs.io/"} | ||
* */ | ||
it('should assert we validateLongitude properly', async () => { | ||
const outsideRangeErrorMsg = 'Longitude must be between -180 and 180.' | ||
const needValueErrorMsg = 'Longitude is required.' | ||
|
||
expect(validateLongitude(180)).toBe(true) | ||
expect(validateLongitude(181)).toBe(outsideRangeErrorMsg) | ||
expect(validateLongitude(179)).toBe(true) | ||
expect(validateLongitude(0)).toBe(true) | ||
expect(validateLongitude(null)).toBe(needValueErrorMsg) | ||
}) | ||
}) | ||
|
||
describe('validateLatitude', () => { | ||
/** | ||
* @jest-environment jsdom | ||
* @jest-environment-options {"url": "https://jestjs.io/"} | ||
* */ | ||
it('should assert we validateLatitude properly', async () => { | ||
const outsideRangeErrorMsg = 'Latitude must be between -90 and 90.' | ||
const needValueErrorMsg = 'Latitude is required.' | ||
|
||
expect(validateLatitude(90)).toBe(true) | ||
expect(validateLatitude(91)).toBe(outsideRangeErrorMsg) | ||
expect(validateLatitude(89)).toBe(true) | ||
expect(validateLatitude(0)).toBe(true) | ||
expect(validateLatitude(null)).toBe(true) | ||
expect(validateLatitude('abc')).toBe(needValueErrorMsg) | ||
}) | ||
}) |
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
25 changes: 25 additions & 0 deletions
25
src/components/AddContentModal/LocationStep/utils/index.ts
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,25 @@ | ||
export const validateLatitude = (valueString: string) => { | ||
const value = Number(valueString) | ||
|
||
if (value < -90 || value > 90) { | ||
return 'Latitude must be between -90 and 90.' | ||
} | ||
|
||
if (!value && value !== 0) { | ||
return 'Latitude is required.' | ||
} | ||
|
||
return true | ||
} | ||
|
||
export const validateLongitude = (value: number) => { | ||
if (value < -180 || value > 180) { | ||
return 'Longitude must be between -180 and 180.' | ||
} | ||
|
||
if (!value && value !== 0) { | ||
return 'Longitude is required.' | ||
} | ||
|
||
return true | ||
} |