import { test, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import Table from './Table';
test('table renders correctly', () => {
render(
Public holidays in 2020
| Date |
Day |
Holiday |
| 10 April |
Friday |
Good Friday |
);
const table = screen.getByRole('table');
expect(table).toHaveClass('ds_table');
expect(table.nodeName).toEqual('TABLE');
});
test('table with smallscreen behaviour', () => {
const SMALL_SCREEN_BEHAVIOUR = 'scrolling';
render(
Public holidays in 2020
| Date |
Day |
Holiday |
| 10 April |
Friday |
Good Friday |
);
const table = screen.getByRole('table');
expect(table).toHaveAttribute('data-smallscreen', SMALL_SCREEN_BEHAVIOUR);
expect(table.nodeName).toEqual('TABLE');
});
test('instantiating/initialising DS component script: smallscreen', () => {
render(
Public holidays in 2020
| Date |
Day |
Holiday |
| 10 April |
Friday |
Good Friday |
);
const table = screen.getByRole('table');
expect(table).toHaveClass('js-initialised');
expect(table).toHaveClass('js-instantiated');
});
test('instantiating/initialising DS component script: not smallscreen', () => {
render(
);
const table = screen.getByRole('table');
expect(table).not.toHaveClass('js-initialised');
expect(table).not.toHaveClass('js-instantiated');
});
test('passing additional props', () => {
render(
);
const table = screen.getByRole('table');
expect(table?.dataset.test).toEqual('foo');
});
test('table with additional CSS class', () => {
render(
);
const table = screen.getByRole('table');
expect(table).toHaveClass('foo', 'ds_table');
});