Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Td): fix children and add tests #1703

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dnb-eufemia/src/components/table/TableTd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Td = (
className={classnames('dnb-table__td', className)}
{...props}
>
{children}
</td>
)
}
Expand Down
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',
])
})
})