Skip to content

Commit

Permalink
[feat] add test case and docs for addSubRow & addSubRowFromTop
Browse files Browse the repository at this point in the history
  • Loading branch information
qili.taoqili committed Mar 11, 2019
1 parent ccfe7f0 commit 2869d54
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ $ npm start
* addEmptyRowFromTop(): 从顶部添加一个空的新行。
* addRow(rowData): 以指定数据添加一个新行。
* addRowFromTop(rowData): 以指定数据从顶部添加一个新行。
* addSubRow(rowData, jsxid, cb): 树形表格模式下从底部插入一个子树节点行
* addSubRomFromTop(rowData, jsxid, cb): 树形表格模式下从顶部插入一个子树节点行
* delRow(rowData): 删除一个新行。
* editRow(rowData): 使指定的行切换到编辑模式。
* editAllRow(): 使所有行切换到编辑模式。
Expand Down
4 changes: 4 additions & 0 deletions doc/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ let columns = [

## API

* addSubRow(rowData, jsxid, cb): add an sub row with specified data in tree table from bottom
* addSubRowFromTop(rowData, jsxid, cb): add an sub row with specified data in tree table from top


### Row Editing

* getData(): return cellData & do Validation
Expand Down
72 changes: 72 additions & 0 deletions tests/tree.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,76 @@ describe('Tree', () => {
wrapper.find('.kuma-icon.kuma-icon-triangle-right').at(4).simulate('click');
expect(wrapper.find('.kuma-uxtable-row').length).to.be(rowLength + 1);
});

it('api addSubRow & addSubRowFromTop', (done) => {
wrapper = mount(
<Table
{...common}
loadTreeData={loadTreeDataWithSync}
renderModel="tree"
levels={0}
/>
);
const table = wrapper.instance()
expect(table.state.expandedKeys).to.have.length(0)
table.addSubRow({
id: '9999',
radio: true,
grade: '2grade2',
email: '2email2',
firstName: '2firstName2',
lastName: '2lastName2',
birthDate: '2birthDate2',
country: '2country2',
city: '2city2'
}, 0, () => {
const data = table.getData().data.data;
expect(data[0].data).to.have.length(4);
expect(data[0].data[3].id).to.be('9999');
expect(data[0].data[3].__treeId__).to.be('0-3');
expect(table.state.expandedKeys.includes(0))
done();
});
table.addSubRowFromTop({
id: '0000',
radio: true,
grade: '2grade2',
email: '2email2',
firstName: '2firstName2',
lastName: '2lastName2',
birthDate: '2birthDate2',
country: '2country2',
city: '2city2'
}, 0, () => {
const data = table.getData().data.data;
expect(data[0].data).to.have.length(5);
expect(data[0].data[4].id).to.be('0000');
expect(data[0].data[4].__treeId__).to.be('0-0');
done();
});

// not tree table
let wrapper = mount(
<Table
{...common}
loadTreeData={loadTreeDataWithSync}
levels={0}
/>
);
wrapper.instance().addSubRow({
id: '9999',
radio: true,
grade: '2grade2',
email: '2email2',
firstName: '2firstName2',
lastName: '2lastName2',
birthDate: '2birthDate2',
country: '2country2',
city: '2city2'
}, 0, () => {
const data = wrapper.instance().getData().data.data;
expect(data[0].data).to.have.length(3);
done();
});
});
});

0 comments on commit 2869d54

Please sign in to comment.