Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
feat: Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wangkailang committed Jun 11, 2019
1 parent 73a3ad2 commit d3a2fc1
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 98 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js:
- stable

jobs:
include:
- stage: "Tests"
name: "Unit Tests"
script: yarn && yarn test

branches:
only:
- master
9 changes: 2 additions & 7 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
resolve: `gatsby-source-filesystem`,
options: {
name: `wizard-ui`,
path: Path.resolve(__dirname, `../src/lib`)
path: Path.resolve(__dirname, `../src/components`)
},
},
{
Expand All @@ -22,12 +22,7 @@ module.exports = {
},
},
`gatsby-mdx`,
{
resolve: "gatsby-plugin-ts-loader",
options: {
tslint: true // false or exclude to disable tslint
}
},
`gatsby-plugin-typescript`,
`gatsby-plugin-react-helmet`,
`gatsby-transformer-react-docgen`,
`gatsby-transformer-sharp`,
Expand Down
3 changes: 1 addition & 2 deletions docs/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
require('ts-node/register')
const path = require('path');
const { createFilePath } = require('gatsby-source-filesystem');

Expand All @@ -12,7 +11,7 @@ exports.onCreateWebpackConfig = ({ actions }) => {
resolve: {
modules: [path.resolve(__dirname, 'node_modules')],
alias: {
'wizard-ui': path.resolve(__dirname, '../src/index.tsx'),
'wizard-ui': path.resolve(__dirname, '../src/components'),
'icomoon-icon': path.resolve (__dirname, '../src/style/icomoon/selection.json')
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"gatsby-plugin-react-helmet": "^3.0.12",
"gatsby-plugin-sass": "^2.0.11",
"gatsby-plugin-sharp": "^2.0.37",
"gatsby-plugin-ts-loader": "^0.1.0",
"gatsby-plugin-typescript": "^2.0.15",
"gatsby-source-filesystem": "^2.0.38",
"gatsby-transformer-react-docgen": "^4.0.1",
"gatsby-transformer-sharp": "^2.1.19",
Expand Down
1 change: 1 addition & 0 deletions docs/src/components/Playground/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import * as bs from 'react-bootstrap';
// @ts-ignore
import * as libs from 'wizard-ui';
import examples from '../../examples';
import AllIcon from '../Icon';
Expand Down
113 changes: 36 additions & 77 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-typescript@^7.2.0":
version "7.3.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.3.3.tgz#a7cc3f66119a9f7ebe2de5383cce193473d65991"
integrity sha512-dGwbSMA1YhVS8+31CnPR7LB4pcbrzcV99wQzby4uAfrkZPYZlQ7ImwdpzLqi6Z6IL02b8IAL379CaMwo0x5Lag==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-arrow-functions@^7.0.0", "@babel/plugin-transform-arrow-functions@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.2.0.tgz#9aeafbe4d6ffc6563bf8f8372091628f00779550"
Expand Down Expand Up @@ -628,6 +635,14 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-typescript@^7.3.2":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.4.5.tgz#ab3351ba35307b79981993536c93ff8be050ba28"
integrity sha512-RPB/YeGr4ZrFKNwfuQRlMf2lxoCUaU01MTw39/OFE/RiL8HDjtn68BwEPft1P7JN4akyEmjGWAMNldOV7o9V2g==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-typescript" "^7.2.0"

"@babel/plugin-transform-unicode-regex@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.4.4.tgz#ab4634bb4f14d36728bf5978322b35587787970f"
Expand Down Expand Up @@ -710,6 +725,14 @@
"@babel/plugin-transform-react-jsx-self" "^7.0.0"
"@babel/plugin-transform-react-jsx-source" "^7.0.0"

"@babel/preset-typescript@^7.0.0":
version "7.3.3"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.3.3.tgz#88669911053fa16b2b276ea2ede2ca603b3f307a"
integrity sha512-mzMVuIP4lqtn4du2ynEfdO0+RYcslwrZiJHXu4MGaC1ctJiW2fyaeDrtjJGs7R/KebZ1sgowcIoWf4uRpEfKEg==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-transform-typescript" "^7.3.2"

"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.4.2":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12"
Expand Down Expand Up @@ -2124,11 +2147,6 @@ buffer@^5.2.1:
base64-js "^1.0.2"
ieee754 "^1.1.4"

builtin-modules@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
integrity sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=

builtin-modules@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484"
Expand Down Expand Up @@ -2334,7 +2352,7 @@ chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
Expand Down Expand Up @@ -2689,7 +2707,7 @@ command-exists@^1.2.2:
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==

commander@^2.11.0, commander@^2.12.1, commander@^2.18.0, commander@^2.19.0:
commander@^2.11.0, commander@^2.18.0, commander@^2.19.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
Expand Down Expand Up @@ -3602,11 +3620,6 @@ devcert-san@^0.3.3:
tmp "^0.0.31"
tslib "^1.6.0"

diff@^3.2.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==

diff@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
Expand Down Expand Up @@ -3923,7 +3936,7 @@ engine.io@~3.3.1:
engine.io-parser "~2.1.0"
ws "~6.1.0"

enhanced-resolve@^4.0.0, enhanced-resolve@^4.1.0:
enhanced-resolve@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz#41c7e0bfdfe74ac1ffe1e57ad6a5c6c9f3742a7f"
integrity sha512-F/7vkyTtyc/llOIn8oWclcB25KdRaiPBpZYDgJHgh/UHtpgT2p2eldQgtQnLtUvfMKPKxbRaQM/hHkvLHt1Vng==
Expand Down Expand Up @@ -5106,15 +5119,14 @@ gatsby-plugin-sharp@^2.0.37:
sharp "^0.22.1"
svgo "^1.2.0"

gatsby-plugin-ts-loader@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/gatsby-plugin-ts-loader/-/gatsby-plugin-ts-loader-0.1.0.tgz#248e960a2d6ee66a7d82879e36c3839811628420"
integrity sha512-tPUvov4mLPsfnuew+s5BTTGJyYxSRwKSyrfBz8hG9poKLJ5BwlRiQ3BFu53/0w/aw8u0I/ijKrkE4IN7kZ7fkg==
gatsby-plugin-typescript@^2.0.15:
version "2.0.15"
resolved "https://registry.yarnpkg.com/gatsby-plugin-typescript/-/gatsby-plugin-typescript-2.0.15.tgz#2c95e512287f8d4df02245152a94cf9601813e45"
integrity sha512-ZOKEjz+VhDLT1Q8w33JmR2NUDYiYgThab7jFZQvEd9zWA9x70BZlFL5kMy6mhHXIkD6dhPwYN1WM1yWWRzkOjw==
dependencies:
ts-loader "^5.3.2"
tslint "^5.12.0"
tslint-loader "^3.5.4"
typescript "^3.2.2"
"@babel/preset-typescript" "^7.0.0"
"@babel/runtime" "^7.0.0"
babel-plugin-remove-graphql-queries "^2.6.3"

gatsby-react-router-scroll@^2.0.7:
version "2.0.7"
Expand Down Expand Up @@ -10413,7 +10425,7 @@ rgba-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/rgba-regex/-/rgba-regex-1.0.0.tgz#43374e2e2ca0968b0ef1523460b7d730ff22eeb3"
integrity sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=

rimraf@2, rimraf@2.6.3, rimraf@^2.2.8, rimraf@^2.4.4, rimraf@^2.5.0, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3:
rimraf@2, rimraf@2.6.3, rimraf@^2.2.8, rimraf@^2.5.0, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3:
version "2.6.3"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
Expand Down Expand Up @@ -10592,7 +10604,7 @@ semver-truncate@^1.1.2:
dependencies:
semver "^5.3.0"

"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0:
"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0:
version "5.7.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b"
integrity sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==
Expand Down Expand Up @@ -11797,17 +11809,6 @@ trough@^1.0.0:
dependencies:
glob "^7.1.2"

ts-loader@^5.3.2:
version "5.4.5"
resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-5.4.5.tgz#a0c1f034b017a9344cef0961bfd97cc192492b8b"
integrity sha512-XYsjfnRQCBum9AMRZpk2rTYSVpdZBpZK+kDh0TeT3kxmQNBDVIeUjdPjY5RZry4eIAb8XHc4gYSUiUWPYvzSRw==
dependencies:
chalk "^2.3.0"
enhanced-resolve "^4.0.0"
loader-utils "^1.0.2"
micromatch "^3.1.4"
semver "^5.0.1"

ts-node@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.2.0.tgz#4a89754b00560bb24cd54526e1685fa38c45f240"
Expand All @@ -11824,48 +11825,11 @@ ts-pnp@^1.1.2:
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.2.tgz#be8e4bfce5d00f0f58e0666a82260c34a57af552"
integrity sha512-f5Knjh7XCyRIzoC/z1Su1yLLRrPrFCgtUAh/9fCSP6NKbATwpOL1+idQVXQokK9GRFURn/jYPGPfegIctwunoA==

tslib@^1.6.0, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
tslib@^1.6.0, tslib@^1.9.0:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==

tslint-loader@^3.5.4:
version "3.5.4"
resolved "https://registry.yarnpkg.com/tslint-loader/-/tslint-loader-3.5.4.tgz#052af7f0772434451ea1b247bb55407f878a4c40"
integrity sha512-jBHNNppXut6SgZ7CsTBh+6oMwVum9n8azbmcYSeMlsABhWWoHwjq631vIFXef3VSd75cCdX3rc6kstsB7rSVVw==
dependencies:
loader-utils "^1.0.2"
mkdirp "^0.5.1"
object-assign "^4.1.1"
rimraf "^2.4.4"
semver "^5.3.0"

tslint@^5.12.0:
version "5.17.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.17.0.tgz#f9f0ce2011d8e90debaa6e9b4975f24cd16852b8"
integrity sha512-pflx87WfVoYepTet3xLfDOLDm9Jqi61UXIKePOuca0qoAZyrGWonDG9VTbji58Fy+8gciUn8Bt7y69+KEVjc/w==
dependencies:
"@babel/code-frame" "^7.0.0"
builtin-modules "^1.1.1"
chalk "^2.3.0"
commander "^2.12.1"
diff "^3.2.0"
glob "^7.1.1"
js-yaml "^3.13.1"
minimatch "^3.0.4"
mkdirp "^0.5.1"
resolve "^1.3.2"
semver "^5.3.0"
tslib "^1.8.0"
tsutils "^2.29.0"

tsutils@^2.29.0:
version "2.29.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99"
integrity sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==
dependencies:
tslib "^1.8.1"

tty-browserify@0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"
Expand Down Expand Up @@ -11913,11 +11877,6 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.2.2:
version "3.5.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.1.tgz#ba72a6a600b2158139c5dd8850f700e231464202"
integrity sha512-64HkdiRv1yYZsSe4xC1WVgamNigVYjlssIoaH2HcZF0+ijsk5YK2g0G34w9wJkze8+5ow4STd22AynfO6ZYYLw==

ua-parser-js@^0.7.18:
version "0.7.19"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.19.tgz#94151be4c0a7fb1d001af7022fdaca4642659e4b"
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"main": "src/index.tsx",
"dependencies": {
"@types/jest": "24.0.13",
"@types/jest": "^24.0.13",
"@types/node": "12.0.2",
"@types/react": "16.8.18",
"@types/react-dom": "16.8.4",
Expand Down Expand Up @@ -40,11 +40,14 @@
"@storybook/addon-options": "^5.0.11",
"@storybook/react": "^5.0.11",
"@types/classnames": "^2.2.8",
"@types/enzyme": "^3.9.3",
"@types/react-bootstrap": "^0.32.17",
"babel-loader": "^8.0.6",
"classnames": "^2.2.6",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"node-sass": "^4.12.0",
"raw-loader": "^2.0.0",
"react-syntax-highlighter": "^7.0.4"
"react-syntax-highlighter": "^7.0.4",
"ts-jest": "^24.0.2"
}
}
31 changes: 31 additions & 0 deletions src/components/Badge/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import Badge from './index';
import { shallow } from 'enzyme';

describe('Badge', () => {
it('badge not showing count === 0', () => {
const badge = shallow(<Badge count={0} />);
expect(badge.find('.Badge').exists()).toEqual(false);
});
it('badge showing count === 0 with showZero', () => {
const badge = shallow(<Badge count={0} showZero />);
expect(badge.find('.Badge').length).toBe(1);
expect(badge.text()).toEqual('0');
});
it('default status danger', () => {
const badge = shallow(<Badge count="default" />);
expect(badge.find('.Badge--danger').exists()).toEqual(true);
});
it('number over 99 will be set to 99+', () => {
const badge = shallow(<Badge count={500} />);
expect(badge.text()).toEqual('99+');
});
it('overflowCount can be set', () => {
const badge = shallow(<Badge count={10000} overflowCount={999} />);
expect(badge.text()).toEqual('999+');
});
it('badge showing tip with children', () => {
const badge = shallow(<Badge count="2000">UI</Badge>);
expect(badge.find('.Badge__wrapper').exists()).toEqual(true);
});
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/index';
1 change: 0 additions & 1 deletion src/index.tsx

This file was deleted.

1 change: 1 addition & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
10 changes: 10 additions & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* https://github.com/xsky-fe/create-react-app-wizard/blob/master/packages/react-scripts/scripts/utils/createJestConfig.js#L28
* https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#testing-components
**/
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure ({
adapter: new Adapter (),
})
4 changes: 2 additions & 2 deletions stories/components/Badge/Default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Badge } from '../../../src/lib';
import BadgeCode from '!!raw-loader!../../../src/lib/Badge';
import { Badge } from '../../../src/components';
import BadgeCode from '!!raw-loader!../../../src/components/Badge';
import ComponentBody from '../../templates/ComponentBody/index';

const SIZES = ['small', 'middle', 'large'];
Expand Down
2 changes: 1 addition & 1 deletion stories/components/Badge/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Badge from '!!raw-loader!../../../src/lib/Badge';
import Badge from '!!raw-loader!../../../src/components/Badge';
import Default from './Default';
import DefaultCode from '!!raw-loader!./Default';

Expand Down
Loading

0 comments on commit d3a2fc1

Please sign in to comment.