-
Notifications
You must be signed in to change notification settings - Fork 33
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
fd825e7
commit 0912bc0
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ const Td = ( | |
className={classnames('dnb-table__td', className)} | ||
{...props} | ||
> | ||
{children} | ||
</td> | ||
) | ||
} | ||
|
74 changes: 74 additions & 0 deletions
74
packages/dnb-eufemia/src/components/table/__tests__/TableTd.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,74 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import TableTd from '../TableTd' | ||
|
||
describe('TableTd', () => { | ||
it('should contain children content', () => { | ||
render( | ||
<table> | ||
<tbody> | ||
<tr> | ||
<TableTd>td content</TableTd> | ||
</tr> | ||
</tbody> | ||
</table> | ||
) | ||
|
||
const element = document.querySelector('td') | ||
|
||
expect(element.textContent).toBe('td content') | ||
}) | ||
|
||
it('should include custom attributes', () => { | ||
render( | ||
<table> | ||
<tbody> | ||
<tr> | ||
<TableTd aria-label="custom-label">td content</TableTd> | ||
</tr> | ||
</tbody> | ||
</table> | ||
) | ||
|
||
const element = document.querySelector('td') | ||
const attributes = Array.from(element.attributes).map( | ||
(attr) => attr.name | ||
) | ||
|
||
expect(attributes).toEqual(['role', 'class', 'aria-label']) | ||
}) | ||
|
||
it('should have role with cell as value', () => { | ||
render( | ||
<table> | ||
<tbody> | ||
<tr> | ||
<TableTd>td content</TableTd> | ||
</tr> | ||
</tbody> | ||
</table> | ||
) | ||
|
||
const element = document.querySelector('td') | ||
|
||
expect(element.getAttribute('role')).toBe('cell') | ||
}) | ||
|
||
it('should include custom classes', () => { | ||
render( | ||
<table> | ||
<tbody> | ||
<tr> | ||
<TableTd className="custom-class">td content</TableTd> | ||
</tr> | ||
</tbody> | ||
</table> | ||
) | ||
|
||
const element = document.querySelector('td') | ||
expect(Array.from(element.classList)).toEqual([ | ||
'dnb-table__td', | ||
'custom-class', | ||
]) | ||
}) | ||
}) |