Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge 7b0be31 into 2b858ac
Browse files Browse the repository at this point in the history
  • Loading branch information
patorjk committed Sep 8, 2019
2 parents 2b858ac + 7b0be31 commit 3d40a33
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/csv-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Example extends React.Component {
rowsPerPage: 10,
downloadOptions: {
filename: 'excel-format.csv',
separator: ';',
separator: ',',
filterOptions: {
useDisplayedColumnsOnly: true,
useDisplayedRowsOnly: true,
Expand Down
15 changes: 6 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ function sortCompare(order) {
}

function createCSVDownload(columns, data, options) {
const replaceDoubleQuoteInString = columnData =>
typeof columnData === 'string' ? columnData.replace(/\"/g, '""') : columnData;
const replaceDoubleQuoteInString = columnData => {
return typeof columnData === 'string' ? columnData.replace(/\"/g, '""') : columnData;
};

const buildHead = columns => {
return (
columns
.reduce(
(soFar, column) =>
column.download
? soFar + '"' + replaceDoubleQuoteInString(column.name) + '"' + options.downloadOptions.separator
: soFar,
'',
)
.reduce((soFar, column) => {
return column.download ? soFar + '"' + replaceDoubleQuoteInString(column.name) + '"' + options.downloadOptions.separator : soFar;
}, '')
.slice(0, -1) + '\r\n'
);
};
Expand Down
43 changes: 43 additions & 0 deletions test/MUIDataTableBodyCell.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { spy, stub } from 'sinon';
import { mount, shallow } from 'enzyme';
import { assert, expect, should } from 'chai';
import textLabels from '../src/textLabels';
import TableBodyCell from '../src/components/TableBodyCell';

describe('<TableBodyCell />', function() {
let classes;

before(() => {
classes = {
root: {},
};
});

it('should trigger onCellClick prop callback when clicking cell', () => {
const options = { sort: true, textLabels, onCellClick: spy() };

const fullWrapper = mount(
<TableBodyCell
options={options}
colIndex={0}
rowIndex={0}
dataIndex={0}
print={false}
columnHeader="Header"
onCellClick={options.onCellClick}
classes={classes}>
some content
</TableBodyCell>,
);

// The test should click on both TDs that are rendered, but only 1 onCellClick
// should fire because the first TD represents the column header (due to responsive design).
fullWrapper.find('td').forEach(item => {
item.simulate('click');
});

assert.strictEqual(options.onCellClick.callCount, 1);

});
});
6 changes: 4 additions & 2 deletions test/MUIDataTableHeadCell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('<TableHeadCell />', function() {
assert.strictEqual(actualResult.length, 0);
});

it('should trigger toggleSort prop callback when calling method handleSortClick', () => {
it('should trigger toggleSort prop callback when clicking or pressing enter on column label', () => {
const options = { sort: true, textLabels };
const toggleSort = spy();

Expand All @@ -87,7 +87,9 @@ describe('<TableHeadCell />', function() {
);

fullWrapper.find('span[data-column-label="true"]').simulate('click');

assert.strictEqual(toggleSort.callCount, 1);

fullWrapper.find('span[data-column-label="true"]').simulate('keyUp', {key: 'Enter'});
assert.strictEqual(toggleSort.callCount, 2);
});
});

0 comments on commit 3d40a33

Please sign in to comment.