Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions test/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,96 @@ tape('gamma transfer function', t => {
t.equal(formatHex(brighten('#cc0033')), '#ff0070');
t.end();
});

tape('when mode is null and color is rgb string', t => {
let increaser = mapper(v => v + 0.1, null);

// might be incorrect
t.throws(() => {
increaser('#cc0033');
}, "Cannot read properties of undefined (reading 'channels')");
t.end();
});

tape('when mode is null and color is rgb', t => {
let increaser = mapper(v => v + 0.1, null);
const res = increaser({ mode: 'rgb', r: 0.8, g: 0, b: 0.2 });

// might be incorrect
t.equal(res.mode, null);
t.end();
});

tape('when mode is null and preserve_mode is true', t => {
let increaser = mapper(v => v + 1, null, true);

// might be incorrect
t.throws(
() => {
const res = increaser({ mode: 'rgb', r: 0.8, g: 0, b: 0.2 });
console.log(res);
},
{ message: "Cannot read properties of undefined (reading 'rgb')" }
);
t.end();
});

tape('when mode is undefined and preserve_mode is true', t => {
let decreaseMapper = mapper(v => v - 0.1, undefined, true);
const res = decreaseMapper('#cc0033');
t.equal(res.mode, 'rgb');
t.end();
});

tape('when mode is hsl and preserve_mode is true', t => {
let increaser = mapper(v => v + 0.1, 'hsl', true);
const res = increaser('#cc0033');
t.equal(res.mode, 'rgb');
t.end();
});

tape('when mode is hsl and preserve_mode is false', t => {
let increaser = mapper(v => v + 0.1, 'hsl', false);
const res = increaser('#cc0033');
t.equal(res.mode, 'hsl');
t.end();
});

tape('when mode is oklch and preserve_mode is false', t => {
let increaser = mapper(v => v + 0.1, 'oklch', false);
const res = increaser('#cc0033');
t.equal(res.mode, 'oklch');
t.end();
});

tape(
`when input color is oklch('color(--oklch 30 0.5 1 / 0.25)') and when mode is hsl and preserve_mode is false`,
t => {
let increaser = mapper(v => v + 0.1, 'hsl', false);
const res = increaser({
mode: 'oklch',
alpha: 0.25,
l: 30,
c: 0.5,
h: 1
});
t.equal(res.mode, 'hsl');
t.end();
}
);

tape(
`when input color is oklch('color(--oklch 30 0.5 1 / 0.25)') and when mode is hsl and preserve_mode is true`,
t => {
let increaser = mapper(v => v + 0.1, 'hsl', true);
const res = increaser({
mode: 'oklch',
alpha: 0.25,
l: 30,
c: 0.5,
h: 1
});
t.equal(res.mode, 'oklch');
t.end();
}
);