Skip to content

Commit 3212b95

Browse files
authored
Tests (#4)
1 parent eac753d commit 3212b95

File tree

11 files changed

+365
-135
lines changed

11 files changed

+365
-135
lines changed

package.json

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,66 @@
11
{
2-
"name": "react-content-loader",
3-
"version": "1.2.0",
4-
"description": "This project is a collection the loader based on styles cards on Facebook, make with SVG and React.",
5-
"repository": {
6-
"type": "git",
7-
"url": "https://github.com/danilowoz/react-content-loader"
8-
},
9-
"author": "Danilo Woznica",
10-
"license": "MIT",
11-
"bugs": {
12-
"url": "https://github.com/danilowoz/react-content-loader/issues"
13-
},
14-
"homepage": "https://github.com/danilowoz/react-content-loader",
15-
"keywords": [
16-
"react",
17-
"facebook-style",
18-
"loader",
19-
"loading",
20-
"content",
21-
"svg"
22-
],
23-
"options": {
24-
"mocha": "--require scripts/mocha_runner src/**/__tests__/**/*.js"
25-
},
26-
"scripts": {
27-
"watch": "babel --plugins transform-es2015-modules-umd src --watch --ignore __tests__ --out-dir ./dist",
28-
"prepublish": "babel --plugins transform-es2015-modules-umd src --ignore __tests__ --out-dir ./dist",
29-
"lint": "eslint ./src",
30-
"lintfix": "eslint ./src --fix",
31-
"testonly": "mocha $npm_package_options_mocha",
32-
"test": "npm run lint && npm run testonly",
33-
"test-watch": "npm run testonly -- --watch --watch-extensions js"
34-
},
35-
"devDependencies": {
36-
"babel-cli": "^6.6.4",
37-
"babel-core": "^6.7.4",
38-
"babel-eslint": "^6.0.2",
39-
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
40-
"babel-polyfill": "^6.7.4",
41-
"babel-preset-es2015": "^6.6.0",
42-
"babel-preset-react": "^6.5.0",
43-
"babel-preset-stage-2": "^6.5.0",
44-
"chai": "^3.5.0",
45-
"enzyme": "^2.2.0",
46-
"eslint": "^2.7.0",
47-
"eslint-plugin-babel": "^3.1.0",
48-
"eslint-plugin-react": "^4.2.3",
49-
"jsdom": "^8.1.0",
50-
"mocha": "^2.4.5",
51-
"nodemon": "^1.9.1",
52-
"react-addons-test-utils": "^15.0.0",
53-
"react": "^15.0.0",
54-
"react-dom": "^15.0.0",
55-
"sinon": "^1.17.3"
56-
},
57-
"peerDependencies": {
58-
"react": "~0.14.8 || ^15.0.0",
59-
"react-dom": "~0.14.8 || ^15.0.0"
60-
},
61-
"dependencies": {
62-
"babel-runtime": "^6.6.1"
63-
}
2+
"name": "react-content-loader",
3+
"version": "1.2.0",
4+
"description": "This project is a collection the loader based on styles cards on Facebook, make with SVG and React.",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/danilowoz/react-content-loader"
8+
},
9+
"author": "Danilo Woznica",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/danilowoz/react-content-loader/issues"
13+
},
14+
"homepage": "https://github.com/danilowoz/react-content-loader",
15+
"keywords": [
16+
"react",
17+
"facebook-style",
18+
"loader",
19+
"loading",
20+
"content",
21+
"svg"
22+
],
23+
"options": {
24+
"mocha": "--require scripts/mocha_runner ./tests/**/*.js ./tests/*.js"
25+
},
26+
"scripts": {
27+
"watch": "babel --plugins transform-es2015-modules-umd src --watch --ignore tests --out-dir ./dist",
28+
"prepublish": "babel --plugins transform-es2015-modules-umd src --ignore tests --out-dir ./dist",
29+
"lint": "eslint ./src",
30+
"lintfix": "eslint ./src --fix",
31+
"testonly": "mocha $npm_package_options_mocha",
32+
"test": "npm run lint && npm run testonly",
33+
"test-watch": "npm run testonly -- --watch --watch-extensions js"
34+
},
35+
"devDependencies": {
36+
"babel-cli": "^6.6.4",
37+
"babel-core": "^6.7.4",
38+
"babel-eslint": "^6.0.2",
39+
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
40+
"babel-polyfill": "^6.7.4",
41+
"babel-preset-es2015": "^6.6.0",
42+
"babel-preset-react": "^6.5.0",
43+
"babel-preset-stage-2": "^6.5.0",
44+
"chai": "^3.5.0",
45+
"chai-enzyme": "^0.6.1",
46+
"enzyme": "^2.2.0",
47+
"eslint": "^2.7.0",
48+
"eslint-plugin-babel": "^3.1.0",
49+
"eslint-plugin-react": "^4.2.3",
50+
"jsdom": "^8.1.0",
51+
"mocha": "^2.4.5",
52+
"nodemon": "^1.9.1",
53+
"react": "^15.0.0",
54+
"react-addons-test-utils": "^15.0.0",
55+
"react-dom": "^15.0.0",
56+
"sinon": "^1.17.3",
57+
"uuid": "^3.0.1"
58+
},
59+
"peerDependencies": {
60+
"react": "~0.14.8 || ^15.0.0",
61+
"react-dom": "~0.14.8 || ^15.0.0"
62+
},
63+
"dependencies": {
64+
"babel-runtime": "^6.6.1"
65+
}
6466
}

