-
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.
refactor(frontend): vitest-v2 (#155)
* chore(frontend): update vitest to v2 * refactor(frontend): existing helpers tests * refactor(frontend): SettingsValidator tests * refactor(frontend): utilities improvements * fix(frontend): getRandomNumber
- Loading branch information
1 parent
c296bd2
commit 0d5a172
Showing
37 changed files
with
791 additions
and
607 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
6 changes: 3 additions & 3 deletions
6
apps/frontend/src/lib/helpers/__tests__/colors/getRandomHexColor.test.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
2 changes: 1 addition & 1 deletion
2
apps/frontend/src/lib/helpers/__tests__/file/addImageSizesToFileName.test.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
10 changes: 10 additions & 0 deletions
10
apps/frontend/src/lib/helpers/__tests__/file/bytesToMegabytes.test.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,10 @@ | ||
import { bytesToMegabytes } from '@helpers/file/bytesToMegabytes' | ||
import { BYTES_IN_MB } from '@helpers/file/constants' | ||
|
||
describe('helpers/file - bytesToMegabytes', () => { | ||
it('should convert bytes to megabytes correctly', () => { | ||
expect(bytesToMegabytes(BYTES_IN_MB)).toBe(1) | ||
expect(bytesToMegabytes(BYTES_IN_MB * 4)).toBe(4) | ||
expect(bytesToMegabytes(BYTES_IN_MB / 2)).toBe(0.5) | ||
}) | ||
}) |
17 changes: 17 additions & 0 deletions
17
apps/frontend/src/lib/helpers/__tests__/file/createFileFromBlob.test.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,17 @@ | ||
import { createFileFromBlob } from '@helpers/file/createFileFromBlob' | ||
|
||
describe('helpers/file - createFileFromBlob', () => { | ||
it('should create a file object from a blob', () => { | ||
const fileName = 'lorem.txt' | ||
const fileType = 'text/plain' | ||
|
||
const blob = new Blob(['Lorem ipsum dolor sit amet, consectetur adipisicing elit'], { | ||
type: fileType | ||
}) | ||
const file = createFileFromBlob(blob, fileName) | ||
|
||
expect(file).toBeInstanceOf(File) | ||
expect(file.name).toBe(fileName) | ||
expect(file.type).toBe(fileType) | ||
}) | ||
}) |
21 changes: 13 additions & 8 deletions
21
apps/frontend/src/lib/helpers/__tests__/file/cropFileName.test.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
11 changes: 4 additions & 7 deletions
11
apps/frontend/src/lib/helpers/__tests__/file/cropImageFileType.test.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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import { cropImageFileType } from '@helpers/file/cropImageFileType' | ||
|
||
describe('@lib/helpers/file/cropImageFileType', () => { | ||
it('should crop the file type correctly', () => { | ||
expect(cropImageFileType('image/png')).toBe('png') | ||
expect(cropImageFileType('image/jpg')).toBe('jpg') | ||
expect(cropImageFileType('image/jpeg')).toBe('jpeg') | ||
expect(cropImageFileType('image/webp')).toBe('webp') | ||
}) | ||
describe('helpers/file - cropImageFileType', () => { | ||
it.each(['png', 'jpg', 'jpeg', 'webp'])('should crop the file type correctly (%s)', type => | ||
expect(cropImageFileType(`image/${type}`)).toBe(type) | ||
) | ||
}) |
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
2 changes: 1 addition & 1 deletion
2
apps/frontend/src/lib/helpers/__tests__/file/isValidFileType.test.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
10 changes: 10 additions & 0 deletions
10
apps/frontend/src/lib/helpers/__tests__/getRandomBoolean.test.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,10 @@ | ||
import { getRandomBoolean } from '@helpers/getRandomBoolean' | ||
|
||
describe('helpers - getRandomBoolean', () => { | ||
it('should return a random boolean', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const result = getRandomBoolean() | ||
expect(typeof result).toBe('boolean') | ||
} | ||
}) | ||
}) |
16 changes: 16 additions & 0 deletions
16
apps/frontend/src/lib/helpers/__tests__/getRandomNumber.test.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,16 @@ | ||
import { getRandomNumber } from '@helpers/getRandomNumber' | ||
|
||
describe('helpers - getRandomNumber', () => { | ||
it.each([ | ||
[0, 0], | ||
[0, 10, 2], | ||
[20, 35], | ||
[-10, 20], | ||
[10, 10] | ||
])('should return a random number value', (...args) => { | ||
const [from, to, precision] = args | ||
const result = getRandomNumber(from, to, precision) | ||
expect(result).not.toBeLessThan(from) | ||
expect(result).not.toBeGreaterThan(to) | ||
}) | ||
}) |
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
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 @@ | ||
export const getRandomBoolean = (): boolean => Math.random() < 0.5 |
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,10 @@ | ||
export const getRandomNumber = (min: number, max: number, precision?: number): number => { | ||
const floating = typeof precision === 'number' | ||
let randomValue = Math.random() * (max - min) + min | ||
|
||
if (floating) { | ||
randomValue = parseFloat(randomValue.toPrecision(precision)) | ||
} | ||
|
||
return randomValue | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.