Skip to content

Commit 01d0617

Browse files
committed
travel, action, and button containers tests
2 parents 502c975 + a9150aa commit 01d0617

28 files changed

+4695
-159
lines changed

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
node_modules
22
.DS_Store
3-
dist/
4-
extension/bundle.js
5-
package/react-time-travel-1.0.1.tgz
3+
src/extension/build/bundles
4+
package/react-time-travel-*.tgz
65
tictactoe
7-
tictactoe/build/bundle.js
8-
tictactoe/package-lock.json
96
parents
107
coverage

package-lock.json

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "webpack --mode production",
77
"dev": "webpack --mode development --watch",
8-
"test": "jest --verbose --coverage"
8+
"test": "jest --verbose --coverage --watchAll"
99
},
1010
"keywords": [
1111
"react",
@@ -38,6 +38,7 @@
3838
"eslint-plugin-jsx-a11y": "^6.2.3",
3939
"eslint-plugin-react": "^7.14.2",
4040
"jest": "^24.8.0",
41+
"jest-cli": "^24.8.0",
4142
"node-sass": "^4.12.0",
4243
"sass-loader": "^7.1.0",
4344
"style-loader": "^0.23.1",
@@ -47,6 +48,7 @@
4748
},
4849
"dependencies": {
4950
"auto-bind": "^2.1.0",
51+
"d3": "^3.5.17",
5052
"prop-types": "^15.7.2",
5153
"rc-slider": "^8.6.13",
5254
"rc-tooltip": "^3.7.3",

package/tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Tree {
44
// give it a special state = 'root'
55
// a setState function that just calls the callback instantly
66
if (!useStateInstead) {
7-
this.component = (component === 'root') ? { state: 'root', setState: (partial, callback) => callback() } : component;
7+
this.component = (component === 'root') ? { state: 'root', setState: (partial, callback) => callback() } : component;
88
} else {
99
this.state = component;
1010
this.name = name;

src/app/__tests__/action.test.jsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,51 @@ describe('unit testing for Action.jsx', () => {
1010
const props = {
1111
selected: true,
1212
handleChangeSnapshot: jest.fn(),
13-
handleSendSnapshot: jest.fn(),
13+
handleJumpSnapshot: jest.fn(),
1414
index: 1,
1515
};
1616
beforeEach(() => {
1717
wrapper = shallow(<Action {...props} />);
1818
});
1919

20-
describe('<Action> component', () => {
21-
it("<Action> should have a className 'action-component selected' if props.selected is true", () => {
20+
describe('Component', () => {
21+
test("should have a className 'action-component selected' if props.selected is true", () => {
2222
wrapper.setProps({ selected: true });
2323
expect(wrapper.hasClass('action-component selected')).toEqual(true);
2424
});
2525

26-
it("<Action> shouldn't have a className 'action-component selected' if props.selected is false", () => {
26+
test("shouldn't have a className 'action-component selected' if props.selected is false", () => {
2727
wrapper.setProps({ selected: false });
2828
expect(wrapper.hasClass('action-component selected')).toEqual(false);
2929
});
3030

31-
it('<Action> should have a text that is equal to props.index', () => {
31+
test('should have a text that is equal to props.index', () => {
3232
expect(wrapper.find('.action-component-text').text()).toEqual(props.index.toString());
3333
});
34+
35+
test('should invoke changeSnapshot method when clicked', () => {
36+
wrapper.find('.action-component').simulate('click');
37+
expect(props.handleChangeSnapshot).toHaveBeenCalled();
38+
});
3439
});
3540

36-
describe('jump button', () => {
37-
it('Should render a jump button', () => {
38-
expect(wrapper.type()).toEqual('div');
39-
expect(wrapper.find('button')).toHaveLength(1);
41+
describe('Jump Button', () => {
42+
test("should render a div with a className 'jump-button' inside action-component", () => {
43+
expect(
44+
wrapper
45+
.find('.action-component')
46+
.children()
47+
.find('.jump-button'),
48+
).toHaveLength(1);
4049
});
4150

42-
it('Should invoke the sendSnapshot method when the jump button is clicked', () => {
51+
test('should invoke jumpSnapshot method when clicked', () => {
4352
wrapper
44-
.find('button')
45-
.at(0)
53+
.find('.action-component')
54+
.children()
55+
.find('.jump-button')
4656
.simulate('click');
47-
expect(props.handleSendSnapshot).toHaveBeenCalled();
57+
expect(props.handleJumpSnapshot).toHaveBeenCalled();
4858
});
4959
});
5060
});

src/app/components/Action.jsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,37 @@ import PropTypes from 'prop-types';
33

44
const Action = (props) => {
55
const {
6-
selected, handleChangeSnapshot, handleJumpSnapshot, index,
6+
selected, handleChangeSnapshot, handleJumpSnapshot, index, sliderIndex,
77
} = props;
8+
89
return (
910
<div
1011
className={selected ? 'action-component selected' : 'action-component'}
1112
onClick={() => handleChangeSnapshot(index)}
1213
role="presentation"
14+
style={index > sliderIndex ? { color: '#5f6369' } : {}}
1315
>
1416
<div className="action-component-text">{index}</div>
15-
<div
17+
<button
1618
className="jump-button"
17-
onClick={() => handleJumpSnapshot(index)}
19+
onClick={(e) => {
20+
e.stopPropagation();
21+
handleJumpSnapshot(index);
22+
}}
1823
tabIndex={index}
19-
role="button"
24+
type="button"
2025
>
2126
Jump
22-
</div>
27+
</button>
2328
</div>
2429
);
2530
};
2631

27-
// Action.propTypes = {
28-
// selected: PropTypes.bool,
29-
// index: PropTypes.number,
30-
// };
32+
Action.propTypes = {
33+
selected: PropTypes.bool.isRequired,
34+
index: PropTypes.number.isRequired,
35+
handleChangeSnapshot: PropTypes.func.isRequired,
36+
handleJumpSnapshot: PropTypes.func.isRequired,
37+
};
3138

3239
export default Action;

src/app/components/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import MainContainer from '../containers/MainContainer';
33

44
const App = () => <MainContainer />;

0 commit comments

Comments
 (0)