mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-03 23:07:26 +03:00
Created Home component tests
This commit is contained in:
parent
49f0109d20
commit
073703ef5b
4 changed files with 125 additions and 3 deletions
|
@ -6,7 +6,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node scripts/start.js",
|
"start": "node scripts/start.js",
|
||||||
"build": "node scripts/build.js",
|
"build": "node scripts/build.js",
|
||||||
"test": "node scripts/test.js --env=jsdom"
|
"test": "node scripts/test.js --env=jsdom --colors"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome": "^1.1.8",
|
"@fortawesome/fontawesome": "^1.1.8",
|
||||||
|
@ -70,6 +70,7 @@
|
||||||
"react-dev-utils": "^5.0.1",
|
"react-dev-utils": "^5.0.1",
|
||||||
"resolve": "1.6.0",
|
"resolve": "1.6.0",
|
||||||
"sass-loader": "^7.0.1",
|
"sass-loader": "^7.0.1",
|
||||||
|
"sinon": "^6.1.5",
|
||||||
"style-loader": "0.19.0",
|
"style-loader": "0.19.0",
|
||||||
"sw-precache-webpack-plugin": "0.11.4",
|
"sw-precache-webpack-plugin": "0.11.4",
|
||||||
"url-loader": "0.6.2",
|
"url-loader": "0.6.2",
|
||||||
|
|
|
@ -28,7 +28,12 @@ export class Home extends React.Component {
|
||||||
{hasServers && (
|
{hasServers && (
|
||||||
<ListGroup className="home__servers-list">
|
<ListGroup className="home__servers-list">
|
||||||
{servers.map(({ name, id }) => (
|
{servers.map(({ name, id }) => (
|
||||||
<ListGroupItem tag={Link} to={`/server/${id}/list-short-urls/1`} className="home__servers-item">
|
<ListGroupItem
|
||||||
|
key={id}
|
||||||
|
tag={Link}
|
||||||
|
to={`/server/${id}/list-short-urls/1`}
|
||||||
|
className="home__servers-item"
|
||||||
|
>
|
||||||
{name}
|
{name}
|
||||||
<FontAwesomeIcon icon={chevronIcon} className="home__servers-item-icon" />
|
<FontAwesomeIcon icon={chevronIcon} className="home__servers-item-icon" />
|
||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
|
|
52
test/home/Home.test.js
Normal file
52
test/home/Home.test.js
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import { shallow } from 'enzyme'
|
||||||
|
import { values } from 'ramda'
|
||||||
|
import React from 'react'
|
||||||
|
import * as sinon from 'sinon'
|
||||||
|
import { Home } from '../../src/common/Home'
|
||||||
|
|
||||||
|
describe('<Home />', () => {
|
||||||
|
let wrapped;
|
||||||
|
const defaultProps = {
|
||||||
|
resetSelectedServer: () => {},
|
||||||
|
servers: {},
|
||||||
|
};
|
||||||
|
const createComponent = props => {
|
||||||
|
const actualProps = { ...defaultProps, ...props };
|
||||||
|
wrapped = shallow(<Home {...actualProps} />);
|
||||||
|
return wrapped;
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
if (wrapped !== undefined) {
|
||||||
|
wrapped.unmount();
|
||||||
|
wrapped = undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resets selected server when mounted', () => {
|
||||||
|
const resetSelectedServer = sinon.spy();
|
||||||
|
|
||||||
|
expect(resetSelectedServer.called).toEqual(false);
|
||||||
|
createComponent({ resetSelectedServer });
|
||||||
|
expect(resetSelectedServer.called).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows link to create server when no servers exist', () => {
|
||||||
|
const wrapped = createComponent();
|
||||||
|
|
||||||
|
expect(wrapped.find('Link')).toHaveLength(1);
|
||||||
|
expect(wrapped.find('ListGroup')).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows servers list when list of servers is not empty', () => {
|
||||||
|
const servers = {
|
||||||
|
1: { name: 'foo', id: '123' },
|
||||||
|
2: { name: 'bar', id: '456' },
|
||||||
|
}
|
||||||
|
const wrapped = createComponent({ servers });
|
||||||
|
|
||||||
|
expect(wrapped.find('Link')).toHaveLength(0);
|
||||||
|
expect(wrapped.find('ListGroup')).toHaveLength(1);
|
||||||
|
expect(wrapped.find('ListGroupItem')).toHaveLength(values(servers).length);
|
||||||
|
});
|
||||||
|
});
|
66
yarn.lock
66
yarn.lock
|
@ -31,6 +31,22 @@
|
||||||
humps "^2.0.1"
|
humps "^2.0.1"
|
||||||
prop-types "^15.5.7"
|
prop-types "^15.5.7"
|
||||||
|
|
||||||
|
"@sinonjs/commons@^1.0.1":
|
||||||
|
version "1.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.0.2.tgz#3e0ac737781627b8844257fadc3d803997d0526e"
|
||||||
|
dependencies:
|
||||||
|
type-detect "4.0.8"
|
||||||
|
|
||||||
|
"@sinonjs/formatio@^2.0.0":
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-2.0.0.tgz#84db7e9eb5531df18a8c5e0bfb6e449e55e654b2"
|
||||||
|
dependencies:
|
||||||
|
samsam "1.3.0"
|
||||||
|
|
||||||
|
"@sinonjs/samsam@^2.0.0":
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-2.0.0.tgz#9163742ac35c12d3602dece74317643b35db6a80"
|
||||||
|
|
||||||
"@types/node@*":
|
"@types/node@*":
|
||||||
version "10.5.6"
|
version "10.5.6"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.6.tgz#1640f021dd0eaf12e731e54198c12ad2e020dc8e"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.6.tgz#1640f021dd0eaf12e731e54198c12ad2e020dc8e"
|
||||||
|
@ -2151,7 +2167,7 @@ detect-port-alt@1.1.6:
|
||||||
address "^1.0.1"
|
address "^1.0.1"
|
||||||
debug "^2.6.0"
|
debug "^2.6.0"
|
||||||
|
|
||||||
diff@^3.2.0:
|
diff@^3.2.0, diff@^3.5.0:
|
||||||
version "3.5.0"
|
version "3.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
|
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
|
||||||
|
|
||||||
|
@ -4451,6 +4467,10 @@ jsx-ast-utils@^2.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
array-includes "^3.0.3"
|
array-includes "^3.0.3"
|
||||||
|
|
||||||
|
just-extend@^1.1.27:
|
||||||
|
version "1.1.27"
|
||||||
|
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-1.1.27.tgz#ec6e79410ff914e472652abfa0e603c03d60e905"
|
||||||
|
|
||||||
killable@^1.0.0:
|
killable@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.0.tgz#da8b84bd47de5395878f95d64d02f2449fe05e6b"
|
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.0.tgz#da8b84bd47de5395878f95d64d02f2449fe05e6b"
|
||||||
|
@ -4598,6 +4618,10 @@ lodash.flattendeep@^4.4.0:
|
||||||
version "4.4.0"
|
version "4.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
|
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
|
||||||
|
|
||||||
|
lodash.get@^4.4.2:
|
||||||
|
version "4.4.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
|
||||||
|
|
||||||
lodash.isfunction@^3.0.9:
|
lodash.isfunction@^3.0.9:
|
||||||
version "3.0.9"
|
version "3.0.9"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051"
|
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051"
|
||||||
|
@ -4647,6 +4671,10 @@ loglevel@^1.4.1:
|
||||||
version "1.6.1"
|
version "1.6.1"
|
||||||
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.1.tgz#e0fc95133b6ef276cdc8887cdaf24aa6f156f8fa"
|
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.1.tgz#e0fc95133b6ef276cdc8887cdaf24aa6f156f8fa"
|
||||||
|
|
||||||
|
lolex@^2.3.2, lolex@^2.7.1:
|
||||||
|
version "2.7.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.1.tgz#e40a8c4d1f14b536aa03e42a537c7adbaf0c20be"
|
||||||
|
|
||||||
longest@^1.0.1:
|
longest@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
|
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
|
||||||
|
@ -4975,6 +5003,16 @@ next-tick@1:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
|
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
|
||||||
|
|
||||||
|
nise@^1.4.2:
|
||||||
|
version "1.4.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/nise/-/nise-1.4.2.tgz#a9a3800e3994994af9e452333d549d60f72b8e8c"
|
||||||
|
dependencies:
|
||||||
|
"@sinonjs/formatio" "^2.0.0"
|
||||||
|
just-extend "^1.1.27"
|
||||||
|
lolex "^2.3.2"
|
||||||
|
path-to-regexp "^1.7.0"
|
||||||
|
text-encoding "^0.6.4"
|
||||||
|
|
||||||
no-case@^2.2.0:
|
no-case@^2.2.0:
|
||||||
version "2.3.2"
|
version "2.3.2"
|
||||||
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac"
|
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac"
|
||||||
|
@ -6623,6 +6661,10 @@ safe-regex@^1.1.0:
|
||||||
version "2.1.2"
|
version "2.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
|
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
|
||||||
|
|
||||||
|
samsam@1.3.0:
|
||||||
|
version "1.3.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.3.0.tgz#8d1d9350e25622da30de3e44ba692b5221ab7c50"
|
||||||
|
|
||||||
sane@~1.6.0:
|
sane@~1.6.0:
|
||||||
version "1.6.0"
|
version "1.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/sane/-/sane-1.6.0.tgz#9610c452307a135d29c1fdfe2547034180c46775"
|
resolved "https://registry.yarnpkg.com/sane/-/sane-1.6.0.tgz#9610c452307a135d29c1fdfe2547034180c46775"
|
||||||
|
@ -6819,6 +6861,20 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
|
||||||
version "3.0.2"
|
version "3.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
|
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
|
||||||
|
|
||||||
|
sinon@^6.1.5:
|
||||||
|
version "6.1.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/sinon/-/sinon-6.1.5.tgz#41451502d43cd5ffb9d051fbf507952400e81d09"
|
||||||
|
dependencies:
|
||||||
|
"@sinonjs/commons" "^1.0.1"
|
||||||
|
"@sinonjs/formatio" "^2.0.0"
|
||||||
|
"@sinonjs/samsam" "^2.0.0"
|
||||||
|
diff "^3.5.0"
|
||||||
|
lodash.get "^4.4.2"
|
||||||
|
lolex "^2.7.1"
|
||||||
|
nise "^1.4.2"
|
||||||
|
supports-color "^5.4.0"
|
||||||
|
type-detect "^4.0.8"
|
||||||
|
|
||||||
slash@^1.0.0:
|
slash@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
|
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
|
||||||
|
@ -7237,6 +7293,10 @@ test-exclude@^4.2.1:
|
||||||
read-pkg-up "^1.0.1"
|
read-pkg-up "^1.0.1"
|
||||||
require-main-filename "^1.0.1"
|
require-main-filename "^1.0.1"
|
||||||
|
|
||||||
|
text-encoding@^0.6.4:
|
||||||
|
version "0.6.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
|
||||||
|
|
||||||
text-table@0.2.0, text-table@~0.2.0:
|
text-table@0.2.0, text-table@~0.2.0:
|
||||||
version "0.2.0"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
|
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
|
||||||
|
@ -7366,6 +7426,10 @@ type-check@~0.3.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
prelude-ls "~1.1.2"
|
prelude-ls "~1.1.2"
|
||||||
|
|
||||||
|
type-detect@4.0.8, type-detect@^4.0.8:
|
||||||
|
version "4.0.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
|
||||||
|
|
||||||
type-is@~1.6.15, type-is@~1.6.16:
|
type-is@~1.6.15, type-is@~1.6.16:
|
||||||
version "1.6.16"
|
version "1.6.16"
|
||||||
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194"
|
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194"
|
||||||
|
|
Loading…
Reference in a new issue