Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
Comment thread
dmytrokirpa marked this conversation as resolved.
import { renderHook } from '@testing-library/react-hooks';
import { useAlphaSlider_unstable } from './useAlphaSlider';
import { ColorPickerProvider } from '../../contexts/colorPicker';

describe('useAlphaSlider', () => {
it('uses the default shape', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useAlphaSlider_unstable({}, ref));

expect(result.current.shape).toBe('rounded');
});

it('uses the shape from context', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useAlphaSlider_unstable({}, ref), {
wrapper: ({ children }: { children: React.ReactNode }) => (
<ColorPickerProvider value={{ color: undefined, shape: 'square', requestChange: jest.fn() }}>
{children}
</ColorPickerProvider>
),
});

expect(result.current.shape).toBe('square');
});

it('prefers the shape prop over context', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useAlphaSlider_unstable({ shape: 'rounded' }, ref), {
wrapper: ({ children }: { children: React.ReactNode }) => (
<ColorPickerProvider value={{ color: undefined, shape: 'square', requestChange: jest.fn() }}>
{children}
</ColorPickerProvider>
),
});

expect(result.current.shape).toBe('rounded');
});

it('uses the shape prop', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useAlphaSlider_unstable({ shape: 'square' }, ref));

expect(result.current.shape).toBe('square');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { ColorPickerProvider } from '../../contexts/colorPicker';
import { useColorArea_unstable } from './useColorArea';

describe('useColorArea', () => {
it('uses the default shape', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useColorArea_unstable({}, ref));

expect(result.current.shape).toBe('rounded');
});

it('uses the shape from context', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useColorArea_unstable({}, ref), {
wrapper: ({ children }: { children: React.ReactNode }) => (
<ColorPickerProvider value={{ color: undefined, shape: 'square', requestChange: jest.fn() }}>
{children}
</ColorPickerProvider>
),
});

expect(result.current.shape).toBe('square');
});

it('prefers the shape prop over context', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useColorArea_unstable({ shape: 'rounded' }, ref), {
wrapper: ({ children }: { children: React.ReactNode }) => (
<ColorPickerProvider value={{ color: undefined, shape: 'square', requestChange: jest.fn() }}>
{children}
</ColorPickerProvider>
),
});

expect(result.current.shape).toBe('rounded');
});

it('uses the shape prop', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useColorArea_unstable({ shape: 'square' }, ref));

expect(result.current.shape).toBe('square');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { act, renderHook } from '@testing-library/react-hooks';
import { useColorPicker_unstable } from './useColorPicker';

describe('useColorPicker', () => {
it('returns state based on props', () => {
const color = { h: 120, s: 0.5, v: 0.75 };
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useColorPicker_unstable({ color, shape: 'square' }, ref));

expect(result.current.color).toBe(color);
expect(result.current.shape).toBe('square');
});

it('forwards requested color changes', () => {
const onColorChange = jest.fn();
const color = { h: 240, s: 0.25, v: 0.5 };
const event = {} as React.ChangeEvent<HTMLInputElement>;
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useColorPicker_unstable({ onColorChange }, ref));

act(() => result.current.requestChange(event, { color }));

expect(onColorChange).toHaveBeenCalledTimes(1);
expect(onColorChange).toHaveBeenCalledWith(event, {
type: 'change',
event,
color,
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { ColorPickerProvider } from '../../contexts/colorPicker';
import { useColorSlider_unstable } from './useColorSlider';

describe('useColorSlider', () => {
it('uses the default shape', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useColorSlider_unstable({}, ref));

expect(result.current.shape).toBe('rounded');
});

it('uses the shape from context', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useColorSlider_unstable({}, ref), {
wrapper: ({ children }: { children: React.ReactNode }) => (
<ColorPickerProvider value={{ color: undefined, shape: 'square', requestChange: jest.fn() }}>
{children}
</ColorPickerProvider>
),
});

expect(result.current.shape).toBe('square');
});

it('prefers the shape prop over context', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useColorSlider_unstable({ shape: 'rounded' }, ref), {
wrapper: ({ children }: { children: React.ReactNode }) => (
<ColorPickerProvider value={{ color: undefined, shape: 'square', requestChange: jest.fn() }}>
{children}
</ColorPickerProvider>
),
});

expect(result.current.shape).toBe('rounded');
});

it('uses the shape prop', () => {
const ref = React.createRef<HTMLInputElement>();
const { result } = renderHook(() => useColorSlider_unstable({ shape: 'square' }, ref));

expect(result.current.shape).toBe('square');
});
});
Loading