import * as React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { Box } from '../../Box';
import { Disclosure } from '../index';
import render from '../../utils/_tests/render';
describe('props', () => {
it('should render correctly', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return Toggle;
}
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should assign a ref', () => {
const ref = React.createRef();
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return (
Toggle
);
}
render();
expect(ref.current).toMatchSnapshot();
});
it('should render correctly when disabled is set', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return (
Toggle
);
}
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly when focusable is set', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return (
Toggle
);
}
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
describe('composition', () => {
describe('as', () => {
it('should render correctly', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return (
Toggle
);
}
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
describe('hook', () => {
it('should return with Disclosure props', () => {
const { result } = renderHook(() => {
const hidden = Disclosure.useState({ baseId: 'test' });
return Disclosure.useProps(hidden);
});
expect(result.current).toMatchSnapshot();
});
});
describe('render props', () => {
it('should render correctly', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return (
{(DisclosureDisclosureProps) => Hello world
}
);
}
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
});
describe('overrides', () => {
it('Disclosure.base should render correctly', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return (
Toggle
);
}
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
describe('theming', () => {
it('Disclosure.base should render correctly', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return Toggle;
}
const { container } = render(, {
theme: { Disclosure: { styles: { base: { backgroundColor: 'red' } } } },
});
expect(container.firstChild).toMatchSnapshot();
});
});
describe('defaultProps', () => {
it('should render correctly for className', () => {
function Component() {
const hidden = Disclosure.useState({ baseId: 'test' });
return Toggle;
}
const { container } = render(, {
theme: { Disclosure: { defaultProps: { className: 'red' } } },
});
expect(container.firstChild).toMatchSnapshot();
});
});
describe('useContext', () => {
it('should render correctly', () => {
let disclosure;
function ParentComponent({ children }: any) {
return {children};
}
function ChildComponent() {
const context = Disclosure.useContext();
disclosure = context.disclosure;
return hello world;
}
render(
);
expect(disclosure).toMatchSnapshot();
});
});