Browse Source

Merge pull request #961 from Gamaranto/atlas-tests

Add Tests
Bedeho Mender 4 years ago
parent
commit
5aceb165cf

+ 1 - 0
.eslintignore

@@ -1,3 +1,4 @@
 node_modules
 dist
 packages/**/dist
+.coverage

+ 1 - 1
.huskyrc

@@ -1,6 +1,6 @@
 {
     "hooks": {
         "pre-commit": "lint-staged",
-        "pre-push": "yarn test"
+        "pre-push": "yarn coverage"
     }
 }

+ 1 - 0
.prettierignore

@@ -2,3 +2,4 @@ node_modules/
 dist/
 .yarn/
 storybook-static/
+.coverage

+ 3 - 1
package.json

@@ -11,7 +11,8 @@
     "storybook": "lerna run --scope atlas-app --stream storybook",
     "lint": "yarn workspace atlas-app lint",
     "clean": "lerna clean && rm -rf node_modules",
-    "test": "yarn workspace atlas-app test"
+    "test": "yarn workspace atlas-app test",
+    "coverage": "yarn test --coverage"
   },
   "lint-staged": {
     "*.{ts,tsx,js,jsx,json}": [
@@ -22,6 +23,7 @@
     "@fortawesome/fontawesome-svg-core": "^1.2.28",
     "@fortawesome/free-solid-svg-icons": "^5.13.0",
     "@fortawesome/react-fontawesome": "^0.1.9",
+    "@types/enzyme": "^3.10.5",
     "@types/jest": "^24.0.0",
     "@types/node": "^12.0.0",
     "@typescript-eslint/eslint-plugin": "^3.5.0",

+ 7 - 0
packages/app/config-overrides.js

@@ -61,4 +61,11 @@ module.exports = {
     paths.appBuild = path.resolve(__dirname, '..', '..', 'dist')
     return paths
   },
+  jest: function (config) {
+    config.coverageDirectory = path.resolve(__dirname, '..', '..', '.coverage')
+    // Don't collect coverage from stories folder
+    config.collectCoverageFrom.push('!<rootDir>/src/**/stories/**/*.{js,jsx,ts,tsx}')
+
+    return config
+  },
 }

+ 0 - 0
packages/app/src/__tests__/LayoutWithRouting.test.js → packages/app/src/__tests__/LayoutWithRouting.test.tsx


+ 0 - 13
packages/app/src/shared/__tests__/Avatar.test.js

@@ -1,13 +0,0 @@
-import React from 'react'
-import { mount } from 'enzyme'
-import Avatar from '../components/Avatar'
-
-describe('Avatar component', () => {
-  const component = mount(
-    <Avatar img="https://s3.amazonaws.com/keybase_processed_uploads/9003a57620356bd89d62bd34c7c0c305_360_360.jpg" />
-  )
-
-  it('Should render correctly', () => {
-    expect(component).toMatchSnapshot()
-  })
-})

+ 8 - 0
packages/app/src/shared/__tests__/Avatar.test.tsx

@@ -0,0 +1,8 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import Avatar from '@/shared/components/Avatar'
+describe('Avatar component', () => {
+  it('Should render avatar correctly', () => {
+    expect(mount(<Avatar img="https://source.unsplash.com/WLUHO9A_xik/1600x900" />)).toBeDefined()
+  })
+})

+ 0 - 13
packages/app/src/shared/__tests__/Button.test.js

@@ -1,13 +0,0 @@
-import React from 'react'
-import { mount } from 'enzyme'
-import { Button } from '../components'
-
-describe('Button component', () => {
-  it('Should render default button correctly', () => {
-    expect(mount(<Button>Click me!</Button>)).toMatchSnapshot()
-  })
-
-  it('Should render custom button correctly', () => {
-    expect(mount(<Button size="large">Hello Atlas</Button>)).toMatchSnapshot()
-  })
-})

+ 13 - 0
packages/app/src/shared/__tests__/Button.test.tsx

@@ -0,0 +1,13 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import Button from '@/shared/components/Button'
+
+describe('Button component', () => {
+  it('Should render button correctly', () => {
+    expect(mount(<Button>Click me!</Button>)).toBeDefined()
+  })
+
+  it('Should render custom button correctly', () => {
+    expect(mount(<Button size="small">Hello Atlas</Button>)).toBeDefined()
+  })
+})

+ 16 - 0
packages/app/src/shared/__tests__/Carousel.test.tsx

@@ -0,0 +1,16 @@
+import React from 'react'
+import { shallow } from 'enzyme'
+import Carousel from '@/shared/components/Carousel'
+describe('Carousel component', () => {
+  it('Should render Carousel correctly', () => {
+    expect(
+      shallow(
+        <Carousel>
+          <div>Carousel child 1</div>
+          <div>Carousel child 1</div>
+          <div>Carousel child 1</div>
+        </Carousel>
+      )
+    ).toBeDefined()
+  })
+})

+ 9 - 0
packages/app/src/shared/__tests__/Checkbox.test.tsx

@@ -0,0 +1,9 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import Checkbox from '@/shared/components/Checkbox'
+
+describe('Checkbox component', () => {
+  it('Should render checkbox correctly', () => {
+    expect(mount(<Checkbox label="Test checkbox" icon="check" error />)).toBeDefined()
+  })
+})

+ 8 - 0
packages/app/src/shared/__tests__/Gallery.test.tsx

@@ -0,0 +1,8 @@
+import React from 'react'
+import { shallow } from 'enzyme'
+import Gallery from '@/shared/components/Gallery'
+describe('Gallery component', () => {
+  it('Should render Gallery correctly', () => {
+    expect(shallow(<Gallery title="Test gallery" />)).toBeDefined()
+  })
+})

+ 16 - 0
packages/app/src/shared/__tests__/Grid.test.tsx

@@ -0,0 +1,16 @@
+import React from 'react'
+import { shallow } from 'enzyme'
+import Grid from '@/shared/components/Grid'
+describe('Grid component', () => {
+  it('Should render Grid correctly', () => {
+    expect(
+      shallow(
+        <Grid>
+          <div>Grid Elemen 1</div>
+          <div>Grid Elemen 2</div>
+          <div>Grid Elemen 3</div>
+        </Grid>
+      )
+    ).toBeDefined()
+  })
+})

+ 17 - 0
packages/app/src/shared/__tests__/HamburgerButton.test.tsx

@@ -0,0 +1,17 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import HamburgerButton from '@/shared/components/HamburgerButton'
+describe('HamburgerButton component', () => {
+  it('Should render Hamburger correctly', () => {
+    expect(
+      mount(
+        <HamburgerButton
+          active
+          onClick={() => {
+            console.log('HamburgerButton Clicked')
+          }}
+        />
+      )
+    ).toBeDefined()
+  })
+})

+ 8 - 0
packages/app/src/shared/__tests__/NavButton.test.tsx

@@ -0,0 +1,8 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import NavButton from '@/shared/components/NavButton'
+describe('NavButton component', () => {
+  it('Should render NavButton correctly', () => {
+    expect(mount(<NavButton />)).toBeDefined()
+  })
+})

+ 8 - 0
packages/app/src/shared/__tests__/RadioButton.test.tsx

@@ -0,0 +1,8 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import RadioButton from '@/shared/components/RadioButton'
+describe('RadioButton component', () => {
+  it('Should render radio button correctly', () => {
+    expect(mount(<RadioButton label="test Radio Button" />)).toBeDefined()
+  })
+})

+ 8 - 0
packages/app/src/shared/__tests__/TextField.test.tsx

@@ -0,0 +1,8 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import TextField from '@/shared/components/TextField'
+describe('TextField component', () => {
+  it('Should render Text Field correctly', () => {
+    expect(mount(<TextField label="Test TextField" />)).toBeDefined()
+  })
+})

+ 8 - 0
packages/app/src/shared/__tests__/VideoPlayer.test.tsx

@@ -0,0 +1,8 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import VideoPlayer from '@/shared/components/VideoPlayer'
+describe('VideoPlayer component', () => {
+  it('Should render Video Player correctly', () => {
+    expect(mount(<VideoPlayer src="" />)).toBeDefined()
+  })
+})

+ 18 - 0
packages/app/src/shared/__tests__/VideoPreview.test.tsx

@@ -0,0 +1,18 @@
+import React from 'react'
+import { mount } from 'enzyme'
+import { VideoPreview } from '@/shared/components/VideoPreview'
+describe('VideoPreview component', () => {
+  it('Should render Video Preview correctly', () => {
+    expect(
+      mount(
+        <VideoPreview
+          title="Some Video Title"
+          channelName="some channel"
+          posterURL=""
+          views={1000}
+          createdAt={new Date()}
+        />
+      )
+    ).toBeDefined()
+  })
+})

+ 0 - 3
packages/app/src/shared/__tests__/__snapshots__/Avatar.test.js.snap

@@ -1,3 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Avatar component Should render correctly 1`] = `ReactWrapper {}`;

+ 0 - 5
packages/app/src/shared/__tests__/__snapshots__/Button.test.js.snap

@@ -1,5 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Button component Should render custom button correctly 1`] = `ReactWrapper {}`;
-
-exports[`Button component Should render default button correctly 1`] = `ReactWrapper {}`;

+ 15 - 0
yarn.lock

@@ -3653,11 +3653,26 @@
   dependencies:
     "@types/babel-types" "*"
 
+"@types/cheerio@*":
+  version "0.22.21"
+  resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.21.tgz#5e37887de309ba11b2e19a6e14cad7874b31a8a3"
+  integrity sha512-aGI3DfswwqgKPiEOTaiHV2ZPC9KEhprpgEbJnv0fZl3SGX0cGgEva1126dGrMC6AJM6v/aihlUgJn9M5DbDZ/Q==
+  dependencies:
+    "@types/node" "*"
+
 "@types/color-name@^1.1.1":
   version "1.1.1"
   resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
   integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
 
+"@types/enzyme@^3.10.5":
+  version "3.10.5"
+  resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.5.tgz#fe7eeba3550369eed20e7fb565bfb74eec44f1f0"
+  integrity sha512-R+phe509UuUYy9Tk0YlSbipRpfVtIzb/9BHn5pTEtjJTF5LXvUjrIQcZvNyANNEyFrd2YGs196PniNT1fgvOQA==
+  dependencies:
+    "@types/cheerio" "*"
+    "@types/react" "*"
+
 "@types/eslint-visitor-keys@^1.0.0":
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"