mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-28 21:20:04 +00:00
Compare commits
7 Commits
react-boot
...
mock-props
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
788fcfc93d | ||
|
|
1e816c3f2b | ||
|
|
2a7ec721d7 | ||
|
|
b6698a5307 | ||
|
|
4e6b341828 | ||
|
|
8769f10d17 | ||
|
|
d8a6807f1b |
@@ -11,11 +11,12 @@
|
|||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"comma-dangle": ["error", "never"],
|
"comma-dangle": ["error", "never"],
|
||||||
"react/jsx-curly-spacing": 0,
|
|
||||||
"react/forbid-prop-types": 0,
|
"react/forbid-prop-types": 0,
|
||||||
|
"react/jsx-curly-spacing": 0,
|
||||||
"react/jsx-filename-extension": 0,
|
"react/jsx-filename-extension": 0,
|
||||||
"react/jsx-space-before-closing": 0,
|
"react/jsx-space-before-closing": 0,
|
||||||
"react/jsx-tag-spacing": ["error", { "beforeSelfClosing": "always" }],
|
"react/jsx-tag-spacing": ["error", { "beforeSelfClosing": "always" }],
|
||||||
|
"react/require-default-props": 0,
|
||||||
"import/extensions": 0, // skip import extensions
|
"import/extensions": 0, // skip import extensions
|
||||||
"import/no-unresolved": [0, { "ignore": ["^react-bootstrap-table"] }], // monorepo setup
|
"import/no-unresolved": [0, { "ignore": ["^react-bootstrap-table"] }], // monorepo setup
|
||||||
"import/prefer-default-export": 0,
|
"import/prefer-default-export": 0,
|
||||||
|
|||||||
@@ -74,6 +74,11 @@
|
|||||||
"testEnvironment": "node",
|
"testEnvironment": "node",
|
||||||
"testMatch": [
|
"testMatch": [
|
||||||
"**/test/**/*.test.js"
|
"**/test/**/*.test.js"
|
||||||
|
],
|
||||||
|
"moduleFileExtensions": ["js", "jsx"],
|
||||||
|
"moduleDirectories": [
|
||||||
|
"node_modules",
|
||||||
|
"packages/react-bootstrap-table2"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* eslint no-console: 0 */
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDom from 'react-dom';
|
import ReactDom from 'react-dom';
|
||||||
|
|
||||||
|
|||||||
1
packages/react-bootstrap-table2/src/body.js
vendored
1
packages/react-bootstrap-table2/src/body.js
vendored
@@ -1,5 +1,4 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
/* eslint react/require-default-props: 0 */
|
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint react/require-default-props: 0 */
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import cs from 'classnames';
|
import cs from 'classnames';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint react/require-default-props: 0 */
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Const from './const';
|
import Const from './const';
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* eslint
|
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
|
||||||
react/require-default-props: 0
|
|
||||||
jsx-a11y/no-noninteractive-element-interactions: 0
|
|
||||||
*/
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Const from '../const';
|
import Const from '../const';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint react/require-default-props: 0 */
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Constant from '../const';
|
import Constant from '../const';
|
||||||
|
|||||||
@@ -2,33 +2,22 @@ import React from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Body from '../src/body';
|
import Body from 'src/body';
|
||||||
import Row from '../src/row';
|
import Row from 'src/row';
|
||||||
import Const from '../src/const';
|
import Const from 'src/const';
|
||||||
import RowSection from '../src/row-section';
|
import RowSection from 'src/row-section';
|
||||||
import mockBodyResolvedProps from '../test/mock-data/body-resolved-props';
|
import { baseColumns, baseData, baseProps, bodyResolvedProps } from 'test/factory';
|
||||||
|
|
||||||
|
const columns = baseColumns();
|
||||||
|
const data = baseData();
|
||||||
|
const mockBodyResolvedProps = bodyResolvedProps();
|
||||||
|
|
||||||
describe('Body', () => {
|
describe('Body', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const columns = [{
|
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
}, {
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Name'
|
|
||||||
}];
|
|
||||||
|
|
||||||
const data = [{
|
|
||||||
id: 1,
|
|
||||||
name: 'A'
|
|
||||||
}, {
|
|
||||||
id: 2,
|
|
||||||
name: 'B'
|
|
||||||
}];
|
|
||||||
|
|
||||||
describe('simplest body', () => {
|
describe('simplest body', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<Body {...mockBodyResolvedProps} keyField="id" columns={ columns } data={ data } />);
|
wrapper = shallow(<Body {...baseProps} {...mockBodyResolvedProps} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render successfully', () => {
|
it('should render successfully', () => {
|
||||||
@@ -42,10 +31,8 @@ describe('Body', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Body
|
<Body
|
||||||
|
{...baseProps}
|
||||||
{...mockBodyResolvedProps}
|
{...mockBodyResolvedProps}
|
||||||
keyField="id"
|
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
visibleColumnSize={ columns.length }
|
visibleColumnSize={ columns.length }
|
||||||
isEmpty
|
isEmpty
|
||||||
/>);
|
/>);
|
||||||
@@ -67,10 +54,8 @@ describe('Body', () => {
|
|||||||
emptyIndication = 'Table is empty';
|
emptyIndication = 'Table is empty';
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Body
|
<Body
|
||||||
|
{...baseProps}
|
||||||
{...mockBodyResolvedProps}
|
{...mockBodyResolvedProps}
|
||||||
keyField="id"
|
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
visibleColumnSize={ columns.length }
|
visibleColumnSize={ columns.length }
|
||||||
noDataIndication={ emptyIndication }
|
noDataIndication={ emptyIndication }
|
||||||
isEmpty
|
isEmpty
|
||||||
@@ -93,10 +78,8 @@ describe('Body', () => {
|
|||||||
emptyIndicationCallBack = sinon.stub().returns(content);
|
emptyIndicationCallBack = sinon.stub().returns(content);
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Body
|
<Body
|
||||||
|
{...baseProps}
|
||||||
{...mockBodyResolvedProps}
|
{...mockBodyResolvedProps}
|
||||||
keyField="id"
|
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
visibleColumnSize={ columns.length }
|
visibleColumnSize={ columns.length }
|
||||||
noDataIndication={ emptyIndicationCallBack }
|
noDataIndication={ emptyIndicationCallBack }
|
||||||
isEmpty
|
isEmpty
|
||||||
@@ -127,10 +110,8 @@ describe('Body', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Body
|
<Body
|
||||||
|
{...baseProps}
|
||||||
{...mockBodyResolvedProps}
|
{...mockBodyResolvedProps}
|
||||||
data={ data }
|
|
||||||
columns={ columns }
|
|
||||||
keyField={ keyField }
|
|
||||||
cellEdit={ cellEdit }
|
cellEdit={ cellEdit }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -150,16 +131,13 @@ describe('Body', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when selectRow.mode is checkbox or radio (row was selectable)', () => {
|
describe('when selectRow.mode is checkbox or radio (row was selectable)', () => {
|
||||||
const keyField = 'id';
|
|
||||||
const selectRow = { mode: 'checkbox' };
|
const selectRow = { mode: 'checkbox' };
|
||||||
|
|
||||||
it('props selected should be true if all rows were selected', () => {
|
it('props selected should be true if all rows were selected', () => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Body
|
<Body
|
||||||
|
{...baseProps}
|
||||||
{...mockBodyResolvedProps}
|
{...mockBodyResolvedProps}
|
||||||
data={ data }
|
|
||||||
columns={ columns }
|
|
||||||
keyField={ keyField }
|
|
||||||
selectedRowKeys={[1, 2]}
|
selectedRowKeys={[1, 2]}
|
||||||
selectRow={selectRow}
|
selectRow={selectRow}
|
||||||
/>
|
/>
|
||||||
@@ -171,10 +149,8 @@ describe('Body', () => {
|
|||||||
it('props selected should be false if all rows were not selected', () => {
|
it('props selected should be false if all rows were not selected', () => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Body
|
<Body
|
||||||
|
{...baseProps}
|
||||||
{...mockBodyResolvedProps}
|
{...mockBodyResolvedProps}
|
||||||
data={ data }
|
|
||||||
columns={ columns }
|
|
||||||
keyField={ keyField }
|
|
||||||
selectedRowKeys={[]}
|
selectedRowKeys={[]}
|
||||||
selectRow={selectRow}
|
selectRow={selectRow}
|
||||||
/>
|
/>
|
||||||
@@ -186,13 +162,10 @@ describe('Body', () => {
|
|||||||
|
|
||||||
describe('when selectRow.mode is ROW_SELECT_DISABLED (row was un-selectable)', () => {
|
describe('when selectRow.mode is ROW_SELECT_DISABLED (row was un-selectable)', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const keyField = 'id';
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Body
|
<Body
|
||||||
|
{...baseProps}
|
||||||
{...mockBodyResolvedProps}
|
{...mockBodyResolvedProps}
|
||||||
data={ data }
|
|
||||||
columns={ columns }
|
|
||||||
keyField={ keyField }
|
|
||||||
selectedRowKeys={[]}
|
selectedRowKeys={[]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,33 +2,20 @@ import React from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Caption from '../src/caption';
|
import Caption from 'src/caption';
|
||||||
import Header from '../src/header';
|
import BootstrapTable from 'src/bootstrap-table';
|
||||||
import Body from '../src/body';
|
import Header from 'src/header';
|
||||||
import BootstrapTable from '../src/bootstrap-table';
|
import Body from 'src/body';
|
||||||
import Const from '../src/const';
|
import Const from 'src/const';
|
||||||
|
import { baseData, baseProps } from 'test/factory';
|
||||||
|
|
||||||
describe('BootstrapTable', () => {
|
describe('BootstrapTable', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const columns = [{
|
const data = baseData();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
}, {
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Name'
|
|
||||||
}];
|
|
||||||
|
|
||||||
const data = [{
|
|
||||||
id: 1,
|
|
||||||
name: 'A'
|
|
||||||
}, {
|
|
||||||
id: 2,
|
|
||||||
name: 'B'
|
|
||||||
}];
|
|
||||||
|
|
||||||
describe('simplest table', () => {
|
describe('simplest table', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } />);
|
wrapper = shallow(<BootstrapTable {...baseProps} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render successfully', () => {
|
it('should render successfully', () => {
|
||||||
@@ -52,7 +39,7 @@ describe('BootstrapTable', () => {
|
|||||||
|
|
||||||
describe('when hover props is true', () => {
|
describe('when hover props is true', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } hover />);
|
wrapper = shallow(<BootstrapTable {...baseProps} hover />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have table-hover class on table', () => {
|
it('should have table-hover class on table', () => {
|
||||||
@@ -62,7 +49,7 @@ describe('BootstrapTable', () => {
|
|||||||
|
|
||||||
describe('when striped props is true', () => {
|
describe('when striped props is true', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } striped />);
|
wrapper = shallow(<BootstrapTable {...baseProps} striped />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have table-striped class on table', () => {
|
it('should have table-striped class on table', () => {
|
||||||
@@ -72,7 +59,7 @@ describe('BootstrapTable', () => {
|
|||||||
|
|
||||||
describe('when condensed props is true', () => {
|
describe('when condensed props is true', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } condensed />);
|
wrapper = shallow(<BootstrapTable {...baseProps} condensed />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have table-condensed class on table', () => {
|
it('should have table-condensed class on table', () => {
|
||||||
@@ -82,7 +69,7 @@ describe('BootstrapTable', () => {
|
|||||||
|
|
||||||
describe('when bordered props is false', () => {
|
describe('when bordered props is false', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<BootstrapTable keyField="id" columns={ columns } data={ data } bordered={ false } />);
|
wrapper = shallow(<BootstrapTable {...baseProps} bordered={ false } />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not have table-condensed class on table', () => {
|
it('should not have table-condensed class on table', () => {
|
||||||
@@ -94,10 +81,8 @@ describe('BootstrapTable', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
|
{...baseProps}
|
||||||
caption={ <span className="table-caption">test</span> }
|
caption={ <span className="table-caption">test</span> }
|
||||||
keyField="id"
|
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
bordered={ false }
|
bordered={ false }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -120,9 +105,7 @@ describe('BootstrapTable', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
keyField="id"
|
{...baseProps}
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
bordered={ false }
|
bordered={ false }
|
||||||
cellEdit={ cellEdit }
|
cellEdit={ cellEdit }
|
||||||
/>
|
/>
|
||||||
@@ -148,9 +131,7 @@ describe('BootstrapTable', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
keyField="id"
|
{...baseProps}
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
selectRow={{ mode: 'radio' }}
|
selectRow={{ mode: 'radio' }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -169,9 +150,7 @@ describe('BootstrapTable', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
keyField="id"
|
{...baseProps}
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
selectRow={{ mode: 'checkbox' }}
|
selectRow={{ mode: 'checkbox' }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -197,11 +176,7 @@ describe('BootstrapTable', () => {
|
|||||||
describe('handleAllRowsSelect', () => {
|
describe('handleAllRowsSelect', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<BootstrapTable
|
<BootstrapTable {...baseProps} />
|
||||||
keyField="id"
|
|
||||||
columns={ columns }
|
|
||||||
data={ data }
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,17 @@ import React from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Const from '../src/const';
|
import Const from 'src/const';
|
||||||
import Cell from '../src/cell';
|
import Cell from 'src/cell';
|
||||||
|
|
||||||
|
import { baseColumn, baseRow } from 'test/factory';
|
||||||
|
|
||||||
describe('Cell', () => {
|
describe('Cell', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const row = {
|
const row = baseRow();
|
||||||
id: 1,
|
|
||||||
name: 'A'
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('simplest cell', () => {
|
describe('simplest cell', () => {
|
||||||
const column = {
|
const column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<Cell row={ row } columnIndex={ 1 } rowIndex={ 1 } column={ column } />);
|
wrapper = shallow(<Cell row={ row } columnIndex={ 1 } rowIndex={ 1 } column={ column } />);
|
||||||
@@ -30,8 +26,7 @@ describe('Cell', () => {
|
|||||||
|
|
||||||
describe('when column.hidden prop is true', () => {
|
describe('when column.hidden prop is true', () => {
|
||||||
const column = {
|
const column = {
|
||||||
dataField: 'id',
|
...baseColumn(),
|
||||||
text: 'ID',
|
|
||||||
hidden: true
|
hidden: true
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,8 +44,7 @@ describe('Cell', () => {
|
|||||||
describe('when column.formatter prop is defined', () => {
|
describe('when column.formatter prop is defined', () => {
|
||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
const column = {
|
const column = {
|
||||||
dataField: 'id',
|
...baseColumn(),
|
||||||
text: 'ID',
|
|
||||||
formatExtraData: []
|
formatExtraData: []
|
||||||
};
|
};
|
||||||
const formatterResult = (<h3>{ row[column.dataField] }</h3>);
|
const formatterResult = (<h3>{ row[column.dataField] }</h3>);
|
||||||
@@ -85,10 +79,7 @@ describe('Cell', () => {
|
|||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
column = {
|
column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when style is an object', () => {
|
describe('when style is an object', () => {
|
||||||
@@ -139,10 +130,7 @@ describe('Cell', () => {
|
|||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
column = {
|
column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when classes is an object', () => {
|
describe('when classes is an object', () => {
|
||||||
@@ -193,10 +181,7 @@ describe('Cell', () => {
|
|||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
column = {
|
column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when title is boolean', () => {
|
describe('when title is boolean', () => {
|
||||||
@@ -246,8 +231,7 @@ describe('Cell', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
column = {
|
column = {
|
||||||
dataField: 'id',
|
...baseColumn(),
|
||||||
text: 'ID',
|
|
||||||
events: {
|
events: {
|
||||||
onClick: sinon.stub()
|
onClick: sinon.stub()
|
||||||
}
|
}
|
||||||
@@ -274,10 +258,7 @@ describe('Cell', () => {
|
|||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
column = {
|
column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when align is string', () => {
|
describe('when align is string', () => {
|
||||||
@@ -326,10 +307,7 @@ describe('Cell', () => {
|
|||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
column = {
|
column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when attrs is an object', () => {
|
describe('when attrs is an object', () => {
|
||||||
@@ -453,10 +431,7 @@ describe('Cell', () => {
|
|||||||
let onStartCallBack;
|
let onStartCallBack;
|
||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
const columnIndex = 1;
|
const columnIndex = 1;
|
||||||
const column = {
|
const column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
onStartCallBack = sinon.stub().withArgs(rowIndex, columnIndex);
|
onStartCallBack = sinon.stub().withArgs(rowIndex, columnIndex);
|
||||||
|
|||||||
@@ -3,24 +3,20 @@ import React from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow, mount } from 'enzyme';
|
import { shallow, mount } from 'enzyme';
|
||||||
|
|
||||||
import { TableRowWrapper } from './test-helpers/table-wrapper';
|
import EditingCell from 'src/editing-cell';
|
||||||
import EditingCell from '../src/editing-cell';
|
import TextEditor from 'src/text-editor';
|
||||||
import TextEditor from '../src/text-editor';
|
import EditorIndicator from 'src/editor-indicator';
|
||||||
import EditorIndicator from '../src/editor-indicator';
|
|
||||||
|
import { TableRowWrapper } from 'test/test-helpers/table-wrapper';
|
||||||
|
import { baseColumn, baseRow } from 'test/factory';
|
||||||
|
|
||||||
describe('EditingCell', () => {
|
describe('EditingCell', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let onEscape;
|
let onEscape;
|
||||||
let onComplete;
|
let onComplete;
|
||||||
const row = {
|
const row = baseRow();
|
||||||
id: 1,
|
|
||||||
name: 'A'
|
|
||||||
};
|
|
||||||
|
|
||||||
let column = {
|
let column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
onComplete = sinon.stub();
|
onComplete = sinon.stub();
|
||||||
|
|||||||
30
packages/react-bootstrap-table2/test/factory/base-props.js
vendored
Normal file
30
packages/react-bootstrap-table2/test/factory/base-props.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
export const baseColumns = () => [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Name'
|
||||||
|
}];
|
||||||
|
|
||||||
|
export const baseColumn = () => ({ dataField: 'id', text: 'ID' });
|
||||||
|
|
||||||
|
export const baseData = () => [{
|
||||||
|
id: 1,
|
||||||
|
name: 'A'
|
||||||
|
}, {
|
||||||
|
id: 2,
|
||||||
|
name: 'B'
|
||||||
|
}];
|
||||||
|
|
||||||
|
export const baseRow = () => ({ id: 1, name: 'A' });
|
||||||
|
|
||||||
|
export const baseKeyField = () => 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baseProps contains those basical props marked as `required` in BootstrapTable
|
||||||
|
*/
|
||||||
|
export const baseProps = {
|
||||||
|
columns: baseColumns(),
|
||||||
|
data: baseData(),
|
||||||
|
keyField: baseKeyField()
|
||||||
|
};
|
||||||
19
packages/react-bootstrap-table2/test/factory/index.js
vendored
Normal file
19
packages/react-bootstrap-table2/test/factory/index.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { bodyResolvedProps, headerResolvedProps } from './resolved-props';
|
||||||
|
import {
|
||||||
|
baseColumns, baseColumn, baseData,
|
||||||
|
baseKeyField, baseRow, baseProps
|
||||||
|
} from './base-props';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide the base props in order to test easiler.
|
||||||
|
*/
|
||||||
|
export {
|
||||||
|
bodyResolvedProps,
|
||||||
|
headerResolvedProps,
|
||||||
|
baseColumns,
|
||||||
|
baseColumn,
|
||||||
|
baseData,
|
||||||
|
baseRow,
|
||||||
|
baseKeyField,
|
||||||
|
baseProps
|
||||||
|
};
|
||||||
13
packages/react-bootstrap-table2/test/factory/resolved-props.js
vendored
Normal file
13
packages/react-bootstrap-table2/test/factory/resolved-props.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import BootstrapTable from 'src/bootstrap-table';
|
||||||
|
import { baseProps as props } from './base-props';
|
||||||
|
|
||||||
|
const bootstrapTable = new BootstrapTable(props);
|
||||||
|
|
||||||
|
export const bodyResolvedProps = () => ({
|
||||||
|
cellEdit: bootstrapTable.resolveCellEditProps(),
|
||||||
|
selectRow: bootstrapTable.resolveCellSelectionProps()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const headerResolvedProps = () => ({
|
||||||
|
selectRow: bootstrapTable.resolveHeaderCellSelectionProps()
|
||||||
|
});
|
||||||
@@ -2,20 +2,19 @@ import React from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Const from '../src/const';
|
import Const from 'src/const';
|
||||||
import SortCaret from '../src/sort-caret';
|
import SortCaret from 'src/sort-caret';
|
||||||
import SortSymbol from '../src/sort-symbol';
|
import SortSymbol from 'src/sort-symbol';
|
||||||
import HeaderCell from '../src/header-cell';
|
import HeaderCell from 'src/header-cell';
|
||||||
|
|
||||||
|
import { baseColumn } from 'test/factory';
|
||||||
|
|
||||||
describe('HeaderCell', () => {
|
describe('HeaderCell', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const index = 1;
|
const index = 1;
|
||||||
|
|
||||||
describe('simplest header cell', () => {
|
describe('simplest header cell', () => {
|
||||||
const column = {
|
const column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
|
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
|
||||||
@@ -35,8 +34,7 @@ describe('HeaderCell', () => {
|
|||||||
|
|
||||||
describe('when column.hidden props is true', () => {
|
describe('when column.hidden props is true', () => {
|
||||||
const column = {
|
const column = {
|
||||||
dataField: 'id',
|
...baseColumn(),
|
||||||
text: 'ID',
|
|
||||||
hidden: true
|
hidden: true
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -142,10 +140,8 @@ describe('HeaderCell', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when column.headerFormatter prop is defined', () => {
|
describe('when column.headerFormatter prop is defined', () => {
|
||||||
const column = {
|
const column = baseColumn();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
};
|
|
||||||
const formatterResult = (<h3>{ column.text }</h3>);
|
const formatterResult = (<h3>{ column.text }</h3>);
|
||||||
const formatter = sinon.stub()
|
const formatter = sinon.stub()
|
||||||
.withArgs(column, index)
|
.withArgs(column, index)
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import HeaderCell from '../src/header-cell';
|
import HeaderCell from 'src/header-cell';
|
||||||
import SelectionHeaderCell from '../src//row-selection/selection-header-cell';
|
import SelectionHeaderCell from 'src/row-selection/selection-header-cell';
|
||||||
import Header from '../src/header';
|
import Header from 'src/header';
|
||||||
import Const from '../src/const';
|
import Const from 'src/const';
|
||||||
import mockHeaderResolvedProps from '../test/mock-data/header-resolved-props';
|
import { headerResolvedProps, baseColumns } from 'test/factory';
|
||||||
|
|
||||||
|
const mockHeaderResolvedProps = headerResolvedProps();
|
||||||
|
|
||||||
describe('Header', () => {
|
describe('Header', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const columns = [{
|
const columns = baseColumns();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
}, {
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Name'
|
|
||||||
}];
|
|
||||||
|
|
||||||
describe('simplest header', () => {
|
describe('simplest header', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import Const from '../../src/const';
|
|
||||||
|
|
||||||
const { ROW_SELECT_DISABLED, UNABLE_TO_CELL_EDIT } = Const;
|
|
||||||
|
|
||||||
export const cellSelectionResolvedProps = {
|
|
||||||
mode: ROW_SELECT_DISABLED
|
|
||||||
};
|
|
||||||
|
|
||||||
export const cellEditResolvedProps = {
|
|
||||||
mode: UNABLE_TO_CELL_EDIT
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
|
||||||
cellEdit: cellEditResolvedProps,
|
|
||||||
selectRow: cellSelectionResolvedProps
|
|
||||||
};
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import Const from '../../src/const';
|
|
||||||
|
|
||||||
const { ROW_SELECT_DISABLED } = Const;
|
|
||||||
|
|
||||||
export const headerCellSelectionResolvedProps = {
|
|
||||||
mode: ROW_SELECT_DISABLED
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
|
||||||
selectRow: headerCellSelectionResolvedProps
|
|
||||||
};
|
|
||||||
@@ -2,27 +2,16 @@ import React, { Component } from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { extendTo } from '../test-helpers/mock-component';
|
import baseResolver from 'src/props-resolver/index';
|
||||||
import baseResolver from '../../src/props-resolver/index';
|
import Const from 'src/const';
|
||||||
import Const from '../../src/const';
|
import { extendTo } from 'test/test-helpers/mock-component';
|
||||||
|
import { baseColumns, baseData, baseKeyField } from 'test/factory';
|
||||||
|
|
||||||
|
const columns = baseColumns();
|
||||||
|
const data = baseData();
|
||||||
|
const keyField = baseKeyField();
|
||||||
|
|
||||||
describe('TableResolver', () => {
|
describe('TableResolver', () => {
|
||||||
const keyField = 'id';
|
|
||||||
const columns = [{
|
|
||||||
dataField: keyField,
|
|
||||||
text: 'ID'
|
|
||||||
}, {
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Name'
|
|
||||||
}];
|
|
||||||
const data = [{
|
|
||||||
id: 1,
|
|
||||||
name: 'A'
|
|
||||||
}, {
|
|
||||||
id: 2,
|
|
||||||
name: 'B'
|
|
||||||
}];
|
|
||||||
|
|
||||||
const ExtendBase = baseResolver(Component);
|
const ExtendBase = baseResolver(Component);
|
||||||
const BootstrapTableMock = extendTo(ExtendBase);
|
const BootstrapTableMock = extendTo(ExtendBase);
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import RowSection from '../src/row-section';
|
import RowSection from 'src/row-section';
|
||||||
|
|
||||||
describe('Row', () => {
|
describe('Row', () => {
|
||||||
const colSpan = 3;
|
const colSpan = 3;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import SelectionCell from '../../src/row-selection/selection-cell';
|
import SelectionCell from 'src/row-selection/selection-cell';
|
||||||
|
|
||||||
describe('<SelectionCell />', () => {
|
describe('<SelectionCell />', () => {
|
||||||
const mode = 'checkbox';
|
const mode = 'checkbox';
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import React from 'react';
|
|||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import Constant from '../../src/const';
|
import Constant from 'src/const';
|
||||||
import SelectionHeaderCell, { CheckBox } from '../../src/row-selection/selection-header-cell';
|
import SelectionHeaderCell, { CheckBox } from 'src/row-selection/selection-header-cell';
|
||||||
|
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
|
|||||||
@@ -2,32 +2,21 @@ import React from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Cell from '../src/cell';
|
import Cell from 'src/cell';
|
||||||
import Row from '../src/row';
|
import Row from 'src/row';
|
||||||
import Const from '../src/const';
|
import Const from 'src/const';
|
||||||
import EditingCell from '../src/editing-cell';
|
import EditingCell from 'src/editing-cell';
|
||||||
import SelectionCell from '../src//row-selection/selection-cell';
|
import SelectionCell from 'src/row-selection/selection-cell';
|
||||||
import mockBodyResolvedProps from '../test/mock-data/body-resolved-props';
|
import { bodyResolvedProps, baseColumns, baseRow } from 'test/factory';
|
||||||
|
|
||||||
const defaultColumns = [{
|
const mockBodyResolvedProps = bodyResolvedProps();
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
const defaultColumns = baseColumns();
|
||||||
}, {
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Name'
|
|
||||||
}, {
|
|
||||||
dataField: 'price',
|
|
||||||
text: 'Price'
|
|
||||||
}];
|
|
||||||
|
|
||||||
describe('Row', () => {
|
describe('Row', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
const row = {
|
const row = baseRow();
|
||||||
id: 1,
|
|
||||||
name: 'A',
|
|
||||||
price: 1000
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('simplest row', () => {
|
describe('simplest row', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Const from '../src/const';
|
import Const from 'src/const';
|
||||||
import SortCaret from '../src/sort-caret';
|
import SortCaret from 'src/sort-caret';
|
||||||
|
|
||||||
describe('SortCaret', () => {
|
describe('SortCaret', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import SortSymbol from '../src/sort-symbol';
|
import SortSymbol from 'src/sort-symbol';
|
||||||
|
|
||||||
describe('SortSymbol', () => {
|
describe('SortSymbol', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import Base from '../../src/store/base';
|
import Base from 'src/store/base';
|
||||||
import Const from '../../src/const';
|
import Const from 'src/const';
|
||||||
import _ from '../../src/utils';
|
import _ from 'src/utils';
|
||||||
|
import { baseKeyField } from 'test/factory';
|
||||||
|
|
||||||
|
const keyField = baseKeyField();
|
||||||
|
|
||||||
describe('Store Base', () => {
|
describe('Store Base', () => {
|
||||||
let store;
|
let store;
|
||||||
@@ -13,7 +16,7 @@ describe('Store Base', () => {
|
|||||||
{ id: 4, name: '123tester' },
|
{ id: 4, name: '123tester' },
|
||||||
{ id: 1, name: '!@#' }
|
{ id: 1, name: '!@#' }
|
||||||
];
|
];
|
||||||
store = new Base({ data, keyField: 'id' });
|
store = new Base({ data, keyField });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('initialize', () => {
|
describe('initialize', () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import { sort } from '../../src/store/sort';
|
import { sort } from 'src/store/sort';
|
||||||
import Const from '../../src/const';
|
import Const from 'src/const';
|
||||||
|
|
||||||
describe('Sort Function', () => {
|
describe('Sort Function', () => {
|
||||||
const data = [
|
const data = [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import TextEditor from '../src/text-editor';
|
import TextEditor from 'src/text-editor';
|
||||||
|
|
||||||
describe('TextEditor', () => {
|
describe('TextEditor', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ from '../src/utils';
|
import _ from 'src/utils';
|
||||||
|
|
||||||
describe('Utils', () => {
|
describe('Utils', () => {
|
||||||
describe('get', () => {
|
describe('get', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user