From 4855303a5e1ed0d79b4c65c7757ce80ff95d4978 Mon Sep 17 00:00:00 2001 From: Jonathan Zobro Date: Sun, 1 Oct 2017 20:57:21 +0700 Subject: [PATCH 1/7] move Peers to component/Peers --- .../Peers/components/Peer => components/Peers}/Peer.js | 0 .../Peers/components/Peer => components/Peers}/Peer.scss | 2 +- .../components/PeerForm => components/Peers}/PeerForm.js | 0 .../components/PeerForm => components/Peers}/PeerForm.scss | 2 +- .../components/PeerModal => components/Peers}/PeerModal.js | 0 .../PeerModal => components/Peers}/PeerModal.scss | 2 +- .../wallet/components => }/components/Peers/Peers.js | 6 +++--- .../wallet/components => }/components/Peers/Peers.scss | 2 +- .../wallet/components => }/components/Peers/index.js | 0 app/routes/wallet/components/Wallet.js | 2 +- .../components/components/Peers/components/Peer/index.js | 3 --- .../components/Peers/components/PeerForm/index.js | 3 --- .../components/Peers/components/PeerModal/index.js | 3 --- 13 files changed, 8 insertions(+), 17 deletions(-) rename app/{routes/wallet/components/components/Peers/components/Peer => components/Peers}/Peer.js (100%) rename app/{routes/wallet/components/components/Peers/components/Peer => components/Peers}/Peer.scss (88%) rename app/{routes/wallet/components/components/Peers/components/PeerForm => components/Peers}/PeerForm.js (100%) rename app/{routes/wallet/components/components/Peers/components/PeerForm => components/Peers}/PeerForm.scss (95%) rename app/{routes/wallet/components/components/Peers/components/PeerModal => components/Peers}/PeerModal.js (100%) rename app/{routes/wallet/components/components/Peers/components/PeerModal => components/Peers}/PeerModal.scss (95%) rename app/{routes/wallet/components => }/components/Peers/Peers.js (91%) rename app/{routes/wallet/components => }/components/Peers/Peers.scss (93%) rename app/{routes/wallet/components => }/components/Peers/index.js (100%) delete mode 100644 app/routes/wallet/components/components/Peers/components/Peer/index.js delete mode 100644 app/routes/wallet/components/components/Peers/components/PeerForm/index.js delete mode 100644 app/routes/wallet/components/components/Peers/components/PeerModal/index.js diff --git a/app/routes/wallet/components/components/Peers/components/Peer/Peer.js b/app/components/Peers/Peer.js similarity index 100% rename from app/routes/wallet/components/components/Peers/components/Peer/Peer.js rename to app/components/Peers/Peer.js diff --git a/app/routes/wallet/components/components/Peers/components/Peer/Peer.scss b/app/components/Peers/Peer.scss similarity index 88% rename from app/routes/wallet/components/components/Peers/components/Peer/Peer.scss rename to app/components/Peers/Peer.scss index 33bec192..5e491fe1 100644 --- a/app/routes/wallet/components/components/Peers/components/Peer/Peer.scss +++ b/app/components/Peers/Peer.scss @@ -1,4 +1,4 @@ -@import '../../../../../../../variables.scss'; +@import '../../variables.scss'; .peer { position: relative; diff --git a/app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.js b/app/components/Peers/PeerForm.js similarity index 100% rename from app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.js rename to app/components/Peers/PeerForm.js diff --git a/app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.scss b/app/components/Peers/PeerForm.scss similarity index 95% rename from app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.scss rename to app/components/Peers/PeerForm.scss index b924df67..975b946b 100644 --- a/app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.scss +++ b/app/components/Peers/PeerForm.scss @@ -1,4 +1,4 @@ -@import '../../../../../../../variables.scss'; +@import '../../variables.scss'; .title { text-align: center; diff --git a/app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.js b/app/components/Peers/PeerModal.js similarity index 100% rename from app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.js rename to app/components/Peers/PeerModal.js diff --git a/app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.scss b/app/components/Peers/PeerModal.scss similarity index 95% rename from app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.scss rename to app/components/Peers/PeerModal.scss index 1421f729..e1d41492 100644 --- a/app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.scss +++ b/app/components/Peers/PeerModal.scss @@ -1,4 +1,4 @@ -@import '../../../../../../../variables.scss'; +@import '../../variables.scss'; .peer { padding: 40px; diff --git a/app/routes/wallet/components/components/Peers/Peers.js b/app/components/Peers/Peers.js similarity index 91% rename from app/routes/wallet/components/components/Peers/Peers.js rename to app/components/Peers/Peers.js index c21de324..5df2b11e 100644 --- a/app/routes/wallet/components/components/Peers/Peers.js +++ b/app/components/Peers/Peers.js @@ -1,9 +1,9 @@ import React from 'react' import PropTypes from 'prop-types' import { TiPlus } from 'react-icons/lib/ti' -import PeerModal from './components/PeerModal' -import PeerForm from './components/PeerForm' -import Peer from './components/Peer' +import PeerModal from './PeerModal' +import PeerForm from './PeerForm' +import Peer from './Peer' import styles from './Peers.scss' const Peers = ({ diff --git a/app/routes/wallet/components/components/Peers/Peers.scss b/app/components/Peers/Peers.scss similarity index 93% rename from app/routes/wallet/components/components/Peers/Peers.scss rename to app/components/Peers/Peers.scss index d153687c..f24f6f70 100644 --- a/app/routes/wallet/components/components/Peers/Peers.scss +++ b/app/components/Peers/Peers.scss @@ -1,4 +1,4 @@ -@import '../../../../../variables.scss'; +@import '../../variables.scss'; .peers { width: 75%; diff --git a/app/routes/wallet/components/components/Peers/index.js b/app/components/Peers/index.js similarity index 100% rename from app/routes/wallet/components/components/Peers/index.js rename to app/components/Peers/index.js diff --git a/app/routes/wallet/components/Wallet.js b/app/routes/wallet/components/Wallet.js index 6f5d6320..e21cbe02 100644 --- a/app/routes/wallet/components/Wallet.js +++ b/app/routes/wallet/components/Wallet.js @@ -2,7 +2,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import ReactSVG from 'react-svg' import Channels from 'components/Channels' -import Peers from './components/Peers' +import Peers from 'components/Peers' import styles from './Wallet.scss' class Wallet extends Component { diff --git a/app/routes/wallet/components/components/Peers/components/Peer/index.js b/app/routes/wallet/components/components/Peers/components/Peer/index.js deleted file mode 100644 index dddc3c4b..00000000 --- a/app/routes/wallet/components/components/Peers/components/Peer/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import Peer from './Peer' - -export default Peer diff --git a/app/routes/wallet/components/components/Peers/components/PeerForm/index.js b/app/routes/wallet/components/components/Peers/components/PeerForm/index.js deleted file mode 100644 index 3b3d5e23..00000000 --- a/app/routes/wallet/components/components/Peers/components/PeerForm/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import PeerForm from './PeerForm' - -export default PeerForm diff --git a/app/routes/wallet/components/components/Peers/components/PeerModal/index.js b/app/routes/wallet/components/components/Peers/components/PeerModal/index.js deleted file mode 100644 index dd05dd8e..00000000 --- a/app/routes/wallet/components/components/Peers/components/PeerModal/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import PeerModal from './PeerModal' - -export default PeerModal From 56497e4b5ae5675b589cb10f013423ee51890a78 Mon Sep 17 00:00:00 2001 From: Jonathan Zobro Date: Sun, 1 Oct 2017 22:15:01 +0700 Subject: [PATCH 2/7] add baseline tests to component/Peers, use 'app/node_modules' in eslintrc to import app specific node_modules --- .eslintrc | 2 +- test/components/Peers.spec.js | 76 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/components/Peers.spec.js diff --git a/.eslintrc b/.eslintrc index 3da1075f..c67c328e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -36,7 +36,7 @@ "settings": { "import/resolver": { "node": { - "paths": ["app"] + "paths": ["app", "app/node_modules"] }, "webpack": { "config": "webpack.config.eslint.js" diff --git a/test/components/Peers.spec.js b/test/components/Peers.spec.js new file mode 100644 index 00000000..20fdda04 --- /dev/null +++ b/test/components/Peers.spec.js @@ -0,0 +1,76 @@ +import React from 'react' +import { shallow } from 'enzyme' + +import { TiPlus } from 'react-icons/lib/ti' +import Peers from '../../app/components/Peers' +import PeerModal from '../../app/components/Peers/PeerModal' +import PeerForm from '../../app/components/Peers/PeerForm' +import Peer from '../../app/components/Peers/Peer' + +const defaultProps = { + peersLoading: false, + peers: [], + setPeer: () => {}, + peerModalOpen: false, + peerForm: {}, + setPeerForm: () => {}, + connect: () => {}, + isOpen: false, + resetPeer: () => {}, + disconnect: () => {}, + form: {}, + setForm: () => {} +} + +const peer = { + address: '45.77.115.33:9735', + bytes_recv: '63322', + bytes_sent: '68714', + inbound: true, + peer_id: 3, + ping_time: '261996', + pub_key: '0293cb97aac77eacjc5377d761640f1b51ebba350902801e1aa62853fa7bc3a1f30', + sat_recv: '0', + sat_sent: '0' +} + +describe('component.Peers', () => { + describe('default components', () => { + const props = { ...defaultProps } + const el = shallow() + it('should contain Modal and Form', () => { + expect(el.find(PeerModal)).toHaveLength(1) + expect(el.find(PeerForm)).toHaveLength(1) + }) + it('should have Peers header, and plus button', () => { + expect(el.contains('Peers')).toBe(true) + expect(el.find(TiPlus)).toHaveLength(1) + }) + }) + + describe('peers are loading', () => { + const props = { ...defaultProps, peersLoading: true } + const el = shallow() + it('should display loading msg', () => { + expect(el.contains('Loading...')).toBe(true) + }) + }) + + describe('peers are loaded', () => { + describe('no peers', () => { + const props = { ...defaultProps } + const el = shallow() + it('should show no peers', () => { + expect(el.find(Peer)).toHaveLength(0) + }) + }) + + describe('peer connected', () => { + const props = { ...defaultProps, peers: [peer] } + const el = shallow() + it('should show peer information', () => { + expect(el.find(Peer)).toHaveLength(1) + }) + }) + }) +}) From f9229805056e5634934cc35e77daca6ba4a48a0d Mon Sep 17 00:00:00 2001 From: Jonathan Zobro Date: Sun, 1 Oct 2017 22:29:45 +0700 Subject: [PATCH 3/7] update tests for Channel --- test/components/Channels.spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/components/Channels.spec.js b/test/components/Channels.spec.js index 3df31617..4d7c5d63 100644 --- a/test/components/Channels.spec.js +++ b/test/components/Channels.spec.js @@ -1,6 +1,7 @@ import React from 'react'; import { shallow } from 'enzyme' +import { TiPlus } from 'react-icons/lib/ti' import Channels from '../../app/components/Channels' import ChannelModal from '../../app/components/Channels/ChannelModal' import ChannelForm from '../../app/components/Channels/ChannelForm' @@ -72,6 +73,10 @@ describe('Channels', () => { expect(el.find(ChannelModal)).toHaveLength(1) expect(el.find(ChannelForm)).toHaveLength(1) }) + it('should have Channels header, and plus button', () => { + expect(el.contains('Channels')).toBe(true) + expect(el.find(TiPlus)).toHaveLength(1) + }) }) describe('channels are loading', () => { From c9cda7d37ee0b616c599952c9d75480127c70c95 Mon Sep 17 00:00:00 2001 From: Jonathan Zobro Date: Sun, 1 Oct 2017 22:58:46 +0700 Subject: [PATCH 4/7] test AnimatedCheckmark --- test/components/AnimatedCheckmark.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/components/AnimatedCheckmark.spec.js diff --git a/test/components/AnimatedCheckmark.spec.js b/test/components/AnimatedCheckmark.spec.js new file mode 100644 index 00000000..83e44057 --- /dev/null +++ b/test/components/AnimatedCheckmark.spec.js @@ -0,0 +1,14 @@ +import React from 'react' +import { shallow } from 'enzyme' +import Isvg from 'react-inlinesvg' + +import AnimatedCheckmark from '../../app/components/AnimatedCheckmark' + +describe('component.AnimatedCheckmark', () => { + describe('default', () => { + it('should render default component', () => { + const el = shallow() + expect(el.find(Isvg)).toHaveLength(1) + }) + }) +}) From 3475b74a17f47aa995f260379cf228744908a966 Mon Sep 17 00:00:00 2001 From: Jonathan Zobro Date: Sun, 1 Oct 2017 23:34:46 +0700 Subject: [PATCH 5/7] test CryptoIcon and add specific src test to AnimatedCheckmark --- test/components/AnimatedCheckmark.spec.js | 2 +- test/components/CryptoIcon.spec.js | 36 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/components/CryptoIcon.spec.js diff --git a/test/components/AnimatedCheckmark.spec.js b/test/components/AnimatedCheckmark.spec.js index 83e44057..5bc25efe 100644 --- a/test/components/AnimatedCheckmark.spec.js +++ b/test/components/AnimatedCheckmark.spec.js @@ -8,7 +8,7 @@ describe('component.AnimatedCheckmark', () => { describe('default', () => { it('should render default component', () => { const el = shallow() - expect(el.find(Isvg)).toHaveLength(1) + expect(el.find(Isvg).props().src).toContain('checkmark.svg') }) }) }) diff --git a/test/components/CryptoIcon.spec.js b/test/components/CryptoIcon.spec.js new file mode 100644 index 00000000..a61e53d0 --- /dev/null +++ b/test/components/CryptoIcon.spec.js @@ -0,0 +1,36 @@ +import React from 'react' +import { shallow } from 'enzyme' +import { FaBitcoin } from 'react-icons/lib/fa' +import Isvg from 'react-inlinesvg' +import CryptoIcon from '../../app/components/CryptoIcon' + +const defaultProps = { + currency: 'bch', + styles: {} +} + +describe('component.CryptoIcon', () => { + describe('currency is "unknown"', () => { + const props = { ...defaultProps } + const el = shallow() + it('should show empty span', () => { + expect(el.html()).toEqual('') + }) + }) + + describe('currency is "btc"', () => { + const props = { ...defaultProps, currency: 'btc' } + const el = shallow() + it('should show btc symbol', () => { + expect(el.find(FaBitcoin)).toHaveLength(1) + }) + }) + + describe('currency is "ltc"', () => { + const props = { ...defaultProps, currency: 'ltc' } + const el = shallow() + it('should show ltc symbol', () => { + expect(el.find(Isvg).props().src).toContain('litecoin.svg') + }) + }) +}) From fc29da6ed4db1eff7bfa09112b86a6624f3144a9 Mon Sep 17 00:00:00 2001 From: Jonathan Zobro Date: Sun, 1 Oct 2017 23:48:12 +0700 Subject: [PATCH 6/7] test CurrencyIcon component --- test/components/CurrencyIcon.spec.js | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/components/CurrencyIcon.spec.js diff --git a/test/components/CurrencyIcon.spec.js b/test/components/CurrencyIcon.spec.js new file mode 100644 index 00000000..dbee5b51 --- /dev/null +++ b/test/components/CurrencyIcon.spec.js @@ -0,0 +1,29 @@ +import React from 'react' +import { shallow } from 'enzyme' +import { FaDollar } from 'react-icons/lib/fa' +import CryptoIcon from '../../app/components/CryptoIcon' +import CurrencyIcon from '../../app/components/CurrencyIcon' + +const defaultProps = { + currency: '', + crypto: '', + styles: {} +} + +describe('component.CurrencyIcon', () => { + describe('currency is "usd"', () => { + const props = { ...defaultProps, currency: 'usd' } + const el = shallow() + it('should show usd symbo', () => { + expect(el.find(FaDollar)).toHaveLength(1) + }) + }) + + describe('currency is not "usd"', () => { + const props = { ...defaultProps, currency: 'btc' } + const el = shallow() + it('should show btc symbol', () => { + expect(el.find(CryptoIcon)).toHaveLength(1) + }) + }) +}) From 29d695bb49e982ea666e0c65ee2c25933067cd7b Mon Sep 17 00:00:00 2001 From: Jonathan Zobro Date: Sun, 1 Oct 2017 23:55:56 +0700 Subject: [PATCH 7/7] test LoadingBolt component --- test/components/CurrencyIcon.spec.js | 2 +- test/components/LoadingBolt.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/components/LoadingBolt.spec.js diff --git a/test/components/CurrencyIcon.spec.js b/test/components/CurrencyIcon.spec.js index dbee5b51..bf7ee136 100644 --- a/test/components/CurrencyIcon.spec.js +++ b/test/components/CurrencyIcon.spec.js @@ -14,7 +14,7 @@ describe('component.CurrencyIcon', () => { describe('currency is "usd"', () => { const props = { ...defaultProps, currency: 'usd' } const el = shallow() - it('should show usd symbo', () => { + it('should show usd symbol', () => { expect(el.find(FaDollar)).toHaveLength(1) }) }) diff --git a/test/components/LoadingBolt.spec.js b/test/components/LoadingBolt.spec.js new file mode 100644 index 00000000..e60cd5f4 --- /dev/null +++ b/test/components/LoadingBolt.spec.js @@ -0,0 +1,12 @@ +import React from 'react' +import { shallow } from 'enzyme' +import Isvg from 'react-inlinesvg' +import LoadingBolt from '../../app/components/LoadingBolt' + +describe('component.LoadingBolt', () => { + const el = shallow() + it('should show defaults', () => { + expect(el.find(Isvg).props().src).toContain('cloudbolt.svg') + expect(el.text()).toContain('loading') + }) +})