-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Table): fix record key when there is no key to use
when there is no key to use, instead key with index is wrong when have disabled record, fix this. close #67
- Loading branch information
1 parent
b2ccb7c
commit 3d795f9
Showing
3 changed files
with
85 additions
and
8 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
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
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,60 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import Table from 'src/components/Table'; | ||
|
||
jest.unmock('rc-trigger'); | ||
|
||
describe('Table', () => { | ||
test('select', () => { | ||
const error = (global.console.error = jest.fn()); | ||
const onRowSelect = jest.fn(); | ||
let onRowSelectTimes = 0; | ||
|
||
class Demo extends React.Component { | ||
render() { | ||
const dataSource = new Array(100).fill(null).map((v, i) => ({ | ||
index: `index-${i}`, | ||
i | ||
})); | ||
const columns = new Array(5).fill(null).map((v, i) => ({ | ||
title: `title-${i}`, | ||
key: `title-${i}`, | ||
width: 200, | ||
render: record => <span>content {record.index}</span> | ||
})); | ||
return ( | ||
<div> | ||
<div className="demo-wrap"> | ||
<Table | ||
rowSelection={{ | ||
defaultSelectedRowKeys: [1, 2, 4, 5], | ||
onChange: onRowSelect, | ||
getDisabledOfRow: record => record.i < 4 | ||
}} | ||
dataSource={dataSource} | ||
columns={columns} | ||
{...this.props} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const wrapper = mount(<Demo />); | ||
|
||
expect(error).toHaveBeenCalledTimes(1); | ||
|
||
expect(wrapper.find('.uc-fe-table-tbody i.icon__checkbox-ed').length).toBe(4); | ||
expect(wrapper.find('.uc-fe-table-tbody i[disabled=true]').length).toBe(4); | ||
expect(wrapper.find('.uc-fe-table-tbody i.icon__checkbox-ed[disabled=true]').length).toBe(2); | ||
|
||
wrapper.find('.uc-fe-table-thead i.icon__checkbox').simulate('click'); | ||
expect(wrapper.find('.uc-fe-table-tbody i.icon__checkbox-ed').length).toBe(8); | ||
expect(wrapper.find('.uc-fe-table-tbody i[disabled=true]').length).toBe(4); | ||
expect(wrapper.find('.uc-fe-table-tbody i.icon__checkbox-ed[disabled=true]').length).toBe(2); | ||
expect(onRowSelect).toHaveBeenCalledTimes(++onRowSelectTimes); | ||
expect(onRowSelect).toHaveBeenLastCalledWith(['1', '2', '4', '5', '6', '7', '8', '9']); | ||
}); | ||
}); |