Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
qianchuan.hw committed Jun 12, 2018
1 parent 281a889 commit b82c5c1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function getData(validate) {
};
}

function changeTreeExpandState({ tableData, rowData }, cb = null) {
function changeTreeExpandState({ tableData, rowData }, cb = () => {}) {
const expandedKeys = deepcopy(this.state.expandedKeys);
util.toggleItemInArr(rowData.jsxid, expandedKeys);
if (tableData) {
Expand All @@ -249,17 +249,13 @@ function changeTreeExpandState({ tableData, rowData }, cb = null) {
expandedKeys,
data: tableData,
}, () => {
if (cb) {
cb();
}
cb();
});
} else {
this.setState({
expandedKeys,
}, () => {
if (cb) {
cb();
}
cb();
});
}
}
Expand Down
55 changes: 55 additions & 0 deletions tests/tree.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Adapter from 'enzyme-adapter-react-15';
// import sinon from 'sinon';

import Table from '../src';
import { promise } from 'when';

Enzyme.configure({ adapter: new Adapter() });

Expand Down Expand Up @@ -111,13 +112,47 @@ const common = {
],
},
],
}, {
check: false,
id: '2',
grade: 'grade2',
email: 'email',
firstName: 'firstName1',
lastName: 'lastName1',
birthDate: 'birthDate1',
country: '086156529655931.121(xsxs)',
city: '87181',
data: [],
},
],
currentPage: 1,
totalCount: 30,
},
};

const addedContent = {
data: [
{
id: '3',
grade: 'grade2',
email: 'email',
firstName: 'firstName1',
lastName: 'lastName1',
birthDate: 'birthDate1',
country: '086156529655931.121(xsxs)',
city: '9527',
},
],
};

function loadTreeDataWithSync() {
return addedContent;
}

function loadTreeDataWithAsync() {
return Promise.resolve(addedContent);
}

describe('Tree', () => {
let wrapper;
it('props renderModel', () => {
Expand Down Expand Up @@ -160,5 +195,25 @@ describe('Tree', () => {
wrapper.find('.kuma-uxtable-row .kuma-uxtable-expand-icon').at(0).simulate('change');
expect(wrapper.find('.kuma-uxtable-row .kuma-uxtable-tree-row').length).not.to.be(0);
});

it('should asynchronous add remote row to toggle tree ', () => {
wrapper = mount(
<Table {...common} loadTreeData={loadTreeDataWithAsync} renderModel="tree" levels={0} />
);
const rowLength = wrapper.find('.kuma-uxtable-row').length;
wrapper.find('.kuma-icon .kuma-icon-triangle-right').at(4).simulate('click');
setTimeout(() => {
expect(wrapper.find('.kuma-uxtable-row').length).to.be(rowLength + 1);
});
});

it('should synchronous add remote row to toggle tree', () => {
wrapper = mount(
<Table {...common} loadTreeData={loadTreeDataWithSync} renderModel="tree" levels={0} />
);
const rowLength = wrapper.find('.kuma-uxtable-row').length;
wrapper.find('.kuma-icon .kuma-icon-triangle-right').at(4).simulate('click');
expect(wrapper.find('.kuma-uxtable-row').length).to.be(rowLength + 1);
});
});

0 comments on commit b82c5c1

Please sign in to comment.