From b3044b26a7ba493954589a0bb45b2d5953171e99 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Tue, 21 Aug 2018 13:50:30 +0200 Subject: [PATCH] test(reducers): add transaction reducer tests --- .../__snapshots__/transaction.spec.js.snap | 123 ++++++++++++++++++ test/unit/reducers/transaction.spec.js | 90 +++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 test/unit/reducers/__snapshots__/transaction.spec.js.snap create mode 100644 test/unit/reducers/transaction.spec.js diff --git a/test/unit/reducers/__snapshots__/transaction.spec.js.snap b/test/unit/reducers/__snapshots__/transaction.spec.js.snap new file mode 100644 index 00000000..62ef8c2d --- /dev/null +++ b/test/unit/reducers/__snapshots__/transaction.spec.js.snap @@ -0,0 +1,123 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`reducers transactionReducer should correctly addTransaction 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": Array [ + undefined, + ], +} +`; + +exports[`reducers transactionReducer should correctly getTransactions 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": true, + "transactions": Array [], +} +`; + +exports[`reducers transactionReducer should correctly hideSuccessTransactionScreen 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": Array [], +} +`; + +exports[`reducers transactionReducer should correctly receiveTransactions 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": undefined, +} +`; + +exports[`reducers transactionReducer should correctly sendTransaction 1`] = ` +Object { + "sendingTransaction": true, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": Array [], +} +`; + +exports[`reducers transactionReducer should correctly sendTransactions 1`] = ` +Object { + "sendingTransaction": true, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": Array [], +} +`; + +exports[`reducers transactionReducer should correctly showSuccessTransactionScreen 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": true, + "txid": undefined, + }, + "transactionLoading": false, + "transactions": Array [], +} +`; + +exports[`reducers transactionReducer should correctly transactionFailed 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": Array [], +} +`; + +exports[`reducers transactionReducer should correctly transactionSuccessful 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": Array [], +} +`; + +exports[`reducers transactionReducer should handle initial state 1`] = ` +Object { + "sendingTransaction": false, + "successTransactionScreen": Object { + "show": false, + "txid": "", + }, + "transactionLoading": false, + "transactions": Array [], +} +`; diff --git a/test/unit/reducers/transaction.spec.js b/test/unit/reducers/transaction.spec.js new file mode 100644 index 00000000..530b5bc8 --- /dev/null +++ b/test/unit/reducers/transaction.spec.js @@ -0,0 +1,90 @@ +import transactionReducer, { + GET_TRANSACTIONS, + RECEIVE_TRANSACTIONS, + SEND_TRANSACTION, + TRANSACTION_SUCCESSFULL, + TRANSACTION_FAILED, + ADD_TRANSACTION, + SHOW_SUCCESS_TRANSACTION_SCREEN, + HIDE_SUCCESS_TRANSACTION_SCREEN +} from 'reducers/transaction' + +describe('reducers', () => { + describe('transactionReducer', () => { + it('should handle initial state', () => { + expect(transactionReducer(undefined, {})).toMatchSnapshot() + }) + + it('should have GET_TRANSACTIONS', () => { + expect(GET_TRANSACTIONS).toEqual('GET_TRANSACTIONS') + }) + + it('should have RECEIVE_TRANSACTIONS', () => { + expect(RECEIVE_TRANSACTIONS).toEqual('RECEIVE_TRANSACTIONS') + }) + + it('should have GET_TICKER', () => { + expect(SEND_TRANSACTION).toEqual('SEND_TRANSACTION') + }) + + it('should have TRANSACTION_SUCCESSFULL', () => { + expect(TRANSACTION_SUCCESSFULL).toEqual('TRANSACTION_SUCCESSFULL') + }) + + it('should have TRANSACTION_FAILED', () => { + expect(TRANSACTION_FAILED).toEqual('TRANSACTION_FAILED') + }) + + it('should have ADD_TRANSACTION', () => { + expect(ADD_TRANSACTION).toEqual('ADD_TRANSACTION') + }) + + it('should have SHOW_SUCCESS_TRANSACTION_SCREEN', () => { + expect(SHOW_SUCCESS_TRANSACTION_SCREEN).toEqual('SHOW_SUCCESS_TRANSACTION_SCREEN') + }) + + it('should have HIDE_SUCCESS_TRANSACTION_SCREEN', () => { + expect(HIDE_SUCCESS_TRANSACTION_SCREEN).toEqual('HIDE_SUCCESS_TRANSACTION_SCREEN') + }) + + it('should correctly getTransactions', () => { + expect(transactionReducer(undefined, { type: GET_TRANSACTIONS })).toMatchSnapshot() + }) + + it('should correctly sendTransactions', () => { + expect(transactionReducer(undefined, { type: SEND_TRANSACTION })).toMatchSnapshot() + }) + + it('should correctly receiveTransactions', () => { + expect(transactionReducer(undefined, { type: RECEIVE_TRANSACTIONS })).toMatchSnapshot() + }) + + it('should correctly sendTransaction', () => { + expect(transactionReducer(undefined, { type: SEND_TRANSACTION })).toMatchSnapshot() + }) + + it('should correctly transactionSuccessful', () => { + expect(transactionReducer(undefined, { type: TRANSACTION_SUCCESSFULL })).toMatchSnapshot() + }) + + it('should correctly transactionFailed', () => { + expect(transactionReducer(undefined, { type: TRANSACTION_FAILED })).toMatchSnapshot() + }) + + it('should correctly addTransaction', () => { + expect(transactionReducer(undefined, { type: ADD_TRANSACTION })).toMatchSnapshot() + }) + + it('should correctly showSuccessTransactionScreen', () => { + expect( + transactionReducer(undefined, { type: SHOW_SUCCESS_TRANSACTION_SCREEN }) + ).toMatchSnapshot() + }) + + it('should correctly hideSuccessTransactionScreen', () => { + expect( + transactionReducer(undefined, { type: HIDE_SUCCESS_TRANSACTION_SCREEN }) + ).toMatchSnapshot() + }) + }) +})