Merge branch 'develop' of https://github.com/andrerfneves/zec-react-wallet into feature/test-components-with-jest
This commit is contained in:
commit
93acce66d0
|
@ -0,0 +1,49 @@
|
|||
// @flow
|
||||
|
||||
import configureStore from 'redux-mock-store';
|
||||
|
||||
import {
|
||||
LOAD_ADDRESSES_SUCCESS,
|
||||
LOAD_ADDRESSES_ERROR,
|
||||
loadAddressesSuccess,
|
||||
loadAddressesError,
|
||||
} from '../../app/redux/modules/receive';
|
||||
|
||||
const store = configureStore()();
|
||||
|
||||
describe('Receive Actions', () => {
|
||||
beforeEach(() => store.clearActions());
|
||||
|
||||
test('should create an action to load addresses with success', () => {
|
||||
const payload = {
|
||||
addresses: [
|
||||
'tm0a9si0ds09gj02jj',
|
||||
'smas098gk02jf0kskk'
|
||||
],
|
||||
};
|
||||
|
||||
store.dispatch(loadAddressesSuccess(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: LOAD_ADDRESSES_SUCCESS,
|
||||
payload,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should create an action to load addresses with error', () => {
|
||||
const payload = {
|
||||
error: 'Something went wrong!',
|
||||
};
|
||||
|
||||
store.dispatch(loadAddressesError(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: LOAD_ADDRESSES_ERROR,
|
||||
payload,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,116 @@
|
|||
// @flow
|
||||
|
||||
import configureStore from 'redux-mock-store';
|
||||
|
||||
import {
|
||||
SEND_TRANSACTION,
|
||||
SEND_TRANSACTION_SUCCESS,
|
||||
SEND_TRANSACTION_ERROR,
|
||||
RESET_SEND_TRANSACTION,
|
||||
VALIDATE_ADDRESS_SUCCESS,
|
||||
VALIDATE_ADDRESS_ERROR,
|
||||
LOAD_ZEC_PRICE,
|
||||
sendTransaction,
|
||||
sendTransactionSuccess,
|
||||
sendTransactionError,
|
||||
resetSendTransaction,
|
||||
validateAddressSuccess,
|
||||
validateAddressError,
|
||||
loadZECPrice,
|
||||
} from '../../app/redux/modules/send';
|
||||
|
||||
const store = configureStore()();
|
||||
|
||||
describe('Send Actions', () => {
|
||||
beforeEach(() => store.clearActions());
|
||||
|
||||
test('should create an action to send a transaction', () => {
|
||||
store.dispatch(sendTransaction());
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: SEND_TRANSACTION,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should create an action to send transaction with success', () => {
|
||||
const payload = {
|
||||
operationId: '0b9ii4590ab-1d012klfo'
|
||||
};
|
||||
|
||||
store.dispatch(sendTransactionSuccess(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: SEND_TRANSACTION_SUCCESS,
|
||||
payload,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should create an action to send transaction with error', () => {
|
||||
const payload = {
|
||||
error: 'Something went wrong!',
|
||||
};
|
||||
|
||||
store.dispatch(sendTransactionError(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: SEND_TRANSACTION_ERROR,
|
||||
payload,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should reset a transaction', () => {
|
||||
store.dispatch(resetSendTransaction());
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: RESET_SEND_TRANSACTION,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should validate a address with success', () => {
|
||||
const payload = {
|
||||
isValid: true
|
||||
};
|
||||
|
||||
store.dispatch(validateAddressSuccess(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: VALIDATE_ADDRESS_SUCCESS,
|
||||
payload,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should validate a address with error', () => {
|
||||
store.dispatch(validateAddressError());
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: VALIDATE_ADDRESS_ERROR,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should load ZEC price', () => {
|
||||
const payload = {
|
||||
value: 1.35
|
||||
};
|
||||
|
||||
store.dispatch(loadZECPrice(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: LOAD_ZEC_PRICE,
|
||||
payload
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,59 @@
|
|||
// @flow
|
||||
|
||||
import configureStore from 'redux-mock-store';
|
||||
|
||||
import {
|
||||
LOAD_TRANSACTIONS,
|
||||
LOAD_TRANSACTIONS_SUCCESS,
|
||||
LOAD_TRANSACTIONS_ERROR,
|
||||
loadTransactions,
|
||||
loadTransactionsSuccess,
|
||||
loadTransactionsError,
|
||||
} from '../../app/redux/modules/transactions';
|
||||
|
||||
const store = configureStore()();
|
||||
|
||||
describe('Transactions Actions', () => {
|
||||
beforeEach(() => store.clearActions());
|
||||
|
||||
test('should create an action to load transactions', () => {
|
||||
store.dispatch(loadTransactions());
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: LOAD_TRANSACTIONS,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should create an action to load transactions with success', () => {
|
||||
const payload = {
|
||||
list: [],
|
||||
zecPrice: 0,
|
||||
};
|
||||
|
||||
store.dispatch(loadTransactionsSuccess(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: LOAD_TRANSACTIONS_SUCCESS,
|
||||
payload,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should create an action to load transactions with error', () => {
|
||||
const payload = {
|
||||
error: 'Something went wrong!',
|
||||
};
|
||||
|
||||
store.dispatch(loadTransactionsError(payload));
|
||||
|
||||
expect(store.getActions()[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: LOAD_TRANSACTIONS_ERROR,
|
||||
payload,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
|
@ -85,4 +85,4 @@ describe('WalletSummary Reducer', () => {
|
|||
|
||||
expect(walletSummaryReducer(undefined, action)).toEqual(expectedState);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// @flow
|
||||
import 'jest-dom/extend-expect';
|
||||
|
||||
import { filterObjectNullKeys } from '../../app/utils/filter-object-null-keys';
|
||||
|
||||
describe('filterObjectNullKeys', () => {
|
||||
test('should filter null keys from object', () => {
|
||||
const initialState = {
|
||||
name: 'John Doe',
|
||||
address: null,
|
||||
amount: 0,
|
||||
transactions: undefined,
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
name: 'John Doe',
|
||||
amount: 0,
|
||||
};
|
||||
|
||||
expect(filterObjectNullKeys(initialState)).toEqual(expectedState);
|
||||
})
|
||||
})
|
|
@ -0,0 +1,37 @@
|
|||
// @flow
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import 'jest-dom/extend-expect';
|
||||
|
||||
import { formatNumber } from '../../app/utils/format-number';
|
||||
|
||||
describe('formatNumber', () => {
|
||||
test('should append ZEC in balance amount', () => {
|
||||
const myBalance = formatNumber({ value: 2.5, append: 'ZEC ' });
|
||||
|
||||
const expectedState = 'ZEC 2.5';
|
||||
|
||||
expect(myBalance).toEqual(expectedState);
|
||||
});
|
||||
|
||||
test('should multiply ZEC balance and show it in USD', () => {
|
||||
const myBalanceInUsd = formatNumber({
|
||||
value: new BigNumber(2.5).times(1.35).toNumber(),
|
||||
append: 'USD $',
|
||||
});
|
||||
|
||||
const expectedState = 'USD $3.375';
|
||||
|
||||
expect(myBalanceInUsd).toEqual(expectedState);
|
||||
});
|
||||
|
||||
test('should multiply decimal ZEC balance and show it in USD', () => {
|
||||
const myBalanceInUsd = formatNumber({
|
||||
value: new BigNumber(0.1).times(0.2).toNumber(),
|
||||
append: 'USD $',
|
||||
});
|
||||
|
||||
const expectedState = 'USD $0.02';
|
||||
|
||||
expect(myBalanceInUsd).toEqual(expectedState);
|
||||
});
|
||||
})
|
|
@ -0,0 +1,13 @@
|
|||
// @flow
|
||||
import 'jest-dom/extend-expect';
|
||||
|
||||
import { getTimestamp } from '../../app/utils/timestamp';
|
||||
|
||||
describe('generate timestamp', () => {
|
||||
test('should generate a random string', () => {
|
||||
const now = getTimestamp();
|
||||
|
||||
expect(now).toEqual(expect.any(Number));
|
||||
|
||||
});
|
||||
})
|
|
@ -0,0 +1,14 @@
|
|||
// @flow
|
||||
import 'jest-dom/extend-expect';
|
||||
|
||||
import { truncateAddress } from '../../app/utils/truncate-address';
|
||||
|
||||
describe('truncateAddress', () => {
|
||||
test('should truncate ZEC address', () => {
|
||||
const myAddress = truncateAddress('t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1');
|
||||
|
||||
const expectedState = 't14oHp2v54vfmdgQ3v3S...8JKHTNi2a1';
|
||||
|
||||
expect(myAddress).toEqual(expectedState);
|
||||
});
|
||||
})
|
|
@ -14,7 +14,7 @@ import {
|
|||
loadWalletSummarySuccess,
|
||||
loadWalletSummaryError,
|
||||
} from '../redux/modules/wallet';
|
||||
import { sortBy } from '../utils/sort-by';
|
||||
import sortBy from '../utils/sort-by';
|
||||
|
||||
import type { AppState } from '../types/app-state';
|
||||
import type { Dispatch } from '../types/redux';
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
import rpc from '../../services/api';
|
||||
import store from '../../config/electron-store';
|
||||
|
||||
import { sortBy } from '../utils/sort-by';
|
||||
import sortBy from '../utils/sort-by';
|
||||
|
||||
import type { AppState } from '../types/app-state';
|
||||
import type { Dispatch } from '../types/redux';
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
// @flow
|
||||
export const formatNumber = ({ value, append = '' }: { value: number | string, append?: string }) => `${append}${(value || 0).toLocaleString()}`;
|
||||
|
||||
export const formatNumber = ({ value, append = '' }: { value: number, append?: string }) => `${append}${(value || 0).toLocaleString()}`;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// @flow
|
||||
/* eslint-disable max-len */
|
||||
// $FlowFixMe
|
||||
export const sortBy = <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] < b[field] ? 1 : -1));
|
||||
export default <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] < b[field] ? 1 : -1));
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// @flow
|
||||
|
||||
export const truncateAddress = (address: string = '') => `${address.substr(0, 20)}...${address.substr(address.length - 10, address.length)}`;
|
||||
export const truncateAddress = (address: string = '') => `${address.substr(0, 20)}...${address.substr(
|
||||
address.length - 10,
|
||||
address.length,
|
||||
)}`;
|
||||
|
|
|
@ -425,7 +425,7 @@ export class SendView extends PureComponent<Props, State> {
|
|||
|
||||
const isEmpty = amount === '';
|
||||
|
||||
const fixedAmount = isEmpty ? '0.00' : amount;
|
||||
const fixedAmount = isEmpty ? 0.0 : amount;
|
||||
|
||||
const zecBalance = formatNumber({ value: balance, append: 'ZEC ' });
|
||||
const zecBalanceInUsd = formatNumber({
|
||||
|
|
|
@ -999,10 +999,10 @@ x.toFormat(3, BigNumber.ROUND_UP, fmt) // '12.34.56.789,124'
|
|||
roundingMode: BigNumber$RoundingMode,
|
||||
format?: BigNumber$Format,
|
||||
): string;
|
||||
toFormat(decimalPlaces: number, roundingMode?: BigNumber$RoundingMode): string;
|
||||
toFormat(decimalPlaces?: number): string;
|
||||
toFormat(decimalPlaces: number, format: BigNumber$Format): string;
|
||||
toFormat(format: BigNumber$Format): string;
|
||||
toFormat(decimalPlaces: number, roundingMode?: BigNumber$RoundingMode): number;
|
||||
toFormat(decimalPlaces?: number): number;
|
||||
toFormat(decimalPlaces: number, format: BigNumber$Format): number;
|
||||
toFormat(format: BigNumber$Format): number;
|
||||
|
||||
/**
|
||||
* Returns an array of two BigNumbers representing the value of this BigNumber as a simple
|
||||
|
|
|
@ -1 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="125" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="125" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h91v20H0z"/><path fill="#4C1" d="M91 0h34v20H91z"/><path fill="url(#b)" d="M0 0h125v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,Geneva,sans-serif" font-size="11"><text x="45.5" y="15" fill="#010101" fill-opacity=".3">flow-coverage</text><text x="45.5" y="14">flow-coverage</text><text x="107" y="15" fill="#010101" fill-opacity=".3">82%</text><text x="107" y="14">82%</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="125" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="125" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h91v20H0z"/><path fill="#4C1" d="M91 0h34v20H91z"/><path fill="url(#b)" d="M0 0h125v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,Geneva,sans-serif" font-size="11"><text x="45.5" y="15" fill="#010101" fill-opacity=".3">flow-coverage</text><text x="45.5" y="14">flow-coverage</text><text x="107" y="15" fill="#010101" fill-opacity=".3">81%</text><text x="107" y="14">81%</text></g></svg>
|
Before Width: | Height: | Size: 745 B After Width: | Height: | Size: 745 B |
Loading…
Reference in New Issue