Skip to content

Commit

Permalink
code coverage now at 91%. ready for first publish
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnb committed Dec 27, 2017
1 parent bc6fc8d commit aedfdba
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,8 @@ const options = {
}
};

```
```


## License
The files included in this repository are licensed under the MIT license.
88 changes: 87 additions & 1 deletion test/MUIDataTable.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import { spy } from "sinon";
import { mount, shallow } from "enzyme";
import { assert, expect, should } from "chai";
import MUIDataTable from "../src/MUIDataTable";
Expand Down Expand Up @@ -49,6 +50,46 @@ describe("<MUIDataTable />", function() {
assert.deepEqual(state.displayData, data);
});

it("should correctly re-build internal table data and displayData structure with prop change", () => {
const mountWrapper = mount(<MUIDataTable columns={columns} data={data} />);
let state = mountWrapper.state();
assert.deepEqual(state.data, data);
assert.deepEqual(state.displayData, data);

// now use updated props
let newData = data.map(item => [...item]);
newData[0][0] = "testing";
mountWrapper.setProps({ data: newData });
mountWrapper.update();

state = mountWrapper.state();
const expectedResult = [
["testing", "Test Corp", "Yonkers", "NY"],
["John Walsh", "Test Corp", "Hartford", "CT"],
["Bob Herm", "Test Corp", "Tampa", "FL"],
["James Houston", "Test Corp", "Dallas", "TX"],
];

assert.deepEqual(state.data, expectedResult);
});

it("should not re-build internal table data and displayData structure with no prop change to data or columns", () => {
const initializeTableSpy = spy(MUIDataTable.prototype, "initializeTable");
const mountWrapper = mount(<MUIDataTable columns={columns} data={data} />);

let state = mountWrapper.state();
assert.deepEqual(state.data, data);
assert.deepEqual(state.displayData, data);

// now update props with no change
mountWrapper.setProps({});
mountWrapper.update();

state = mountWrapper.state();
assert.deepEqual(state.data, data);
assert.deepEqual(initializeTableSpy.callCount, 1);
});

it("should correctly build internal filterList structure", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const state = shallowWrapper.state();
Expand Down Expand Up @@ -110,7 +151,7 @@ describe("<MUIDataTable />", function() {
assert.lengthOf(actualResult, 0);
});

it("should properly set internal filterList when calling filterUpdate method", () => {
it("should properly set internal filterList when calling filterUpdate method with type=checkbox", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const table = shallowWrapper;
const instance = table.instance();
Expand All @@ -121,6 +162,51 @@ describe("<MUIDataTable />", function() {
assert.deepEqual(state.filterList, [["Joe James"], [], [], []]);
});

it("should remove entry from filterList when calling filterUpdate method with type=checkbox and same arguments a second time", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const table = shallowWrapper;
const instance = table.instance();
instance.filterUpdate(0, "Joe James", "checkbox");
table.update();

let state = table.state();
assert.deepEqual(state.filterList, [["Joe James"], [], [], []]);

instance.filterUpdate(0, "Joe James", "checkbox");
table.update();

state = table.state();
assert.deepEqual(state.filterList, [[], [], [], []]);
});

it("should properly set internal filterList when calling filterUpdate method with type=dropdown", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const table = shallowWrapper;
const instance = table.instance();
instance.filterUpdate(0, "Joe James", "dropdown");
table.update();

const state = table.state();
assert.deepEqual(state.filterList, [["Joe James"], [], [], []]);
});

it("should remove entry from filterList when calling filterUpdate method with type=dropdown and same arguments a second time", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const table = shallowWrapper;
const instance = table.instance();
instance.filterUpdate(0, "Joe James", "dropdown");
table.update();

let state = table.state();
assert.deepEqual(state.filterList, [["Joe James"], [], [], []]);

instance.filterUpdate(0, "Joe James", "dropdown");
table.update();

state = table.state();
assert.deepEqual(state.filterList, [[], [], [], []]);
});

it("should properly reset internal filterList when calling resetFilters method", () => {
// set a filter
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
Expand Down
7 changes: 2 additions & 5 deletions test/MUIDataTableSearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ describe("<MUIDataTableSearch />", function() {

const mountWrapper = mount(<MUIDataTableSearch onHide={onHide} options={options} />, { attachTo: document.body });

simulant.fire(document.body.querySelector('input'), 'keydown', { keyCode: 27 });
simulant.fire(document.body.querySelector("input"), "keydown", { keyCode: 27 });
assert.strictEqual(onHide.callCount, 1);

});

it("should hide not hide search bar when entering anything but the ESCAPE key", () => {
Expand All @@ -48,9 +47,7 @@ describe("<MUIDataTableSearch />", function() {

const mountWrapper = mount(<MUIDataTableSearch onHide={onHide} options={options} />, { attachTo: document.body });

simulant.fire(document.body.querySelector('input'), 'keydown', { keyCode: 25 });
simulant.fire(document.body.querySelector("input"), "keydown", { keyCode: 25 });
assert.strictEqual(onHide.callCount, 0);

});

});
2 changes: 1 addition & 1 deletion test/MUIDataTableToolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("<MUIDataTableToolbar />", function() {
const mountWrapper = mount(<MUIDataTableToolbar columns={columns} data={data} options={newOptions} />);
const actualResult = mountWrapper.find(FilterIcon);
assert.strictEqual(actualResult.length, 0);
});
});

it("should render a toolbar with a search clicking search icon", () => {
const mountWrapper = mount(<MUIDataTableToolbar columns={columns} data={data} options={options} />);
Expand Down

0 comments on commit aedfdba

Please sign in to comment.