Skip to content

Commit

Permalink
set prettier on test/
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnb committed Dec 23, 2017
1 parent 94cad45 commit 7799301
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 136 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "mocha --require babel-register test/**/*.test.js",
"coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha --require babel-register test/*.js && nyc report --reporter=html | cat coverage/lcov.info | coveralls",
"coverage:html": "cross-env NODE_ENV=test nyc check-coverage --lines 55 --reporter=html --reporter=text mocha --require babel-register test/*.js && nyc report --reporter=html",
"prettier": "find src/ -name \"*.js\" | xargs prettier --write",
"prettier": "find src/ test/ -name \"*.js\" | xargs prettier --write",
"lint": "eslint src",
"build": "cross-env NODE_ENV=production npm run prettier && rollup -c"
},
Expand Down
6 changes: 2 additions & 4 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ class MUIDataTable extends React.Component {
this.initializeTable(this.props);
}

componentDidMount() {
}
componentDidMount() {}

componentWillUnmount() {
}
componentWillUnmount() {}

componentWillReceiveProps(nextProps) {
if (this.props.data !== nextProps.data || this.props.columns !== nextProps.columns) {
Expand Down
71 changes: 21 additions & 50 deletions test/MUIDataTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ describe("<MUIDataTable />", function() {
["Bob Herm", "Test Corp", "Tampa", "FL"],
["James Houston", "Test Corp", "Dallas", "TX"],
];

});

it("should render a table", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
assert.strictEqual(shallowWrapper.dive().dive().name(), "MUIDataTable");
assert.strictEqual(
shallowWrapper
.dive()
.dive()
.name(),
"MUIDataTable",
);
});


it("should correctly build internal columns data structure", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const actualResult = shallowWrapper.state().columns;
Expand All @@ -34,27 +38,25 @@ describe("<MUIDataTable />", function() {
{ display: true, name: "City", sort: "desc" },
{ display: true, name: "State", sort: "desc" },
];

assert.deepEqual(actualResult, expectedResult);
});


it("should correctly build internal table data and displayData structure", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const state = shallowWrapper.state();
assert.deepEqual(state.data, data);
assert.deepEqual(state.displayData, data);
assert.deepEqual(state.displayData, data);
});

