import React from 'react';
import { render } from '@testing-library/react';
import 'jest-styled-components';
import { Grommet } from '../../Grommet';
import { Heading } from '..';
test('Heading renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Heading accepts ref', () => {
const ref = React.createRef();
const { container } = render(
,
);
expect(ref.current).not.toBeNull();
expect(container.firstChild).toMatchSnapshot();
});
test('Heading level renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Heading size renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Heading textAlign renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Heading margin renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Heading color renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
const LONG = 'a b c d e f g h i j k l m n o p q r s t u v w x y z';
test('Heading truncate renders', () => {
const { container } = render(
{LONG}
{LONG}
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('responsive renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('weight renders', () => {
const { asFragment } = render(
My heading
My heading
My heading
My heading
,
);
expect(asFragment()).toMatchSnapshot();
});
test('Theme based font family renders', () => {
const customTheme = {
heading: {
font: {
family: 'Fira Sans',
},
level: {
1: {
font: {
family: 'Arial',
},
},
2: {
font: {
family: 'Roboto',
},
},
3: {
font: {
family: 'Ubuntu',
},
},
},
},
};
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Theme based font weight renders', () => {
const customTheme = {
heading: {
weight: 600,
level: {
1: {
font: {
weight: '700',
},
},
2: {
font: {
weight: '400',
},
},
3: {
font: {
weight: '200',
},
},
},
},
};
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Theme color renders', () => {
const customTheme = {
heading: {
color: 'text-strong',
},
};
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('Throws a warning when heading.level is undefined in the theme.', () => {
global.console.warn = jest.fn();
const customTheme = {
heading: {
level: {
6: undefined,
},
},
};
render(
,
);
const consoleMsg = 'Heading level 6 is not defined in your theme.';
expect(global.console.warn).toHaveBeenCalledWith(consoleMsg);
});
test('Heading fill renders', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});