Skip to content

Commit

Permalink
chore: snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Jul 17, 2024
1 parent b58f458 commit 77cd891
Show file tree
Hide file tree
Showing 2 changed files with 796 additions and 61 deletions.
84 changes: 23 additions & 61 deletions packages/fuselage/src/components/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,29 @@ import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import { Table, TableRow, TableHead, TableBody, TableCell, TableFoot } from '.';
import * as stories from './Table.stories';

const { Default, Selected } = composeStories(stories);

describe('[Table Component]', () => {
it('renders Table without crashing', () => {
render(<Table />);
});

it('renders TableRow without crashing', () => {
render(<TableRow />, {
wrapper: ({ children }) => (
<table>
<tbody>{children}</tbody>
</table>
),
});
});

it('renders TableHead without crashing', () => {
render(<TableHead />, {
wrapper: ({ children }) => <table>{children}</table>,
});
});

it('renders TableBody without crashing', () => {
render(<TableBody />, {
wrapper: ({ children }) => <table>{children}</table>,
});
});

it('renders TableFoot without crashing', () => {
render(<TableFoot />, {
wrapper: ({ children }) => <table>{children}</table>,
});
});

it('renders TableCell without crashing', () => {
render(<TableCell />, {
wrapper: ({ children }) => (
<table>
<tbody>
<tr>{children}</tr>
</tbody>
</table>
),
});
});

it('should have no a11y violations on Default story', async () => {
const { container: defaultContainer } = render(<Default />);

const defaultResults = await axe(defaultContainer);
expect(defaultResults).toHaveNoViolations();
});

it('should have no a11y violations on Selected story', async () => {
const { container: selectedContainer } = render(<Selected />);

const selectedResults = await axe(selectedContainer);
expect(selectedResults).toHaveNoViolations();
});
const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
]);

describe('[Table Rendering]', () => {
test.each(testCases)(
`renders %s without crashing`,
async (_storyname, Story) => {
const tree = render(<Story />);
expect(tree.baseElement).toMatchSnapshot();
}
);

test.each(testCases)(
'%s should have no a11y violations',
async (_storyname, Story) => {
const { container } = render(<Story />);

const results = await axe(container);
expect(results).toHaveNoViolations();
}
);
});
Loading

0 comments on commit 77cd891

Please sign in to comment.