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,95 @@
import * as React from 'react';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-react-components/Avatar Converged 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Avatar Converged.badgeMask.normal.chromium.png 4 Changed
vr-tests-react-components/Positioning 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Positioning.Positioning end.chromium.png 16 Changed
vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png 314 Changed
vr-tests-react-components/ProgressBar converged 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/ProgressBar converged.Indeterminate + thickness.default.chromium.png 41 Changed
vr-tests-react-components/ProgressBar converged.Indeterminate + thickness - Dark Mode.default.chromium.png 34 Changed
vr-tests-react-components/Skeleton converged 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Skeleton converged.Opaque Skeleton with circle - High Contrast.default.chromium.png 1 Changed
vr-tests-react-components/TagPicker 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/TagPicker.disabled - Dark Mode.disabled input hover.chromium.png 658 Changed
vr-tests-react-components/TagPicker.disabled - RTL.disabled input hover.chromium.png 635 Changed

There were 2 duplicate changes discarded. Check the build logs for more information.

import { act, renderHook } from '@testing-library/react-hooks';
import { SwatchPickerProvider, swatchPickerContextDefaultValue } from '../../contexts/swatchPicker';
import type { SwatchPickerContextValue } from '../../contexts/swatchPicker';
import { useColorSwatch_unstable } from './useColorSwatch';

const props = { color: '#ff0000', value: 'red' };

const createWrapper =
(value: Partial<SwatchPickerContextValue>) =>
({ children }: { children: React.ReactNode }) =>
<SwatchPickerProvider value={{ ...swatchPickerContextDefaultValue, ...value }}>{children}</SwatchPickerProvider>;

describe('useColorSwatch', () => {
it('uses the default size and shape', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useColorSwatch_unstable(props, ref));

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

it('uses the size and shape from context', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useColorSwatch_unstable(props, ref), {
wrapper: createWrapper({ shape: 'circular', size: 'large' }),
});

expect(result.current.size).toBe('large');
expect(result.current.shape).toBe('circular');
});

it('prefers the size and shape props over context', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(
() => useColorSwatch_unstable({ ...props, shape: 'rounded', size: 'extra-small' }, ref),
{ wrapper: createWrapper({ shape: 'circular', size: 'large' }) },
);

expect(result.current.size).toBe('extra-small');
expect(result.current.shape).toBe('rounded');
});

it('uses the radio role outside of a grid', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useColorSwatch_unstable(props, ref));

expect(result.current.root.role).toBe('radio');
expect(result.current.root['aria-checked']).toBe(false);
});

it('uses the gridcell role inside a grid', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useColorSwatch_unstable(props, ref), {
wrapper: createWrapper({ isGrid: true }),
});

expect(result.current.root.role).toBe('gridcell');
expect(result.current.root['aria-selected']).toBe(false);
});

it('uses the selected value from context', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useColorSwatch_unstable(props, ref), {
wrapper: createWrapper({ selectedValue: 'red' }),
});

expect(result.current.selected).toBe(true);
expect(result.current.root['aria-checked']).toBe(true);
});

it('renders a disabled icon by default', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useColorSwatch_unstable(props, ref));

expect(result.current.disabledIcon?.children).toBeDefined();
});

it('forwards requested selection changes', () => {
const requestSelectionChange = jest.fn();
const event = {} as React.MouseEvent<HTMLButtonElement>;
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useColorSwatch_unstable(props, ref), {
wrapper: createWrapper({ requestSelectionChange }),
});

act(() => result.current.root.onClick?.(event));

expect(requestSelectionChange).toHaveBeenCalledTimes(1);
expect(requestSelectionChange).toHaveBeenCalledWith(event, {
selectedValue: 'red',
selectedSwatch: '#ff0000',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { SwatchPickerProvider, swatchPickerContextDefaultValue } from '../../contexts/swatchPicker';
import type { SwatchPickerContextValue } from '../../contexts/swatchPicker';
import { useEmptySwatch_unstable } from './useEmptySwatch';

const createWrapper =
(value: Partial<SwatchPickerContextValue>) =>
({ children }: { children: React.ReactNode }) =>
<SwatchPickerProvider value={{ ...swatchPickerContextDefaultValue, ...value }}>{children}</SwatchPickerProvider>;

describe('useEmptySwatch', () => {
it('uses the default size and shape', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useEmptySwatch_unstable({}, ref));

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

it('uses the size and shape from context', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useEmptySwatch_unstable({}, ref), {
wrapper: createWrapper({ shape: 'circular', size: 'large' }),
});

expect(result.current.size).toBe('large');
expect(result.current.shape).toBe('circular');
});

it('prefers the size and shape props over context', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useEmptySwatch_unstable({ shape: 'rounded', size: 'extra-small' }, ref), {
wrapper: createWrapper({ shape: 'circular', size: 'large' }),
});

expect(result.current.size).toBe('extra-small');
expect(result.current.shape).toBe('rounded');
});

it('uses the radio role outside of a grid', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useEmptySwatch_unstable({}, ref));

expect(result.current.root.role).toBe('radio');
expect(result.current.root['aria-checked']).toBe(false);
});

it('uses the gridcell role inside a grid', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useEmptySwatch_unstable({}, ref), {
wrapper: createWrapper({ isGrid: true }),
});

expect(result.current.root.role).toBe('gridcell');
expect(result.current.root['aria-checked']).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as React from 'react';
import { act, renderHook } from '@testing-library/react-hooks';
import { SwatchPickerProvider, swatchPickerContextDefaultValue } from '../../contexts/swatchPicker';
import type { SwatchPickerContextValue } from '../../contexts/swatchPicker';
import { useImageSwatch_unstable } from './useImageSwatch';

