Skip to content

Commit 34fd8a6

Browse files
authored
Merge pull request #7 from EOS-uiux-Solutions/tests
[React Package] - Tests for generated React SVG components
2 parents b370cb4 + 6027336 commit 34fd8a6

File tree

8 files changed

+15439
-5048
lines changed

8 files changed

+15439
-5048
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ node_modules
77
es
88
lib
99
svg
10+
tests
11+
1012

1113
yarn.lock

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['@babel/preset-env', '@babel/preset-react']
3+
}

package-lock.json

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

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"build:es": "tsc --project tsconfig.build.json --module esnext --outDir es",
1313
"build:lib": "tsc --project tsconfig.build.json --module commonjs --outDir lib",
1414
"build": "npm run build:es && npm run build:lib",
15-
"generate": "npm run fetch && npm run icon && npm run build"
15+
"generate": "npm run fetch && npm run icon && npm run build",
16+
"test": "jest --env=jsdom",
17+
"test:update": "jest -u"
1618
},
1719
"repository": {
1820
"type": "git",
@@ -25,10 +27,16 @@
2527
},
2628
"homepage": "https://github.com/EOS-uiux-Solutions/eos-icons-react#readme",
2729
"devDependencies": {
30+
"@babel/preset-env": "^7.14.7",
31+
"@babel/preset-react": "^7.14.5",
32+
"@testing-library/jest-dom": "^5.14.1",
33+
"@testing-library/react": "^12.0.0",
2834
"@types/gulp": "^4.0.8",
35+
"@types/jest": "^26.0.23",
2936
"@types/react": "^17.0.11",
3037
"@typescript-eslint/eslint-plugin": "^4.28.0",
3138
"@typescript-eslint/parser": "^4.28.0",
39+
"babel-jest": "^27.0.5",
3240
"del": "^6.0.0",
3341
"eos-icons": "^5.1.0",
3442
"eslint": "^7.29.0",
@@ -37,6 +45,12 @@
3745
"eslint-plugin-node": "^11.1.0",
3846
"eslint-plugin-promise": "^5.1.0",
3947
"gulp": "^4.0.2",
48+
"jest": "^27.0.5",
49+
"jest-dom": "^4.0.0",
50+
"react": "^17.0.2",
51+
"react-dom": "^17.0.2",
52+
"react-test-renderer": "^17.0.2",
53+
"ts-jest": "^27.0.3",
4054
"ts-node": "^10.0.0",
4155
"typescript": "^4.3.2"
4256
},

scripts/iconScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function generateIconComponents ({ type, from }: IconGenerateScript) {
2626
}
2727

2828
// eslint-disable-next-line no-template-curly-in-string
29-
const propString = 'svg transform={`rotate(${rotate}) translate(${translateX}, ${translateY}) scale(${scaleX}, ${scaleY})`} fill={color} width={size} height={size}'
29+
const propString = 'svg data-testid="eos-svg-component" transform={`rotate(${rotate}) translate(${translateX}, ${translateY}) scale(${scaleX}, ${scaleY})`} fill={color} width={size} height={size}'
3030
data = data.replace('svg', propString)
3131

3232
const render = componentTemplate({ fileName, data })

test/animatedSvg.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint-disable no-undef */
2+
import React from 'react'
3+
// import renderer from 'react-test-renderer'
4+
import { EosloadingAnimated } from '../lib'
5+
import { render, cleanup } from '@testing-library/react'
6+
import '@testing-library/jest-dom/extend-expect'
7+
8+
afterEach(cleanup)
9+
10+
it('Animated SVG Size prop test', () => {
11+
const randomSize = Math.floor(Math.random()) + 1
12+
const { getByTestId } = render(
13+
<EosloadingAnimated size={`${randomSize}`}/>
14+
)
15+
expect(getByTestId('eos-svg-component')).toHaveStyle({
16+
width: `${randomSize}`,
17+
height: `${randomSize}`
18+
})
19+
})
20+
21+
it('Animated SVG Color prop test', () => {
22+
const { getByTestId } = render(
23+
<EosloadingAnimated color="blue"/>
24+
)
25+
expect(getByTestId('eos-svg-component')).toHaveAttribute('fill', 'blue')
26+
})
27+
28+
it('Animated SVG Rotation prop test', () => {
29+
const randomDegree = Math.floor(Math.random() * 360) + 1
30+
const { getByTestId } = render(
31+
<EosloadingAnimated rotate={`${randomDegree}`}/>
32+
)
33+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', `rotate(${randomDegree}) translate(0, 0) scale(1, 1)`)
34+
})
35+
36+
it('Animated SVG horizontalFlip prop test', () => {
37+
const { getByTestId } = render(
38+
<EosloadingAnimated horizontalFlip={true}/>
39+
)
40+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', 'rotate(0) translate(24, 0) scale(-1, 1)')
41+
})
42+
43+
it('Animated SVG verticalFlip prop test', () => {
44+
const { getByTestId } = render(
45+
<EosloadingAnimated verticalFlip={true}/>
46+
)
47+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', 'rotate(0) translate(0, 24) scale(1, -1)')
48+
})

