-
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.
feat: add unit test to shadows generator
- Loading branch information
1 parent
f0275a5
commit f42fe6f
Showing
3 changed files
with
101 additions
and
7 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,7 @@ | ||
export interface Shadow { | ||
offsetX: number | ||
offsetY: number | ||
radius: number | ||
spreadRadius?: number | ||
color: string | ||
} |
93 changes: 93 additions & 0 deletions
93
theme/theme-shadows-generator/src/unit/generate-shadows.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,93 @@ | ||
import { FigmaThemeShadowsGenerator } from '../FigmaThemeShadowsGenerator.js' | ||
|
||
describe('FigmaThemeShadowsGenerator', () => { | ||
let generator: FigmaThemeShadowsGenerator | ||
|
||
beforeEach(() => { | ||
generator = new FigmaThemeShadowsGenerator() | ||
}) | ||
|
||
it('should correctly identify and return shadows', () => { | ||
const nodes = [ | ||
{ | ||
type: 'DROP_SHADOW', | ||
offset: { x: 10, y: 20 }, | ||
radius: 15, | ||
spread: 5, | ||
color: { r: 1, g: 0, b: 0, a: 0.5 }, | ||
}, | ||
{ | ||
type: 'INNER_SHADOW', | ||
offset: { x: 5, y: 10 }, | ||
radius: 10, | ||
color: { r: 0, g: 0, b: 0, a: 0.75 }, | ||
}, | ||
{ | ||
type: 'TEXT', | ||
style: { fontSize: 16 }, | ||
}, | ||
] | ||
|
||
const shadows = generator.getShadows(nodes) | ||
|
||
expect(shadows).toEqual({ | ||
red: '10px 20px 15px 5px rgba(255, 0, 0, 0.50)', | ||
black: '5px 10px 10px rgba(0, 0, 0, 0.75)', | ||
}) | ||
}) | ||
|
||
it('should generate shadows correctly', () => { | ||
const file = { | ||
document: { | ||
children: [ | ||
{ | ||
type: 'DROP_SHADOW', | ||
offset: { x: 10, y: 20 }, | ||
radius: 15, | ||
spread: 5, | ||
color: { r: 1, g: 0, b: 0, a: 0.5 }, | ||
}, | ||
{ | ||
type: 'INNER_SHADOW', | ||
offset: { x: 5, y: 10 }, | ||
radius: 10, | ||
color: { r: 0, g: 0, b: 0, a: 0.75 }, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
// @ts-ignore | ||
const result = generator.generate(file) | ||
|
||
expect(result).toEqual({ | ||
name: 'shadows', | ||
content: `export const shadows = { | ||
"red": "10px 20px 15px 5px rgba(255, 0, 0, 0.50)", | ||
"black": "5px 10px 10px rgba(0, 0, 0, 0.75)" | ||
}`, | ||
}) | ||
}) | ||
|
||
it('should return empty object if no shadows found', () => { | ||
const nodes = [{ type: 'TEXT', style: { fontSize: 16 } }] | ||
|
||
const shadows = generator.getShadows(nodes) | ||
|
||
expect(shadows).toEqual({}) | ||
|
||
const file = { | ||
document: { | ||
children: nodes, | ||
}, | ||
} | ||
|
||
// @ts-ignore | ||
const result = generator.generate(file) | ||
|
||
expect(result).toEqual({ | ||
name: 'shadows', | ||
content: `export const shadows = {}`, | ||
}) | ||
}) | ||
}) |