-
Notifications
You must be signed in to change notification settings - Fork 2
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
3459564
commit e3b9250
Showing
24 changed files
with
854 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
/* prettier-ignore */ | ||
"recommendations": [ | ||
"csstools.postcss", | ||
"esbenp.prettier-vscode", | ||
"dbaeumer.vscode-eslint", | ||
"astro-build.astro-vscode" | ||
] | ||
"vitest.explorer", | ||
"csstools.postcss", | ||
"esbenp.prettier-vscode", | ||
"dbaeumer.vscode-eslint", | ||
"astro-build.astro-vscode" | ||
] | ||
} |
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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function deepClone<T = object>(obj: T) { | ||
const clone = structuredClone(obj) || JSON.parse(JSON.stringify(obj)) as T; | ||
|
||
return clone; | ||
} |
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,9 @@ | ||
import { rotationDegs } from '@ts/constants.ts'; | ||
|
||
const fullRotationDeg = rotationDegs.full; | ||
|
||
export function resetRotationDeg(rotationDeg: number) { | ||
const rotationQuotient = Math.round(rotationDeg / fullRotationDeg); | ||
|
||
return Math.abs(rotationQuotient * fullRotationDeg); | ||
} |
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,5 @@ | ||
import type { SpinMode } from '@types'; | ||
|
||
export function spinIsRotation(spinMode: SpinMode) { | ||
return spinMode.toLowerCase().includes('rotate'); | ||
} |
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,11 @@ | ||
import { imgStore } from '@ts/imgStore.ts'; | ||
import { it, expect, describe } from 'vitest'; | ||
|
||
describe('imgStore.activeFilter', () => { | ||
it('should update the active filter based on the given name, and allow access to its properties', () => { | ||
const activeFilterName = 'grayscale'; | ||
imgStore.activeFilter = activeFilterName; | ||
|
||
expect(imgStore.activeFilter.name).toBe(activeFilterName); | ||
}); | ||
}); |
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 { imgStore } from '@ts/imgStore.ts'; | ||
import { it, expect, describe } from 'vitest'; | ||
|
||
describe('imgStore.isEdited', () => { | ||
it('should return “true” if the image has been rotated', () => { | ||
const rotationDegs = [-450, -270, -180, -90, 90, 180, 270, 450] as const; | ||
|
||
rotationDegs.forEach((rotationDeg) => { | ||
imgStore.state.rotationDeg = rotationDeg; | ||
|
||
expect(imgStore.isEdited).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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 { imgStore } from '@ts/imgStore.ts'; | ||
import { it, expect, describe } from 'vitest'; | ||
|
||
describe('imgStore.isLandscape', () => { | ||
it('should return “true” if the image has been rotated only by multiples of 90 degrees and not 180 degrees', () => { | ||
const rotationDegs = [-450, -270, -90, 90, 270, 450] as const; | ||
|
||
rotationDegs.forEach((rotationDeg) => { | ||
imgStore.state.rotationDeg = rotationDeg; | ||
|
||
expect(imgStore.isLandscape).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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 { imgStore } from '@ts/imgStore.ts'; | ||
import { it, expect, describe } from 'vitest'; | ||
import { deepClone } from '@ts/utils/deepClone.ts'; | ||
import { resetRotationDeg } from '@ts/utils/resetRotationDeg.ts'; | ||
|
||
describe('imgStore.reset', () => { | ||
it('should correctly reset the state', () => { | ||
const initialState = deepClone(imgStore.state); | ||
const [name, extension, rotationDeg] = ['New Image', 'png', 180]; | ||
const adjustedRotationDeg = resetRotationDeg(rotationDeg); | ||
|
||
Object.assign(imgStore.state, { name, extension, rotationDeg, verticalFlip: -1 }); | ||
imgStore.reset(); | ||
|
||
expect(imgStore.state).toStrictEqual({ ...initialState, name, extension, rotationDeg: adjustedRotationDeg }); | ||
}); | ||
}); |
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 { imgStore } from '@ts/imgStore.ts'; | ||
import { it, expect, describe } from 'vitest'; | ||
|
||
describe('imgStore.title', () => { | ||
it('should set the name and extension of the image file, and return its full name (name.extension)', () => { | ||
Object.assign(imgStore.state, { name: 'New Image', extension: 'png' }); | ||
|
||
expect(imgStore.title).toMatchInlineSnapshot(`"New Image.png"`); | ||
}); | ||
}); |
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,12 @@ | ||
import { imgStore } from '@ts/imgStore.ts'; | ||
import { it, expect, describe } from 'vitest'; | ||
|
||
describe('imgStore.updateCSSFilters', () => { | ||
it('should create and/or update the CSS filters string corresponding with filter values', () => { | ||
imgStore.state.filters.find(({ name }) => name === 'grayscale')!.value = 50; | ||
imgStore.updateCSSFilters(); | ||
const { CSSFilters } = imgStore.state; | ||
|
||
expect(CSSFilters).toMatchInlineSnapshot(`"brightness(100%)grayscale(50%)blur(0px)hue-rotate(0deg)opacity(100%)contrast(100%)saturate(100%)sepia(0%)"`); | ||
}); | ||
}); |
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,21 @@ | ||
import { imgStore } from '@ts/imgStore.ts'; | ||
import { spinModes } from '@ts/constants.ts'; | ||
import { it, expect, describe } from 'vitest'; | ||
import { spinIsRotation } from '@ts/utils/spinIsRotation.ts'; | ||
|
||
describe('imgStore.updateSpinValue', () => { | ||
it('should update the rotation degree and vertical/horizontal flip values', () => { | ||
spinModes.forEach((spinMode) => { | ||
imgStore.updateSpinValue(spinMode); | ||
|
||
const { rotationDeg, verticalFlip, horizontalFlip } = imgStore.state; | ||
|
||
if (spinIsRotation(spinMode)) { | ||
expect(rotationDeg === 0 || rotationDeg % 90 === 0).toBeTruthy(); | ||
} else { | ||
expect([1, -1]).toContain(verticalFlip); | ||
expect([1, -1]).toContain(horizontalFlip); | ||
} | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
import { it, expect, describe } from 'vitest'; | ||
import { deepClone } from '@ts/utils/deepClone.ts'; | ||
|
||
describe('deepClone', () => { | ||
it('should create a deep clone of the given object', () => { | ||
const obj = { | ||
a: 1, | ||
b: true, | ||
c: 'value', | ||
d: { e: 'f' }, | ||
g: [1, '2', { h: '3' }], | ||
}; | ||
const clone = deepClone(obj); | ||
|
||
expect(clone).not.toBe(obj); | ||
expect(clone).toStrictEqual(obj); | ||
}); | ||
}); |
Oops, something went wrong.