test/filledsvg.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint-disable no-undef */
2+
import React from 'react'
3+
// import renderer from 'react-test-renderer'
4+
import { Eos10kFilled } from '../lib'
5+
import { render, cleanup } from '@testing-library/react'
6+
import '@testing-library/jest-dom/extend-expect'
7+
8+
afterEach(cleanup)
9+
10+
it('Filled SVG Size prop test', () => {
11+
const randomSize = Math.floor(Math.random()) + 1
12+
const { getByTestId } = render(
13+
<Eos10kFilled size={`${randomSize}`}/>
14+
)
15+
expect(getByTestId('eos-svg-component')).toHaveStyle({
16+
width: `${randomSize}`,
17+
height: `${randomSize}`
18+
})
19+
})
20+
21+
it('Filled SVG Color prop test', () => {
22+
const { getByTestId } = render(
23+
<Eos10kFilled color="blue"/>
24+
)
25+
expect(getByTestId('eos-svg-component')).toHaveAttribute('fill', 'blue')
26+
})
27+
28+
it('Filled SVG Rotation prop test', () => {
29+
const randomDegree = Math.floor(Math.random() * 360) + 1
30+
const { getByTestId } = render(
31+
<Eos10kFilled rotate={`${randomDegree}`}/>
32+
)
33+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', `rotate(${randomDegree}) translate(0, 0) scale(1, 1)`)
34+
})
35+
36+
it('Filled SVG horizontalFlip prop test', () => {
37+
const { getByTestId } = render(
38+
<Eos10kFilled horizontalFlip={true}/>
39+
)
40+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', 'rotate(0) translate(24, 0) scale(-1, 1)')
41+
})
42+
43+
it('Filled SVG verticalFlip prop test', () => {
44+
const { getByTestId } = render(
45+
<Eos10kFilled verticalFlip={true}/>
46+
)
47+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', 'rotate(0) translate(0, 24) scale(1, -1)')
48+
})

test/outlinedSvg.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint-disable no-undef */
2+
import React from 'react'
3+
// import renderer from 'react-test-renderer'
4+
import { Eos10kOutlined } from '../lib'
5+
import { render, cleanup } from '@testing-library/react'
6+
import '@testing-library/jest-dom/extend-expect'
7+
8+
afterEach(cleanup)
9+
10+
it('Outlined SVG Size prop test', () => {
11+
const randomSize = Math.floor(Math.random()) + 1
12+
const { getByTestId } = render(
13+
<Eos10kOutlined size={`${randomSize}`}/>
14+
)
15+
expect(getByTestId('eos-svg-component')).toHaveStyle({
16+
width: `${randomSize}`,
17+
height: `${randomSize}`
18+
})
19+
})
20+
21+
it('Outlined SVG Color prop test', () => {
22+
const { getByTestId } = render(
23+
<Eos10kOutlined color="blue"/>
24+
)
25+
expect(getByTestId('eos-svg-component')).toHaveAttribute('fill', 'blue')
26+
})
27+
28+
it('Outlined SVG Rotation prop test', () => {
29+
const randomDegree = Math.floor(Math.random() * 360) + 1
30+
const { getByTestId } = render(
31+
<Eos10kOutlined rotate={`${randomDegree}`}/>
32+
)
33+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', `rotate(${randomDegree}) translate(0, 0) scale(1, 1)`)
34+
})
35+
36+
it('Outlined SVG horizontalFlip prop test', () => {
37+
const { getByTestId } = render(
38+
<Eos10kOutlined horizontalFlip={true}/>
39+
)
40+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', 'rotate(0) translate(24, 0) scale(-1, 1)')
41+
})
42+
43+
it('Outlined SVG verticalFlip prop test', () => {
44+
const { getByTestId } = render(
45+
<Eos10kOutlined verticalFlip={true}/>
46+
)
47+
expect(getByTestId('eos-svg-component')).toHaveAttribute('transform', 'rotate(0) translate(0, 24) scale(1, -1)')
48+
})

0 commit comments

Comments
 (0)