-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Table): columns change throws (#1219)
- Loading branch information
Showing
6 changed files
with
82 additions
and
7 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
52 changes: 52 additions & 0 deletions
52
src/components/Table/hoc/withTableSettings/__tests__/withTableSettings.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,52 @@ | ||
import React from 'react'; | ||
|
||
import {render, screen} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import {Table, TableColumnConfig} from '../../../Table'; | ||
import {TableSettingsData, withTableSettings} from '../withTableSettings'; | ||
|
||
const item = {name: 'John Doe', occupation: 'Worker'}; | ||
|
||
const TableWithSettings = withTableSettings<typeof item>(Table); | ||
|
||
const columns: TableColumnConfig<typeof item>[] = [ | ||
{ | ||
id: 'name', | ||
}, | ||
{ | ||
id: 'occupation', | ||
}, | ||
]; | ||
|
||
const data = [item]; | ||
|
||
const settings: TableSettingsData = columns.map((column) => ({id: column.id, isSelected: true})); | ||
|
||
test('should change table columns', async () => { | ||
const updateSettings = jest.fn(); | ||
|
||
render( | ||
<TableWithSettings | ||
columns={columns} | ||
data={data} | ||
settings={settings} | ||
updateSettings={updateSettings} | ||
/>, | ||
); | ||
|
||
await userEvent.click(screen.getByRole('button', {name: 'Table settings'})); | ||
await userEvent.click(await screen.findByRole('button', {name: 'occupation'})); | ||
await userEvent.click(screen.getByRole('button', {name: 'Apply'})); | ||
|
||
expect(updateSettings).toHaveBeenCalledWith([ | ||
{ | ||
id: 'name', | ||
isSelected: true, | ||
}, | ||
{ | ||
id: 'occupation', | ||
isSelected: false, | ||
}, | ||
]); | ||
}); |
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,3 @@ | ||
{ | ||
"label_settings": "Table settings" | ||
} |
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,8 @@ | ||
import {addComponentKeysets} from '../../../../utils/addComponentKeysets'; | ||
|
||
import en from './en.json'; | ||
import ru from './ru.json'; | ||
|
||
const COMPONENT = 'withTableSettings'; | ||
|
||
export default addComponentKeysets({en, ru}, COMPONENT); |
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,3 @@ | ||
{ | ||
"label_settings": "Настройки таблицы" | ||
} |
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