import * as React from 'react';
import { Card } from '../Card';
import { render, screen } from '@testing-library/react';
import { ComponentClassNames } from '../../shared';
const testId = 'cardId';
describe('Card component', () => {
it('should render card variations', async () => {
render(
outlined
elevated
);
const outlined = await screen.findByTestId('outlined');
const elevated = await screen.findByTestId('elevated');
expect(outlined.classList).toContain(
`${ComponentClassNames['Card']}--outlined`
);
expect(elevated.classList).toContain(
`${ComponentClassNames['Card']}--elevated`
);
});
it('can render custom classnames', async () => {
render();
const card = await screen.findByTestId(testId);
expect(card.className).toContain('custom-classname');
expect(card.className).toContain(ComponentClassNames.Card);
});
it('should forward ref to DOM element', async () => {
const ref = React.createRef();
const cardContent = 'Hello there';
render(
{cardContent}
);
await screen.findByTestId(testId);
expect(ref.current?.nodeName).toBe('DIV');
expect(ref.current?.innerHTML).toBe(cardContent);
});
it('can render any arbitrary data-* attribute', async () => {
render();
const card = await screen.findByTestId(testId);
expect(card.dataset['demo']).toBe('true');
});
it('can render tag', async () => {
render();
const card = await screen.findByTestId(testId);
expect(card.nodeName).toBe('SECTION');
});
});