import { act, render, screen } from '@testing-library/react';
import ColorSchemeProvider, { useColorScheme } from './ColorSchemeProvider';
import DesignTokensProvider from './DesignTokensProvider';
import ExperimentProvider from './ExperimentProvider';
function ThemeAwareComponent() {
const theme = useColorScheme();
return
{theme.colorSchemeName}
;
}
describe('ColorSchemeProvider', () => {
it('renders child content in a div with id', () => {
const { container } = render(
Child 1
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('div')).toMatchInlineSnapshot(`
Child 1
`);
});
it('renders styling for light mode when no color scheme specified', () => {
const { container } = render(
Content
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('renders styling for light mode when specified', () => {
const { container } = render(
Content
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('renders styling for dark mode when specified', () => {
const { container } = render(
Content
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('renders styling with media query when userPreference', () => {
const { container } = render(
Content
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('renders styling with a custom class if has an id', () => {
const { container } = render(
Content
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('.__gestaltThemetestId')).toBeTruthy();
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
});
describe('useColorScheme', () => {
it('uses light mode theme when not in theme provider', () => {
render();
expect(screen.getByText('lightMode')).toBeTruthy();
});
it('uses light mode theme when specified', () => {
render(
,
);
expect(screen.getByText('lightMode')).toBeTruthy();
});
it('uses dark mode theme when specified', () => {
render(
,
);
expect(screen.getByText('darkMode')).toBeTruthy();
});
it('uses theme based on matchMedia when userPreference', () => {
let listener = jest.fn<
[
{
matches: boolean;
},
],
any
>();
// @ts-expect-error - TS2740 - Type '{ addListener: (cb: any) => void; removeListener: Mock; }' is missing the following properties from type 'MediaQueryList': matches, media, onchange, addEventListener, and 2 more.
window.matchMedia = () => ({
addListener: (cb: any) => {
listener = cb;
},
removeListener: jest.fn(),
});
render(
,
);
expect(screen.getByText('lightMode')).toBeTruthy();
// @ts-expect-error - TS2769 - No overload matches this call.
act(() => listener({ matches: true }));
expect(screen.getByText('darkMode')).toBeTruthy();
});
});
describe('visual refresh tokens', () => {
it('uses visual refresh light mode theme when specified', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses visual refresh dark mode theme when specified', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses visual refresh with tall line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses visual refresh with ck line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses visual refresh with ja line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses visual refresh with th line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses visual refresh with vi line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
});
describe('calico 01 tokens', () => {
it('uses calico 01 light mode theme when specified', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses calico 01 dark mode theme when specified', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses calico 01 with tall line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses calico 01 with ck line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses calico 01 with ja line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses calico 01 with th line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
it('uses calico 01 with vi line height', () => {
const { container } = render(
,
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('style')).toMatchSnapshot();
});
});