From 756c6a2d6c30e4c45a2df05af2a5c735bf207910 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 15 Aug 2017 21:18:18 -0500 Subject: [PATCH] feature(peers/ticker): add basic tests for reducers --- .../reducers/__snapshots__/peers.spec.js.snap | 155 ++++++++++++++++++ .../__snapshots__/ticker.spec.js.snap | 37 +++++ test/reducers/peers.spec.js | 42 ++++- test/reducers/ticker.spec.js | 37 +++++ 4 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 test/reducers/__snapshots__/ticker.spec.js.snap create mode 100644 test/reducers/ticker.spec.js diff --git a/test/reducers/__snapshots__/peers.spec.js.snap b/test/reducers/__snapshots__/peers.spec.js.snap index 2ce6879a..b2bea94c 100644 --- a/test/reducers/__snapshots__/peers.spec.js.snap +++ b/test/reducers/__snapshots__/peers.spec.js.snap @@ -1,5 +1,160 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`reducers peersReducer should correctly connectFailure 1`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly connectFailure 2`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": "foo", + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly connectPeer 1`] = ` +Object { + "connecting": true, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly connectSuccess 1`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [ + "foo", + ], + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly disconnectFailure 1`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly disconnectPeer 1`] = ` +Object { + "connecting": false, + "disconnecting": true, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly disconnectSuccess 1`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly getPeers 1`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": true, +} +`; + +exports[`reducers peersReducer should correctly setPeer 1`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": "foo", + "peerForm": Object { + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": false, +} +`; + +exports[`reducers peersReducer should correctly setPeerForm 1`] = ` +Object { + "connecting": false, + "disconnecting": false, + "peer": null, + "peerForm": Object { + "0": "f", + "1": "o", + "2": "o", + "host": "", + "isOpen": false, + "pubkey": "", + }, + "peers": Array [], + "peersLoading": false, +} +`; + exports[`reducers peersReducer should handle initial state 1`] = ` Object { "connecting": false, diff --git a/test/reducers/__snapshots__/ticker.spec.js.snap b/test/reducers/__snapshots__/ticker.spec.js.snap new file mode 100644 index 00000000..c5123d6e --- /dev/null +++ b/test/reducers/__snapshots__/ticker.spec.js.snap @@ -0,0 +1,37 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`reducers tickerReducer should correctly getTicker 1`] = ` +Object { + "btcTicker": null, + "crypto": "btc", + "currency": "btc", + "tickerLoading": true, +} +`; + +exports[`reducers tickerReducer should correctly receiveTicker 1`] = ` +Object { + "btcTicker": "f", + "crypto": "btc", + "currency": "btc", + "tickerLoading": false, +} +`; + +exports[`reducers tickerReducer should correctly setCurrency 1`] = ` +Object { + "btcTicker": null, + "crypto": "btc", + "currency": "foo", + "tickerLoading": false, +} +`; + +exports[`reducers tickerReducer should handle initial state 1`] = ` +Object { + "btcTicker": null, + "crypto": "btc", + "currency": "btc", + "tickerLoading": false, +} +`; diff --git a/test/reducers/peers.spec.js b/test/reducers/peers.spec.js index d21d7eb5..7cdb55b4 100644 --- a/test/reducers/peers.spec.js +++ b/test/reducers/peers.spec.js @@ -57,8 +57,44 @@ describe('reducers', () => { expect(RECEIVE_PEERS).toEqual('RECEIVE_PEERS') }) - // it('should correctly sendPayment', () => { - // expect(peersReducer(undefined, { type: SET_PAYMENT, payment: 'foo' })).toMatchSnapshot() - // }) + it('should correctly disconnectPeer', () => { + expect(peersReducer(undefined, { type: DISCONNECT_PEER })).toMatchSnapshot() + }) + + it('should correctly disconnectSuccess', () => { + expect(peersReducer(undefined, { type: DISCONNECT_SUCCESS, pubkey: 'foo' })).toMatchSnapshot() + }) + + it('should correctly disconnectFailure', () => { + expect(peersReducer(undefined, { type: DISCONNECT_FAILURE })).toMatchSnapshot() + }) + + it('should correctly connectPeer', () => { + expect(peersReducer(undefined, { type: CONNECT_PEER })).toMatchSnapshot() + }) + + it('should correctly connectSuccess', () => { + expect(peersReducer(undefined, { type: CONNECT_SUCCESS, peer: 'foo' })).toMatchSnapshot() + }) + + it('should correctly connectFailure', () => { + expect(peersReducer(undefined, { type: CONNECT_FAILURE })).toMatchSnapshot() + }) + + it('should correctly setPeerForm', () => { + expect(peersReducer(undefined, { type: SET_PEER_FORM, form: 'foo' })).toMatchSnapshot() + }) + + it('should correctly setPeer', () => { + expect(peersReducer(undefined, { type: SET_PEER, peer: 'foo' })).toMatchSnapshot() + }) + + it('should correctly getPeers', () => { + expect(peersReducer(undefined, { type: GET_PEERS })).toMatchSnapshot() + }) + + it('should correctly connectFailure', () => { + expect(peersReducer(undefined, { type: RECEIVE_PEERS, peers: 'foo' })).toMatchSnapshot() + }) }) }) diff --git a/test/reducers/ticker.spec.js b/test/reducers/ticker.spec.js new file mode 100644 index 00000000..113e8c4a --- /dev/null +++ b/test/reducers/ticker.spec.js @@ -0,0 +1,37 @@ +import tickerReducer, { + SET_CURRENCY, + GET_TICKER, + RECIEVE_TICKER +} from '../../app/reducers/ticker' + +describe('reducers', () => { + describe('tickerReducer', () => { + it('should handle initial state', () => { + expect(tickerReducer(undefined, {})).toMatchSnapshot() + }) + + it('should have SET_CURRENCY', () => { + expect(SET_CURRENCY).toEqual('SET_CURRENCY') + }) + + it('should have GET_TICKER', () => { + expect(GET_TICKER).toEqual('GET_TICKER') + }) + + it('should have RECIEVE_TICKER', () => { + expect(RECIEVE_TICKER).toEqual('RECIEVE_TICKER') + }) + + it('should correctly setCurrency', () => { + expect(tickerReducer(undefined, { type: SET_CURRENCY, currency: 'foo' })).toMatchSnapshot() + }) + + it('should correctly getTicker', () => { + expect(tickerReducer(undefined, { type: GET_TICKER })).toMatchSnapshot() + }) + + it('should correctly receiveTicker', () => { + expect(tickerReducer(undefined, { type: RECIEVE_TICKER, ticker: 'foo' })).toMatchSnapshot() + }) + }) +})