This commit is contained in:
Allen
2017-08-26 04:55:00 -05:00
committed by GitHub
parent b00007cde9
commit 4da199f4fc
2 changed files with 37 additions and 2 deletions

View File

@@ -5,8 +5,16 @@ import _ from './utils';
const HeaderCell = ({ column, index }) => {
const { headerTitle, text, headerAlign, headerFormatter } = column;
const attrs = {};
const {
text,
headerTitle,
headerAlign,
headerFormatter,
headerEvents
} = column;
const attrs = {
...headerEvents
};
const headerStyle = {};
const children = headerFormatter ? headerFormatter(column, index) : text;
@@ -39,6 +47,7 @@ HeaderCell.propTypes = {
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
headerTitle: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
title: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
headerEvents: PropTypes.object,
events: PropTypes.object,
headerAlign: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
align: PropTypes.oneOfType([PropTypes.string, PropTypes.func])

View File

@@ -147,4 +147,30 @@ describe('HeaderCell', () => {
expect(formatter.calledWith(column, index)).toBe(true);
});
});
describe('when column.headerEvents prop is defined', () => {
let column;
beforeEach(() => {
column = {
dataField: 'id',
text: 'ID',
headerEvents: {
onClick: sinon.stub()
}
};
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
});
it('should attachs DOM event successfully', () => {
expect(wrapper.length).toBe(1);
expect(wrapper.find('th').prop('onClick')).toBeDefined();
});
it('event hook should be called when triggering', () => {
wrapper.find('th').simulate('click');
expect(column.headerEvents.onClick.callCount).toBe(1);
});
});
});