-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(Table): added unit tests to Table components (#1294)
Co-authored-by: Kirill Kharitonov <[email protected]>
- Loading branch information
Showing
3 changed files
with
488 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from 'react'; | ||
|
||
import {render} from '@testing-library/react'; | ||
|
||
import {Table, type TableProps} from '../Table'; | ||
import { | ||
type WithTableActionsProps, | ||
type WithTableSelectionProps, | ||
type WithTableSettingsProps, | ||
type WithTableSortingProps, | ||
withTableActions, | ||
withTableCopy, | ||
withTableSelection, | ||
withTableSettings, | ||
withTableSorting, | ||
} from '../hoc'; | ||
|
||
interface Model { | ||
disabled: boolean; | ||
} | ||
|
||
function getTextContent(html = '') { | ||
return html.replace(/uniq\d+/g, ''); | ||
} | ||
|
||
describe('Table HOCs tests', () => { | ||
it('using withTableActions and withTableSelection should not depend of order', () => { | ||
const Table1 = withTableActions(withTableSelection<Model>(Table)); | ||
const Table2 = withTableSelection(withTableActions<Model>(Table)); | ||
|
||
type Props = TableProps<Model> & | ||
WithTableActionsProps<Model> & | ||
WithTableSelectionProps<Model>; | ||
const props: Props = { | ||
data: [{disabled: false}, {disabled: true}], | ||
columns: [{id: 'name'}], | ||
isRowDisabled: ({disabled}) => disabled, | ||
selectedIds: [], | ||
onSelectionChange: () => {}, | ||
getRowActions: () => [], | ||
}; | ||
const {container: container1} = render(React.createElement<Props>(Table1, props)); | ||
const {container: container2} = render(React.createElement<Props>(Table2, props)); | ||
|
||
expect(getTextContent(container1.outerHTML)).toEqual(getTextContent(container2.outerHTML)); | ||
}); | ||
|
||
it('using withTableActions and withTableSorting should not depend of order', () => { | ||
const Table1 = withTableActions(withTableSorting<Model>(Table)); | ||
const Table2 = withTableSorting(withTableActions<Model>(Table)); | ||
|
||
type Props = TableProps<Model> & WithTableActionsProps<Model> & WithTableSortingProps; | ||
const props: Props = { | ||
data: [{disabled: false}, {disabled: true}], | ||
columns: [{id: 'name'}], | ||
isRowDisabled: ({disabled}) => disabled, | ||
getRowActions: () => [], | ||
}; | ||
const {container: container1} = render(React.createElement<Props>(Table1, props)); | ||
const {container: container2} = render(React.createElement<Props>(Table2, props)); | ||
|
||
expect(getTextContent(container1.outerHTML)).toEqual(getTextContent(container2.outerHTML)); | ||
}); | ||
|
||
it('using all HOCs should not depend of order', () => { | ||
const Table1 = withTableSorting( | ||
withTableSettings( | ||
withTableCopy(withTableActions(withTableSelection<Model, {}>(Table))), | ||
), | ||
); | ||
const Table2 = withTableSelection( | ||
withTableActions(withTableCopy(withTableSettings(withTableSorting<Model, {}>(Table)))), | ||
); | ||
|
||
type Props = TableProps<Model> & | ||
WithTableActionsProps<Model> & | ||
WithTableSelectionProps<Model> & | ||
WithTableSettingsProps & | ||
WithTableSortingProps; | ||
|
||
const props: Props = { | ||
data: [{disabled: false}, {disabled: true}], | ||
columns: [{id: 'name'}], | ||
isRowDisabled: ({disabled}) => disabled, | ||
selectedIds: [], | ||
onSelectionChange: () => {}, | ||
getRowActions: () => [], | ||
updateSettings: () => Promise.resolve(), | ||
settings: [], | ||
}; | ||
const {container: container1} = render(React.createElement<Props>(Table1, props)); | ||
const {container: container2} = render(React.createElement<Props>(Table2, props)); | ||
|
||
expect(getTextContent(container1.outerHTML)).toEqual(getTextContent(container2.outerHTML)); | ||
}); | ||
}); |
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
Oops, something went wrong.