mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-28 13:10:03 +00:00
patch tests for search
This commit is contained in:
@@ -134,7 +134,6 @@ class Container extends React.Component {
|
||||
}
|
||||
|
||||
handleTableChange = (type, { searchText }) => {
|
||||
console.log('table change');
|
||||
setTimeout(() => {
|
||||
const result = products.filter((row) => {
|
||||
for (let cidx = 0; cidx < columns.length; cidx += 1) {
|
||||
|
||||
@@ -44,7 +44,7 @@ export default ExtendBase =>
|
||||
|
||||
isRemoteSearch = () => {
|
||||
const { remote } = this.props;
|
||||
return remote === true || (_.isObject(remote) && remote.search);
|
||||
return remote === true || (_.isObject(remote) && remote.search) || this.isRemotePagination();
|
||||
}
|
||||
|
||||
isRemotePagination = () => {
|
||||
|
||||
@@ -134,6 +134,38 @@ describe('Context', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('if search is enable', () => {
|
||||
beforeEach(() => {
|
||||
const SearchContext = React.createContext();
|
||||
const search = {
|
||||
createContext: jest.fn().mockReturnValue({
|
||||
Provider: SearchContext.Provider,
|
||||
Consumer: SearchContext.Consumer
|
||||
}),
|
||||
searchText: ''
|
||||
};
|
||||
wrapper = shallow(
|
||||
<BootstrapTable
|
||||
keyField={ keyField }
|
||||
data={ data }
|
||||
columns={ columns }
|
||||
search={ search }
|
||||
/>
|
||||
);
|
||||
wrapper.render();
|
||||
});
|
||||
|
||||
it('should create contexts correctly', () => {
|
||||
expect(wrapper.instance().DataContext).toBeDefined();
|
||||
expect(wrapper.instance().SearchContext).toBeDefined();
|
||||
expect(wrapper.instance().SortContext).not.toBeDefined();
|
||||
expect(wrapper.instance().SelectionContext).not.toBeDefined();
|
||||
expect(wrapper.instance().CellEditContext).not.toBeDefined();
|
||||
expect(wrapper.instance().FilterContext).not.toBeDefined();
|
||||
expect(wrapper.instance().PaginationContext).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('if column filter is enable', () => {
|
||||
beforeEach(() => {
|
||||
const FilterContext = React.createContext();
|
||||
|
||||
@@ -186,6 +186,48 @@ describe('remoteResolver', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isRemoteSearch', () => {
|
||||
describe('when remote is false', () => {
|
||||
beforeEach(() => {
|
||||
shallowContainer();
|
||||
});
|
||||
|
||||
it('should return false', () => {
|
||||
expect(wrapper.instance().isRemoteSearch()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when remote is true', () => {
|
||||
beforeEach(() => {
|
||||
shallowContainer({ remote: true });
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
expect(wrapper.instance().isRemoteSearch()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when remote.search is true', () => {
|
||||
beforeEach(() => {
|
||||
shallowContainer({ remote: { search: true } });
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
expect(wrapper.instance().isRemoteSearch()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when this.isRemotePagination return true', () => {
|
||||
beforeEach(() => {
|
||||
shallowContainer({ remote: { pagination: true } });
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
expect(wrapper.instance().isRemoteSearch()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleRemoteCellChange', () => {
|
||||
const onTableChangeCB = sinon.stub();
|
||||
const rowId = 1;
|
||||
@@ -244,6 +286,26 @@ describe('remoteResolver', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleRemoteSearchChange', () => {
|
||||
const onTableChangeCB = sinon.stub();
|
||||
const searchText = 'abc';
|
||||
|
||||
beforeEach(() => {
|
||||
onTableChangeCB.reset();
|
||||
shallowContainer({
|
||||
onTableChange: onTableChangeCB
|
||||
});
|
||||
wrapper.instance().handleRemoteSearchChange(searchText);
|
||||
});
|
||||
|
||||
it('should calling props.onTableChange correctly', () => {
|
||||
expect(onTableChangeCB.calledOnce).toBeTruthy();
|
||||
expect(onTableChangeCB.calledWith('search', wrapper.instance().getNewestState({
|
||||
searchText
|
||||
}))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleRemoteFilterChange', () => {
|
||||
const onTableChangeCB = sinon.stub();
|
||||
const filters = { price: { filterVal: 20, filterType: 'TEXT' } };
|
||||
|
||||
Reference in New Issue
Block a user