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

New test #5

Merged
merged 1 commit into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});