Skip to content

Commit

Permalink
Add no gamut map, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Dec 11, 2024
1 parent 74eac4b commit 06bd0f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const FORMATS: ColorFormatId[] = [

export type ColorGamutId = 'srgb' | 'p3' | 'rec2020';

export const GAMUTS: { name: string; format: ColorGamutId }[] = [
export const GAMUTS: { name: string; format: ColorGamutId | null }[] = [
{ name: 'None', format: null },
{ name: 'sRGB', format: 'srgb' },
{ name: 'P3', format: 'p3' },
{ name: 'Rec2020', format: 'rec2020' },
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const sliderGradient = ({
const inGamutSteps: string[] = [];
const stepWidth = 100 / (gradientSteps.length - 1);

if (channel === 'alpha') {
if (channel === 'alpha' || gamut === null) {
return gradientSteps.map((c) => display(c)).join(', ');
}

Expand Down
22 changes: 22 additions & 0 deletions test/lib/components/GamutSelect.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { fireEvent, render } from '@testing-library/svelte';
import { get } from 'svelte/store';

import Gamut from '$lib/components/GamutSelect.svelte';
import { gamut, INITIAL_VALUES, reset } from '$lib/stores';

describe('Space', () => {
afterEach(() => {
reset();
});

it('renders editable gamut select', async () => {
const { getByLabelText } = render(Gamut);

expect(get(gamut)).toBe(INITIAL_VALUES.gamut);

const select = getByLabelText('Gamut');
await fireEvent.change(select, { target: { value: 'rec2020' } });

expect(get(gamut)).toBe('rec2020');
});
});
2 changes: 1 addition & 1 deletion test/lib/components/SpaceSelect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Space', () => {
expect(get(bg).space.id).toBe(INITIAL_VALUES.format);
expect(get(fg).space.id).toBe(INITIAL_VALUES.format);

const select = getByLabelText('Color Format');
const select = getByLabelText('Format');
await fireEvent.change(select, { target: { value: 'hsl' } });

expect(get(bg).space.id).toBe('hsl');
Expand Down

0 comments on commit 06bd0f4

Please sign in to comment.