Skip to content

Commit

Permalink
Tests for FormatGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Oct 26, 2023
1 parent 77ff48a commit 68dae99
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/components/colors/Output.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</script>

<ul data-group="output {type}">
<li>
<li data-testid={`format-${format}`}>
<CopyButton text={targetColorValue} />
<span data-color-info="value">{targetColorValue}</span>
<SupportWarning {format} />
Expand Down
6 changes: 6 additions & 0 deletions test/js/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ export const HSL_BLACK: PlainColorObject = {
};

export const HSL_WHITE_SERIALIZED = serialize(HSL_WHITE, { inGamut: false });

export const OUT_OF_BOUNDED_GAMUTS: PlainColorObject = {
space: ColorSpace.get('oklch'),
coords: [1, 1, 1],
alpha: 1,
};
40 changes: 40 additions & 0 deletions test/js/lib/components/colors/FormatGroup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { render } from '@testing-library/svelte';

import FormatGroup from '$lib/components/colors/FormatGroup.svelte';
import { FORMAT_GROUPS } from '$src/lib/constants';
import { HSL_WHITE, OUT_OF_BOUNDED_GAMUTS } from '$test/fixtures';

describe('FormatGroup', () => {
it('renders selected group', () => {
const GROUP_NAME = 'sRGB Formats';
const { getByTestId, getByText } = render(FormatGroup, {
type: 'bg',
color: HSL_WHITE,
name: GROUP_NAME,
formats: FORMAT_GROUPS[GROUP_NAME]!,
});

expect(getByText(GROUP_NAME)).toBeVisible();
FORMAT_GROUPS[GROUP_NAME]?.forEach((format) => {
expect(getByTestId(`format-${format}`)).toBeVisible();
});
});

it('renders warning if out of gamut', () => {
const GROUP_NAME = 'sRGB Formats';
const { getByTestId, getByText } = render(FormatGroup, {
type: 'bg',
color: OUT_OF_BOUNDED_GAMUTS,
name: GROUP_NAME,
formats: FORMAT_GROUPS[GROUP_NAME]!,
});

expect(getByText(GROUP_NAME)).toBeVisible();
FORMAT_GROUPS[GROUP_NAME]?.forEach((format) => {
expect(getByTestId(`format-${format}`)).toBeVisible();
});
expect(
getByText('Selected color is outside the sRGB gamut.'),
).toBeVisible();
});
});

0 comments on commit 68dae99

Please sign in to comment.