it("should correctly build internal filterList structure", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const state = shallowWrapper.state();
const expectedResult = [[],[],[],[]];
const expectedResult = [[], [], [], []];

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


it("should correctly build internal unique column data for filterData structure", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const state = shallowWrapper.state();
Expand All @@ -65,63 +67,50 @@ describe("<MUIDataTable />", function() {
["NY", "CT", "FL", "TX"],
];

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


it("should correctly build internal rowsPerPage when provided in options", () => {

const options = {
rowsPerPage: 20
rowsPerPage: 20,
};

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
const state = shallowWrapper.state();
assert.strictEqual(state.rowsPerPage, 20);

});


it("should correctly build internal rowsPerPageOptions when provided in options", () => {

const options = {
rowsPerPageOptions: [5, 10, 15]
rowsPerPageOptions: [5, 10, 15],
};

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
const state = shallowWrapper.state();
assert.deepEqual(state.rowsPerPageOptions, [5, 10, 15]);

});


it("should render pagination when enabled in options", () => {

const options = {
pagination: true
pagination: true,
};

const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
const actualResult = mountWrapper.find(MUIDataTablePagination);
assert.lengthOf(actualResult, 1);

});

it("should not render pagination when disabled in options", () => {

const options = {
pagination: false
pagination: false,
};

const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
const actualResult = mountWrapper.find(MUIDataTablePagination);
assert.lengthOf(actualResult, 0);


});

it("should properly set internal filterList when calling filterUpdate method", () => {

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const table = shallowWrapper;
const instance = table.instance();
Expand All @@ -130,11 +119,9 @@ describe("<MUIDataTable />", function() {

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

});

it("should properly reset internal filterList when calling resetFilters method", () => {

// set a filter
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const table = shallowWrapper;
Expand All @@ -150,11 +137,9 @@ describe("<MUIDataTable />", function() {
table.update();
state = table.state();
assert.deepEqual(state.filterList, [[], [], [], []]);

});

it("should properly set searchText when calling searchTextUpdate method", () => {

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const table = shallowWrapper;
const instance = table.instance();
Expand All @@ -164,11 +149,9 @@ describe("<MUIDataTable />", function() {
const state = table.state();

assert.deepEqual(state.displayData, [["Joe James", "Test Corp", "Yonkers", "NY"]]);

});

it("should sort provided column when calling toggleSortColum method", () => {

it("should sort provided column when calling toggleSortColum method", () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const instance = shallowWrapper.instance();

Expand All @@ -184,11 +167,9 @@ describe("<MUIDataTable />", function() {
];

assert.deepEqual(state.displayData, expectedResult);

});

it("should toggle provided column when calling toggleViewCol method", () => {

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const instance = shallowWrapper.instance();

Expand All @@ -204,12 +185,9 @@ describe("<MUIDataTable />", function() {
];

assert.deepEqual(state.columns, expectedResult);


});

it("should get displayable data when calling getDisplayData method", () => {

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const instance = shallowWrapper.instance();
const state = shallowWrapper.state();
Expand All @@ -223,34 +201,27 @@ describe("<MUIDataTable />", function() {
];

assert.deepEqual(actualResult, expectedResult);

});

it("should update rowsPerPage when calling changeRowsPerPage method", () => {

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const instance = shallowWrapper.instance();

instance.changeRowsPerPage(10);
shallowWrapper.update();

const state = shallowWrapper.state();
assert.deepEqual(state.rowsPerPage, 10);

});

it("should update page position when calling changePage method", () => {

const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const instance = shallowWrapper.instance();

instance.changePage(2);
shallowWrapper.update();

const state = shallowWrapper.state();
assert.deepEqual(state.page, 2);

});


});
76 changes: 49 additions & 27 deletions test/MUIDataTableFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,81 +13,103 @@ describe("<MUIDataTableFilter />", function() {
let filterData;

before(() => {

columns = [
{ name: "First Name", display: true, sort: "desc" },
{ name: "Company", display: true, sort: "desc" },
{ name: "City", display: true, sort: "desc" },
{ name: "State", display: true, sort: "desc" },
];

data = [
["Joe James", "Test Corp", "Yonkers", "NY"],
["John Walsh", "Test Corp", "Hartford", "CT"],
["Bob Herm", "Test Corp", "Tampa", "FL"],
["James Houston", "Test Corp", "Dallas", "TX"],
];

filterData = [
["Joe James", "John Walsh", "Bob Herm", "James Houston"],
["Test Corp"],
["Yonkers", "Hartford", "Tampa", "Dallas"],
["NY", "CT", "FL", "TX"],
];

});

it("should data table filter view with checkboxes if filterType = 'checkbox'", () => {

const options = { filterType: "checkbox" };
const filterList = [ [], [], [], [] ];
const shallowWrapper = mount(<MUIDataTableFilter columns={columns} filterStyles={defaultFilterStyles} filterData={filterData} filterList={filterList} options={options} />);

const filterList = [[], [], [], []];
const shallowWrapper = mount(
<MUIDataTableFilter
columns={columns}
filterStyles={defaultFilterStyles}
filterData={filterData}
filterList={filterList}
options={options}
/>,
);

const actualResult = shallowWrapper.find(Checkbox);
assert.strictEqual(actualResult.length, 13);

});

it("should data table filter view with selects if filterType = 'select'", () => {

const options = { filterType: "select" };
const filterList = [ [], [], [], [] ];
const mountWrapper = mount(<MUIDataTableFilter columns={columns} filterStyles={defaultFilterStyles} filterData={filterData} filterList={filterList} options={options} />);

const filterList = [[], [], [], []];
const mountWrapper = mount(
<MUIDataTableFilter
columns={columns}
filterStyles={defaultFilterStyles}
filterData={filterData}
filterList={filterList}
options={options}
/>,
);

const actualResult = mountWrapper.find(Select);
assert.strictEqual(actualResult.length, 4);

});

it("should trigger onFilterUpdate prop callback when calling method handleCheckboxChange", () => {

const options = { filterType: "checkbox" };
const filterList = [ [], [], [], [] ];
const filterList = [[], [], [], []];
const onFilterUpdate = spy();

const shallowWrapper = shallow(<MUIDataTableFilter columns={columns} onFilterUpdate={onFilterUpdate} filterStyles={defaultFilterStyles} filterData={filterData} filterList={filterList} options={options} />);
const shallowWrapper = shallow(
<MUIDataTableFilter
columns={columns}
onFilterUpdate={onFilterUpdate}
filterStyles={defaultFilterStyles}
filterData={filterData}
filterList={filterList}
options={options}
/>,
);
const instance = shallowWrapper.instance();

//const event = { target: { value: 0 }};
instance.handleCheckboxChange(0, 0);
instance.handleCheckboxChange(0, 0);
assert.strictEqual(onFilterUpdate.callCount, 1);

});

it("should trigger onFilterUpdate prop callback when calling method handleDropdownChange", () => {

const options = { filterType: "select" };
const filterList = [ [], [], [], [] ];
const filterList = [[], [], [], []];
const onFilterUpdate = spy();

const shallowWrapper = shallow(<MUIDataTableFilter columns={columns} onFilterUpdate={onFilterUpdate} filterStyles={defaultFilterStyles} filterData={filterData} filterList={filterList} options={options} />);
const shallowWrapper = shallow(
<MUIDataTableFilter
columns={columns}
onFilterUpdate={onFilterUpdate}
filterStyles={defaultFilterStyles}
filterData={filterData}
filterList={filterList}
options={options}
/>,
);
const instance = shallowWrapper.instance();

const event = { target: { value: "All" }};
instance.handleDropdownChange(event, 0);
const event = { target: { value: "All" } };
instance.handleDropdownChange(event, 0);
assert.strictEqual(onFilterUpdate.callCount, 1);

});


});
Loading

0 comments on commit 7799301

Please sign in to comment.