From 77cd891c9df579c34612aab1e187dd5c95e7f25b Mon Sep 17 00:00:00 2001 From: dougfabris Date: Wed, 17 Jul 2024 10:08:03 -0300 Subject: [PATCH] chore: snapshot tests --- .../src/components/Table/Table.spec.tsx | 84 +- .../Table/__snapshots__/Table.spec.tsx.snap | 773 ++++++++++++++++++ 2 files changed, 796 insertions(+), 61 deletions(-) create mode 100644 packages/fuselage/src/components/Table/__snapshots__/Table.spec.tsx.snap diff --git a/packages/fuselage/src/components/Table/Table.spec.tsx b/packages/fuselage/src/components/Table/Table.spec.tsx index 873dc800f0..af45f2185a 100644 --- a/packages/fuselage/src/components/Table/Table.spec.tsx +++ b/packages/fuselage/src/components/Table/Table.spec.tsx @@ -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(); - }); - - it('renders TableRow without crashing', () => { - render(, { - wrapper: ({ children }) => ( -
- {children} -
- ), - }); - }); - - it('renders TableHead without crashing', () => { - render(, { - wrapper: ({ children }) => {children}
, - }); - }); - - it('renders TableBody without crashing', () => { - render(, { - wrapper: ({ children }) => {children}
, - }); - }); - - it('renders TableFoot without crashing', () => { - render(, { - wrapper: ({ children }) => {children}
, - }); - }); - - it('renders TableCell without crashing', () => { - render(, { - wrapper: ({ children }) => ( - - - {children} - -
- ), - }); - }); - - it('should have no a11y violations on Default story', async () => { - const { container: defaultContainer } = render(); - - const defaultResults = await axe(defaultContainer); - expect(defaultResults).toHaveNoViolations(); - }); - - it('should have no a11y violations on Selected story', async () => { - const { container: selectedContainer } = render(); - - 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(); + expect(tree.baseElement).toMatchSnapshot(); + } + ); + + test.each(testCases)( + '%s should have no a11y violations', + async (_storyname, Story) => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); + } + ); }); diff --git a/packages/fuselage/src/components/Table/__snapshots__/Table.spec.tsx.snap b/packages/fuselage/src/components/Table/__snapshots__/Table.spec.tsx.snap new file mode 100644 index 0000000000..4f24bc97a1 --- /dev/null +++ b/packages/fuselage/src/components/Table/__snapshots__/Table.spec.tsx.snap @@ -0,0 +1,773 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[Table Rendering] renders Default without crashing 1`] = ` + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Dessert (100g serving) + + Calories + + Fat (g) + + Carbs (g) + + Protein (g) +
+ Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ Ice cream sandwich + + 237 + + 9 + + 37 + + 4.3 +
+
+
+ +`; + +exports[`[Table Rendering] renders Fixed without crashing 1`] = ` + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Dessert (100g serving) + + Calories + + Fat (g) + + Carbs (g) + + Protein (g) +
+ Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ Ice cream sandwich + + 237 + + 9 + + 37 + + 4.3 +
+
+
+ +`; + +exports[`[Table Rendering] renders Striped without crashing 1`] = ` + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Dessert (100g serving) + + Calories + + Fat (g) + + Carbs (g) + + Protein (g) +
+ Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ Ice cream sandwich + + 237 + + 9 + + 37 + + 4.3 +
+
+
+ +`; + +exports[`[Table Rendering] renders WithSelection without crashing 1`] = ` + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Dessert (100g serving) + + Calories + + Fat (g) + + Carbs (g) + + Protein (g) +
+ + Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ + Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ + Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ + Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+ + Frozen yoghurt + + 159 + + 6 + + 24 + + 4 +
+
+
+
+ 5 Items selected +
+
+
+ + +
+
+
+
+ +`;