Skip to content

Commit

Permalink
migrate more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gka committed Jul 29, 2024
1 parent 1196dc9 commit 0b2d348
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 292 deletions.
81 changes: 0 additions & 81 deletions test/lch.test.cjs

This file was deleted.

60 changes: 60 additions & 0 deletions test/lch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, it, expect } from 'vitest';
import chroma from '../index.js';

describe('Some tests for chroma.lch()', () => {
describe('lch grayscale', () => {
const grays = [
{ l: 0, hex: '#000000' },
{ l: 25, hex: '#3b3b3b' },
{ l: 50, hex: '#777777' },
{ l: 75, hex: '#b9b9b9' },
{ l: 100, hex: '#ffffff' }
];

for (const { l, hex } of grays) {
it(`l = ${l}`, () => {
expect(chroma.lch(l, 0, 0).hex()).toEqual(hex);
});
}
});

describe('lch hues', () => {
const hues = [
{ h: 0, hex: '#dc2c7a' },
{ h: 60, hex: '#bd5c00' },
{ h: 120, hex: '#548400' },
{ h: 180, hex: '#009175' },
{ h: 240, hex: '#008cde' },
{ h: 300, hex: '#6f67df' },
{ h: 360, hex: '#dc2c7a' }
];

for (const { h, hex } of hues) {
it(`h = ${h}`, () => {
expect(chroma.lch(50, 70, h).hex()).toEqual(hex);
});
}
});

describe('lch clipping', () => {
it('20 not clipped', () => {
expect(chroma.lch(90, 20, 80).clipped()).toEqual(false);
});

it('40 clipped', () => {
expect(chroma.lch(90, 40, 80).clipped()).toEqual(true);
});

it('60 clipped', () => {
expect(chroma.lch(90, 60, 80).clipped()).toEqual(true);
});

it('80 clipped', () => {
expect(chroma.lch(90, 80, 80).clipped()).toEqual(true);
});

it('100 clipped', () => {
expect(chroma.lch(90, 100, 80).clipped()).toEqual(true);
});
});
});
67 changes: 0 additions & 67 deletions test/manipulate.test.cjs

This file was deleted.

48 changes: 48 additions & 0 deletions test/manipulate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, it, expect } from 'vitest';
import chroma from '../index.js';

describe('Manipulating colors', () => {
it('darken', () => {
const red = chroma('red');
expect(red.darken().hex()).toEqual('#c20000');
expect(red.darker().hex()).toEqual('#c20000');
});

it('darken more', () => {
const red = chroma('red');
expect(red.darken(2).hex()).toEqual('#890000');
expect(red.darken(10).hex()).toEqual('#000000');
});

it('brighten', () => {
const red = chroma('red');
expect(red.brighten().hex()).toEqual('#ff5a36');
expect(red.brighter().hex()).toEqual('#ff5a36');
});

it('brighten more', () => {
const red = chroma('red');
expect(red.brighten(2).hex()).toEqual('#ff9264');
expect(red.brighter(10).hex()).toEqual('#ffffff');
});

it('saturate', () => {
const red = chroma('red');
expect(red.saturate().hex()).toEqual('#ff0000');
});

it('desaturate', () => {
const red = chroma('red');
expect(red.desaturate().hex()).toEqual('#ee3a20');
});

it('desaturate more', () => {
const red = chroma('red');
expect(red.desaturate(2).hex()).toEqual('#db5136');
});

it('desaturate too much', () => {
const red = chroma('red');
expect(red.desaturate(400).hex()).toEqual('#7f7f7f');
});
});
Loading

0 comments on commit 0b2d348

Please sign in to comment.