const props = { src: 'image.png', value: 'image' };

const createWrapper =
(value: Partial<SwatchPickerContextValue>) =>
({ children }: { children: React.ReactNode }) =>
<SwatchPickerProvider value={{ ...swatchPickerContextDefaultValue, ...value }}>{children}</SwatchPickerProvider>;

describe('useImageSwatch', () => {
it('uses the default size and shape', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useImageSwatch_unstable(props, ref));

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

it('uses the size and shape from context', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useImageSwatch_unstable(props, ref), {
wrapper: createWrapper({ shape: 'circular', size: 'large' }),
});

expect(result.current.size).toBe('large');
expect(result.current.shape).toBe('circular');
});

it('prefers the size and shape from context over props', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(
() => useImageSwatch_unstable({ ...props, shape: 'rounded', size: 'extra-small' }, ref),
{ wrapper: createWrapper({ shape: 'circular', size: 'large' }) },
);

expect(result.current.size).toBe('large');
expect(result.current.shape).toBe('circular');
});

it('uses the radio role outside of a grid', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useImageSwatch_unstable(props, ref));

expect(result.current.root.role).toBe('radio');
expect(result.current.root['aria-checked']).toBe(false);
});

it('uses the gridcell role inside a grid', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useImageSwatch_unstable(props, ref), {
wrapper: createWrapper({ isGrid: true }),
});

expect(result.current.root.role).toBe('gridcell');
expect(result.current.root['aria-selected']).toBe(false);
});

it('uses the selected value from context', () => {
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useImageSwatch_unstable(props, ref), {
wrapper: createWrapper({ selectedValue: 'image' }),
});

expect(result.current.selected).toBe(true);
expect(result.current.root['aria-checked']).toBe(true);
});

it('forwards requested selection changes', () => {
const requestSelectionChange = jest.fn();
const event = {} as React.MouseEvent<HTMLButtonElement>;
const ref = React.createRef<HTMLButtonElement>();
const { result } = renderHook(() => useImageSwatch_unstable(props, ref), {
wrapper: createWrapper({ requestSelectionChange }),
});

act(() => result.current.root.onClick?.(event));

expect(requestSelectionChange).toHaveBeenCalledTimes(1);
expect(requestSelectionChange).toHaveBeenCalledWith(event, {
selectedValue: 'image',
selectedSwatch: 'image.png',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as React from 'react';
import { act, renderHook } from '@testing-library/react-hooks';
import { useSwatchPicker_unstable } from './useSwatchPicker';

describe('useSwatchPicker', () => {
it('uses the default size, shape and spacing', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPicker_unstable({}, ref));

expect(result.current.size).toBe('medium');
expect(result.current.shape).toBeUndefined();
expect(result.current.spacing).toBe('medium');
});

it('uses the size, shape and spacing props', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() =>
useSwatchPicker_unstable({ shape: 'circular', size: 'large', spacing: 'small' }, ref),
);

expect(result.current.size).toBe('large');
expect(result.current.shape).toBe('circular');
expect(result.current.spacing).toBe('small');
});

it('uses the radiogroup role by default', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPicker_unstable({}, ref));

expect(result.current.isGrid).toBe(false);
expect(result.current.root.role).toBe('radiogroup');
});

it('uses the grid role for the grid layout', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPicker_unstable({ layout: 'grid' }, ref));

expect(result.current.isGrid).toBe(true);
expect(result.current.root.role).toBe('grid');
});

it('applies arrow navigation attributes by default', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPicker_unstable({}, ref));

expect(result.current.root).toHaveProperty('data-tabster', expect.any(String));
});

it('does not apply arrow navigation attributes when focusMode is tab', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPicker_unstable({ focusMode: 'tab' }, ref));

expect(result.current.root).not.toHaveProperty('data-tabster');
});

it('uses the default selected value', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPicker_unstable({ defaultSelectedValue: 'red' }, ref));

expect(result.current.selectedValue).toBe('red');
});

it('forwards requested selection changes', () => {
const onSelectionChange = jest.fn();
const event = {} as React.MouseEvent<HTMLButtonElement>;
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPicker_unstable({ onSelectionChange }, ref));

act(() => result.current.requestSelectionChange(event, { selectedValue: 'red', selectedSwatch: '#ff0000' }));

expect(result.current.selectedValue).toBe('red');
expect(onSelectionChange).toHaveBeenCalledTimes(1);
expect(onSelectionChange).toHaveBeenCalledWith(event, {
type: 'click',
event,
selectedValue: 'red',
selectedSwatch: '#ff0000',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { SwatchPickerProvider, swatchPickerContextDefaultValue } from '../../contexts/swatchPicker';
import { useSwatchPickerRow_unstable } from './useSwatchPickerRow';

const wrapper = ({ children }: { children: React.ReactNode }) => (
<SwatchPickerProvider value={{ ...swatchPickerContextDefaultValue, spacing: 'small' }}>
{children}
</SwatchPickerProvider>
);

describe('useSwatchPickerRow', () => {
it('uses the row role', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPickerRow_unstable({}, ref));

expect(result.current.root.role).toBe('row');
});

it('uses the default spacing', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPickerRow_unstable({}, ref));

expect(result.current.spacing).toBe('medium');
});

it('uses the spacing from context', () => {
const ref = React.createRef<HTMLDivElement>();
const { result } = renderHook(() => useSwatchPickerRow_unstable({}, ref), { wrapper });

expect(result.current.spacing).toBe('small');
});
});
Loading