Merge branch 'issue-363' of https://github.com/COzero/react-bootstrap-table2 into COzero-issue-363

This commit is contained in:
AllenFang 2018-08-20 23:23:32 +08:00
commit 2b6081ab31
7 changed files with 48 additions and 22 deletions

View File

@ -52,6 +52,7 @@
"css-loader": "0.28.1",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "1.1.1",
"enzyme-to-json": "^3.3.4",
"eslint": "4.5.0",
"eslint-config-airbnb": "15.1.0",
"eslint-loader": "1.9.0",

View File

@ -75,6 +75,7 @@ export default class SelectionCell extends Component {
checked={ selected }
disabled={ disabled }
className={ bootstrap4 ? 'selection-input-4' : '' }
onChange={ () => {} }
/>
)
}

View File

@ -12,6 +12,7 @@ export const CheckBox = ({ className, checked, indeterminate }) => (
ref={ (input) => {
if (input) input.indeterminate = indeterminate; // eslint-disable-line no-param-reassign
} }
onChange={ () => {} }
/>
);

View File

@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<SelectionCell /> render should render component correctly 1`] = `
<td
onClick={[Function]}
>
<input
checked={true}
className=""
onChange={[Function]}
type="checkbox"
/>
</td>
`;

View File

@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<CheckBox /> render should render component correctly 1`] = `
<input
checked={true}
onChange={[Function]}
type="checkbox"
/>
`;

View File

@ -1,6 +1,7 @@
import 'jsdom-global/register';
import React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import sinon from 'sinon';
import { shallowWithContext } from '../test-helpers/new-context';
@ -61,7 +62,8 @@ describe('<SelectionCell />', () => {
mode={ mode }
rowIndex={ rowIndex }
onRowSelect={ mockOnRowSelect }
/>, { bootstrap4: false }
/>,
{ bootstrap4: false }
);
wrapper.find('td').simulate('click');
});
@ -72,9 +74,7 @@ describe('<SelectionCell />', () => {
it('should calling onRowSelect callback correctly', () => {
expect(mockOnRowSelect.calledOnce).toBe(true);
expect(
mockOnRowSelect.calledWith(rowKey, !selected, rowIndex)
).toBe(true);
expect(mockOnRowSelect.calledWith(rowKey, !selected, rowIndex)).toBe(true);
});
});
@ -88,7 +88,8 @@ describe('<SelectionCell />', () => {
rowIndex={ rowIndex }
onRowSelect={ mockOnRowSelect }
disabled
/>, { bootstrap4: false }
/>,
{ bootstrap4: false }
);
wrapper.find('td').simulate('click');
});
@ -111,7 +112,8 @@ describe('<SelectionCell />', () => {
mode="radio"
rowIndex={ rowIndex }
onRowSelect={ mockOnRowSelect }
/>, { bootstrap4: false }
/>,
{ bootstrap4: false }
);
});
@ -132,11 +134,12 @@ describe('<SelectionCell />', () => {
rowIndex={ rowIndex }
selected
onRowSelect={ mockOnRowSelect }
/>, { bootstrap4: false }
/>,
{ bootstrap4: false }
);
});
it('should be called with correct paramters', () => {
it('should be called with correct parameters', () => {
// first click
wrapper.find('td').simulate('click');
expect(mockOnRowSelect.callCount).toBe(1);
@ -151,12 +154,8 @@ describe('<SelectionCell />', () => {
beforeEach(() => {
wrapper = shallowWithContext(
<SelectionCell
rowKey={ 1 }
mode={ mode }
rowIndex={ rowIndex }
selected={ selected }
/>, { bootstrap4: false }
<SelectionCell rowKey={ 1 } mode={ mode } rowIndex={ rowIndex } selected={ selected } />,
{ bootstrap4: false }
);
});
@ -165,6 +164,7 @@ describe('<SelectionCell />', () => {
expect(wrapper.find('input')).toHaveLength(1);
expect(wrapper.find('input').get(0).props.type).toBe(mode);
expect(wrapper.find('input').get(0).props.checked).toBe(selected);
expect(toJson(wrapper)).toMatchSnapshot();
});
describe('when disabled prop give as true', () => {
@ -176,7 +176,8 @@ describe('<SelectionCell />', () => {
rowIndex={ rowIndex }
selected={ selected }
disabled
/>, { bootstrap4: false }
/>,
{ bootstrap4: false }
);
});
@ -198,7 +199,8 @@ describe('<SelectionCell />', () => {
rowIndex={ rowIndex }
selected={ selected }
selectionRenderer={ selectionRenderer }
/>, { bootstrap4: false }
/>,
{ bootstrap4: false }
);
});
@ -219,12 +221,8 @@ describe('<SelectionCell />', () => {
describe('when bootstrap4 context is true', () => {
beforeEach(() => {
wrapper = shallowWithContext(
<SelectionCell
rowKey={ 1 }
mode={ mode }
rowIndex={ rowIndex }
selected={ selected }
/>, { bootstrap4: true }
<SelectionCell rowKey={ 1 } mode={ mode } rowIndex={ rowIndex } selected={ selected } />,
{ bootstrap4: true }
);
});

View File

@ -1,5 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import sinon from 'sinon';
import { shallowWithContext } from '../test-helpers/new-context';
@ -201,6 +202,7 @@ describe('<CheckBox />', () => {
expect(wrapper.find('input').length).toBe(1);
expect(wrapper.find('input').prop('checked')).toBe(checked);
expect(wrapper.find('input').prop('type')).toBe('checkbox');
expect(toJson(wrapper)).toMatchSnapshot();
});
});
});