-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from arnelenero/feature/color-engine
Feature/color engine
- Loading branch information
Showing
34 changed files
with
1,081 additions
and
158 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { clamp } from '../utils' | ||
|
||
describe('clamp', () => { | ||
it('returns the same value if it is within range', () => { | ||
expect(clamp(50, 0, 100)).toBe(50) | ||
}) | ||
|
||
it('limits the value to the minimum', () => { | ||
expect(clamp(-1, 0, 100)).toBe(0) | ||
}) | ||
|
||
it('limits the value to the maximum', () => { | ||
expect(clamp(101, 0, 100)).toBe(100) | ||
}) | ||
}) |
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,28 @@ | ||
import angle from '../angle' | ||
|
||
describe('angle', () => { | ||
let values: string[] | ||
|
||
values = ['180deg', '180'] | ||
values.forEach(val => { | ||
it(`extracts straight value if angle string is in degrees (default): ${val}`, () => { | ||
expect(angle(val)).toBe(180) | ||
}) | ||
}) | ||
|
||
values = ['3.14159265rad', '200grad', '0.5turn'] | ||
values.forEach(val => { | ||
it(`converts value to degrees if angle string is in a different unit: ${val}`, () => { | ||
expect(Math.round(angle(val))).toBe(180) | ||
}) | ||
}) | ||
|
||
it('normalizes value to range [0..360) degrees', () => { | ||
expect(angle('-90deg')).toBe(270) | ||
expect(angle('360deg')).toBe(0) | ||
}) | ||
|
||
it('returns NaN if argument is not a valid numeric value', () => { | ||
expect(angle('invalid')).toBeNaN() | ||
}) | ||
}) |
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,28 @@ | ||
import colorString from '../colorString' | ||
|
||
describe('colorString', () => { | ||
it('returns a hex string from RGB object when alpha = 1', () => { | ||
const obj = { r: 255, g: 0, b: 255, a: 1 } | ||
expect(colorString(obj)).toBe('#FF00FF') | ||
}) | ||
|
||
it('returns a hex string from HSL object when alpha = 1', () => { | ||
const obj = { h: 240, s: 100, l: 50, a: 1 } | ||
expect(colorString(obj)).toBe('#0000FF') | ||
}) | ||
|
||
it('returns an rgba() string from RGB object when alpha < 1', () => { | ||
const obj = { r: 255, g: 0, b: 255, a: 0.6 } | ||
expect(colorString(obj)).toBe('rgba(255, 0, 255, 0.6)') | ||
}) | ||
|
||
it('returns an rgba() string from HSL object when alpha < 1', () => { | ||
const obj = { h: 240, s: 100, l: 50, a: 0.8 } | ||
expect(colorString(obj)).toBe('rgba(0, 0, 255, 0.8)') | ||
}) | ||
|
||
it('rounds off r,g,b values in rgba() strings', () => { | ||
const obj = { r: 127.5, g: 64.3333, b: 255, a: 0.6 } | ||
expect(colorString(obj)).toBe('rgba(128, 64, 255, 0.6)') | ||
}) | ||
}) |
Oops, something went wrong.