-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add linting validation for cubicBezier token schema (#1078)
- Loading branch information
1 parent
08186e7
commit de32449
Showing
5 changed files
with
39 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/primitives': patch | ||
--- | ||
|
||
Add linting validation for cubicBezier token schema |
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 {z} from 'zod' | ||
import {baseToken} from './baseToken.js' | ||
import {referenceValue} from './referenceValue.js' | ||
import {tokenType} from './tokenType.js' | ||
|
||
export const cubicBezierToken = baseToken.extend({ | ||
$value: z.union([z.array(z.number()).length(4), referenceValue]), | ||
$type: tokenType('cubicBezier'), | ||
}) |
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,22 @@ | ||
import {cubicBezierToken} from './cubicBezierToken.js' | ||
|
||
describe('Schema: cubicBezier', () => { | ||
const validToken = { | ||
$value: [0, 0, 1, 1], | ||
$type: 'cubicBezier', | ||
$description: 'a cubicBezier token', | ||
} | ||
|
||
it('passes on valid cubicBezier values', () => { | ||
expect(cubicBezierToken.safeParse(validToken).success).toStrictEqual(true) | ||
expect(cubicBezierToken.safeParse({...validToken, $value: [0.2, 0.3, 0.85, 1]}).success).toStrictEqual(true) | ||
}) | ||
|
||
it('fails on invalid cubicBezier values', () => { | ||
expect(cubicBezierToken.safeParse({...validToken, $value: ['1', 1, 0, 0]}).success).toStrictEqual(false) | ||
expect(cubicBezierToken.safeParse({...validToken, $value: [0, 1]}).success).toStrictEqual(false) | ||
expect(cubicBezierToken.safeParse({...validToken, $value: [0, 1, 1, 0, 0, 1]}).success).toStrictEqual(false) | ||
expect(cubicBezierToken.safeParse({...validToken, $value: 1}).success).toStrictEqual(false) | ||
expect(cubicBezierToken.safeParse({...validToken, $value: 'linear'}).success).toStrictEqual(false) | ||
}) | ||
}) |
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