-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b10bb17
commit de6aa00
Showing
2 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
packages/braid-design-system/src/lib/components/Table/Table.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import '@testing-library/jest-dom'; | ||
import 'html-validate/jest'; | ||
import React from 'react'; | ||
import { renderToStaticMarkup } from 'react-dom/server'; | ||
import { BraidTestProvider } from '../../../entries/test'; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableFooter, | ||
TableHeadCell, | ||
TableHeader, | ||
TableRow, | ||
Text, | ||
} from '..'; | ||
import { render } from '@testing-library/react'; | ||
|
||
describe('Table', () => { | ||
it('should have accessible label', () => { | ||
const { getByLabelText } = render( | ||
<BraidTestProvider> | ||
<Table label="Table label"> | ||
<TableBody> | ||
<TableRow> | ||
<TableCell> | ||
<Text>Content</Text> | ||
</TableCell> | ||
</TableRow> | ||
</TableBody> | ||
</Table> | ||
</BraidTestProvider>, | ||
); | ||
const tableEl = getByLabelText('Table label'); | ||
expect(tableEl.tagName).toBe('TABLE'); | ||
}); | ||
|
||
describe('should render valid html structure', () => { | ||
it('with all sections', () => { | ||
expect( | ||
renderToStaticMarkup( | ||
<BraidTestProvider> | ||
<Table label="Table label"> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHeadCell> | ||
<Text>Content</Text> | ||
</TableHeadCell> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
<TableRow> | ||
<TableCell> | ||
<Text>Content</Text> | ||
</TableCell> | ||
</TableRow> | ||
</TableBody> | ||
<TableFooter> | ||
<TableRow> | ||
<TableCell> | ||
<Text>Content</Text> | ||
</TableCell> | ||
</TableRow> | ||
</TableFooter> | ||
</Table> | ||
</BraidTestProvider>, | ||
), | ||
).toHTMLValidate({ | ||
extends: ['html-validate:recommended'], | ||
}); | ||
}); | ||
|
||
it('with body only', () => { | ||
expect( | ||
renderToStaticMarkup( | ||
<BraidTestProvider> | ||
<Table label="Table label"> | ||
<TableBody> | ||
<TableRow> | ||
<TableCell> | ||
<Text>Content</Text> | ||
</TableCell> | ||
</TableRow> | ||
</TableBody> | ||
</Table> | ||
</BraidTestProvider>, | ||
), | ||
).toHTMLValidate({ | ||
extends: ['html-validate:recommended'], | ||
}); | ||
}); | ||
|
||
it('with row headers and no column headers', () => { | ||
expect( | ||
renderToStaticMarkup( | ||
<BraidTestProvider> | ||
<Table label="Table label"> | ||
<TableBody> | ||
<TableRow> | ||
<TableHeadCell> | ||
<Text>Content</Text> | ||
</TableHeadCell> | ||
<TableCell> | ||
<Text>Content</Text> | ||
</TableCell> | ||
</TableRow> | ||
</TableBody> | ||
</Table> | ||
</BraidTestProvider>, | ||
), | ||
).toHTMLValidate({ | ||
extends: ['html-validate:recommended'], | ||
}); | ||
}); | ||
|
||
it('with column and row headers', () => { | ||
expect( | ||
renderToStaticMarkup( | ||
<BraidTestProvider> | ||
<Table label="Table label"> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHeadCell> | ||
<Text>Content</Text> | ||
</TableHeadCell> | ||
<TableHeadCell> | ||
<Text>Content</Text> | ||
</TableHeadCell> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
<TableRow> | ||
<TableHeadCell> | ||
<Text>Content</Text> | ||
</TableHeadCell> | ||
<TableCell> | ||
<Text>Content</Text> | ||
</TableCell> | ||
</TableRow> | ||
</TableBody> | ||
</Table> | ||
</BraidTestProvider>, | ||
), | ||
).toHTMLValidate({ | ||
extends: ['html-validate:recommended'], | ||
}); | ||
}); | ||
}); | ||
}); |
5 changes: 4 additions & 1 deletion
5
packages/braid-design-system/src/lib/hooks/useIsomorphicLayoutEffect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { useEffect, useLayoutEffect } from 'react'; | ||
|
||
const isJSDom = | ||
typeof navigator !== 'undefined' && navigator?.userAgent?.includes('jsdom'); | ||
|
||
// `useLayoutEffect` will show a warning if used during SSR | ||
export const useIsomorphicLayoutEffect = | ||
typeof document !== 'undefined' ? useLayoutEffect : useEffect; | ||
typeof document !== 'undefined' && !isJSDom ? useLayoutEffect : useEffect; |