Skip to content

Commit cfe8fe8

Browse files
committed
bullet test review
1 parent d44a97c commit cfe8fe8

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

configs/testConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ const Enzyme = require('enzyme');
22
const EnzymeAdapter = require('enzyme-adapter-react-16');
33

44
// Setup enzyme's react adapter
5-
Enzyme.configure({ adapter: new EnzymeAdapter() });
5+
Enzyme.configure({ adapter: new EnzymeAdapter() });

src/core/bullets.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,43 @@ export default class Bullets extends React.Component {
66
static propTypes = {
77
cssModule: PropTypes.object,
88
rootElement: PropTypes.string.isRequired,
9-
media: PropTypes.array.isRequired,
10-
onClick: PropTypes.func.isRequired,
9+
media: PropTypes.array,
10+
onClick: PropTypes.func,
1111
selected: PropTypes.number,
1212
};
1313

1414
static defaultProps = {
1515
cssModule: null,
1616
selected: 0,
17+
media: [],
18+
onClick: () => {},
1719
};
1820

1921
constructor(props) {
2022
super(props);
2123
this.rootElement = props.rootElement;
2224
}
2325

24-
bulletClick = (event) => {
26+
bulletClick = event => {
2527
const button = event.currentTarget;
26-
button.classList.add(getClassName(`${this.rootElement}__bullets--loading`, this.props.cssModule));
28+
button.classList.add(
29+
getClassName(
30+
`${this.rootElement}__bullets--loading`,
31+
this.props.cssModule
32+
)
33+
);
2734
const index = parseInt(button.getAttribute('data-index'), 10);
2835
const direction = !(this.props.selected > index);
2936
this.props.onClick({ index, direction });
30-
}
37+
};
3138

3239
renderBullets() {
33-
const {
34-
cssModule,
35-
selected,
36-
media = []
37-
} = this.props;
40+
const { cssModule, selected, media = [] } = this.props;
3841
return media.map((item, index) => {
39-
const className = index === selected ? getClassName(`${this.rootElement}__bullets--active`, cssModule) : null;
42+
const className =
43+
index === selected
44+
? getClassName(`${this.rootElement}__bullets--active`, cssModule)
45+
: null;
4046
return (
4147
<button
4248
key={`bullet-${index}`}
@@ -51,14 +57,9 @@ export default class Bullets extends React.Component {
5157
}
5258

5359
render() {
54-
const {
55-
cssModule,
56-
rootElement,
57-
} = this.props;
60+
const { cssModule, rootElement } = this.props;
5861
return (
59-
<nav
60-
className={getClassName(`${rootElement}__bullets`, cssModule)}
61-
>
62+
<nav className={getClassName(`${rootElement}__bullets`, cssModule)}>
6263
{this.renderBullets()}
6364
</nav>
6465
);

src/core/bullets.test.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
import React from 'react'
2-
import {shallow} from 'enzyme'
3-
import Bullets from './bullets'
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import Bullets from './bullets';
44

5-
6-
describe("Bullets Battery Tests", () => {
7-
8-
describe("Composition", () => {
9-
it("Should render empty bullets", () => {
10-
const wrapper = shallow(<Bullets rootElement=".foo"/>);
11-
expect(wrapper.find("button")).toHaveLength(0);
12-
expect(wrapper.find("nav").prop("className")).toEqual(".foo__bullets")
13-
})
14-
it("Should render bullets with for given media", () => {
15-
const media = [1,2,3,4,5]
16-
const wrapper = shallow(<Bullets onClick={jest.fn} media={media} rootElement=".foo"/>);
17-
const buttons = wrapper.find("button")
18-
expect(buttons).toHaveLength(5)
19-
expect(buttons.at(0).prop("className")).toEqual(".foo__bullets--active")
20-
expect(buttons.at(0).prop("data-index")).toEqual(0)
21-
expect(buttons.at(0).text()).toEqual("0")
22-
})
23-
})
24-
25-
26-
})
5+
describe('Bullets Battery Tests', () => {
6+
describe('Composition', () => {
7+
it('Should render empty bullets', () => {
8+
const wrapper = shallow(<Bullets rootElement=".foo" />);
9+
expect(wrapper.find('button')).toHaveLength(0);
10+
expect(wrapper.find('nav').prop('className')).toEqual('.foo__bullets');
11+
});
12+
it('Should render bullets with for given media', () => {
13+
const media = [1, 2, 3, 4, 5];
14+
const wrapper = shallow(
15+
<Bullets onClick={jest.fn} media={media} rootElement=".foo" />
16+
);
17+
const buttons = wrapper.find('button');
18+
expect(buttons).toHaveLength(5);
19+
expect(buttons.at(0).prop('className')).toEqual('.foo__bullets--active');
20+
expect(buttons.at(0).prop('data-index')).toEqual(0);
21+
expect(buttons.at(0).text()).toEqual('0');
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)