src/Wrap.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import React from 'react'
2-
3-
const generateId = () => {
4-
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
5-
let text = ''
6-
7-
for (let i = 0; i < 10; i++)
8-
text += possible.charAt(Math.floor(Math.random() * possible.length))
9-
10-
return text
11-
}
2+
import uuid from 'uuid';
123

134
const Wrap = (props) => {
145

15-
let idClip = generateId()
16-
let idGradient = generateId()
6+
let idClip = uuid.v1()
7+
let idGradient = uuid.v1()
178

189
return (
1910
<svg viewBox={`0 0 400 ${props.height}`} version="1.1" style={props.style} preserveAspectRatio="xMidYMid meet">
@@ -41,4 +32,3 @@ const Wrap = (props) => {
4132
}
4233

4334
export default Wrap
44-
export { generateId }

src/__tests__/index.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ContentLoader extends Component {
3535
)
3636

3737
}
38+
3839
if (!this.props.children) {
3940

4041
switch (this.state.type.toLowerCase()) {

tests/Wrap.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
3+
import {shallow, mount, render} from 'enzyme'
4+
import {expect} from 'chai'
5+
import sinon from 'sinon'
6+
7+
import ContentLoader from '../src/index'
8+
import Wrap, { generateId } from '../src/Wrap'
9+
10+
describe('<Wrap /> Check id`s to render the SVG', () => {
11+
12+
it('is mask with the same `idClip`', () => {
13+
const wrapper = mount(<Wrap />)
14+
let idClip = wrapper.render().find('clipPath')[0].attribs.id
15+
expect(wrapper.render().find('rect[clip-path]')[0].attribs['clip-path']).to.have.equal(`url(#${idClip})`)
16+
})
17+
18+
it('is linearGradient with the same `idClip`', () => {
19+
const wrapper = mount(<Wrap />)
20+
let idGradient = wrapper.render().find('linearGradient')[0].attribs.id
21+
expect(wrapper.render().find('rect[clip-path]')[0].attribs['style']).to.have.equal(`fill: url(#${idGradient});`)
22+
})
23+
24+
})

tests/custom/Circle.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react'
2+
3+
import {shallow, mount, render} from 'enzyme'
4+
import chai, {expect} from 'chai'
5+
6+
import Circle from '../../src/custom/Circle'
7+
8+
describe('<Circle />', () => {
9+
let wrapper
10+
11+
beforeEach(() => {
12+
wrapper = shallow(<Circle />)
13+
})
14+
15+
it('has defaults props', () => {
16+
const props = wrapper.props()
17+
18+
for ( let key in props )
19+
expect(props[key]).to.not.equal(undefined)
20+
})
21+
})

tests/custom/Rect.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react'
2+
3+
import {shallow, mount, render} from 'enzyme'
4+
import chai, {expect} from 'chai'
5+
6+
import Rect from '../../src/custom/Rect'
7+
8+
describe('<Rect />', () => {
9+
let wrapper
10+
11+
beforeEach(() => {
12+
wrapper = shallow(<Rect />)
13+
})
14+
15+
it('has defaults props', () => {
16+
const props = wrapper.props()
17+
18+
for ( let key in props )
19+
expect(props[key]).to.not.equal(undefined)
20+
})
21+
})

0 commit comments

Comments
 (0)