Skip to content

Commit 26784b8

Browse files
authored
Merge pull request #51 from oslabs-beta/josh/app-test
app.jsx test and change text color based on sliderindex
2 parents d89359b + aed7aa1 commit 26784b8

File tree

11 files changed

+389
-224
lines changed

11 files changed

+389
-224
lines changed

package-lock.json

Lines changed: 132 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: 2 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",
@@ -37,6 +37,7 @@
3737
"eslint-plugin-jsx-a11y": "^6.2.3",
3838
"eslint-plugin-react": "^7.14.2",
3939
"jest": "^24.8.0",
40+
"jest-cli": "^24.8.0",
4041
"node-sass": "^4.12.0",
4142
"sass-loader": "^7.1.0",
4243
"style-loader": "^0.23.1",

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ 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>
1517
<button

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)