Skip to content

Commit

Permalink
Add test for RowDataChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
komarovalexander committed Dec 27, 2019
1 parent ffbaf67 commit 7c6895c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"repository": "github:komarovalexander/ka-table",
"homepage": "https://komarovalexander.github.io/ka-table/#/command-column",
"dependencies": {
"@types/enzyme": "^3.10.4",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/react": "16.9.16",
"@types/sinon": "^7.5.1",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
Expand Down Expand Up @@ -43,6 +46,8 @@
"@types/react-highlight": "^0.12.2",
"@types/react-router-dom": "^5.1.3",
"coveralls": "^3.0.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"gulp": "^4.0.2",
"gulp-file": "^0.4.0",
"gulp-gh-pages": "^0.5.4",
Expand All @@ -56,6 +61,7 @@
"react-highlight": "^0.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.0",
"sinon": "^8.0.1",
"tslint": "^5.20.0",
"tslint-react": "^4.1.0",
"typescript": "3.6.3"
Expand Down
23 changes: 21 additions & 2 deletions src/lib/Components/CellComponent/CellComponent.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import ReactDOM from 'react-dom';
import sinon from 'sinon';

import { DataType } from '../../enums';
import CellComponent, { ICellComponentProps } from './CellComponent';
import { DataType, Events } from '../../enums';
import CellEditor from '../CellEditor/CellEditor';
import CellComponent from './CellComponent';

Enzyme.configure({ adapter: new Adapter() });
const props: any = {
column: {
dataType: DataType.String,
Expand All @@ -24,3 +29,17 @@ it('renders without crashing', () => {
ReactDOM.render(<CellComponent {...props} />, element);
ReactDOM.unmountComponentAtNode(element);
});

it('call RowDataChanged when onValueChange', () => {
const dispatch = sinon.spy();
const newValue = {a: 1};
const wrapper = mount(
<CellComponent {...props} isEditableCell='true' dispatch={dispatch} />,
{
attachTo: document.createElement('tr'),
},
);
wrapper.find(CellEditor).last().prop('onValueChange')(newValue);
expect(dispatch.calledOnce).toBeTruthy();
expect(dispatch.args).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`call RowDataChanged when onValueChange 1`] = `
Array [
Array [
"RowDataChanged",
Object {
"newValue": Object {
"a": 1,
},
},
],
]
`;

0 comments on commit 7c6895c

Please sign in to comment.