A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/ducks/app/app.test.js

356 lines
9.0 KiB

import * as actionConstants from '../../store/actionConstants';
import reduceApp from './app';
const actions = actionConstants;
6 years ago
describe('App State', () => {
6 years ago
const metamaskState = {
selectedAddress: '0xAddress',
identities: {
'0xAddress': {
name: 'account 1',
address: '0xAddress',
6 years ago
},
},
};
6 years ago
it('app init state', () => {
const initState = reduceApp(metamaskState, {});
6 years ago
expect.anything(initState);
});
6 years ago
it('sets networkDropdownOpen dropdown to true', () => {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.NETWORK_DROPDOWN_OPEN,
});
6 years ago
expect(state.networkDropdownOpen).toStrictEqual(true);
});
6 years ago
it('sets networkDropdownOpen dropdown to false', () => {
const dropdown = { networkDropdowopen: true };
const state = { ...metamaskState, ...dropdown };
6 years ago
const newState = reduceApp(state, {
type: actions.NETWORK_DROPDOWN_CLOSE,
});
6 years ago
expect(newState.networkDropdownOpen).toStrictEqual(false);
});
6 years ago
it('opens sidebar', () => {
6 years ago
const value = {
transitionName: 'sidebar-right',
type: 'wallet-view',
isOpen: true,
};
const state = reduceApp(metamaskState, {
6 years ago
type: actions.SIDEBAR_OPEN,
value,
});
6 years ago
expect(state.sidebar).toStrictEqual(value);
});
6 years ago
it('closes sidebar', () => {
const openSidebar = { sidebar: { isOpen: true } };
const state = { ...metamaskState, ...openSidebar };
6 years ago
const newState = reduceApp(state, {
type: actions.SIDEBAR_CLOSE,
});
6 years ago
expect(newState.sidebar.isOpen).toStrictEqual(false);
});
6 years ago
it('opens alert', () => {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.ALERT_OPEN,
value: 'test message',
});
6 years ago
expect(state.alertOpen).toStrictEqual(true);
expect(state.alertMessage).toStrictEqual('test message');
});
6 years ago
it('closes alert', () => {
const alert = { alertOpen: true, alertMessage: 'test message' };
const state = { ...metamaskState, ...alert };
6 years ago
const newState = reduceApp(state, {
type: actions.ALERT_CLOSE,
});
6 years ago
expect(newState.alertOpen).toStrictEqual(false);
expect(newState.alertMessage).toBeNull();
});
6 years ago
it('detects qr code data', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.QR_CODE_DETECTED,
value: 'qr data',
});
6 years ago
expect(state.qrCodeData).toStrictEqual('qr data');
});
6 years ago
it('opens modal', () => {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.MODAL_OPEN,
payload: {
name: 'test',
},
});
6 years ago
expect(state.modal.open).toStrictEqual(true);
expect(state.modal.modalState.name).toStrictEqual('test');
});
6 years ago
it('closes modal, but moves open modal state to previous modal state', () => {
const opensModal = {
modal: {
open: true,
modalState: {
name: 'test',
},
},
};
const state = { ...metamaskState, appState: { ...opensModal } };
6 years ago
const newState = reduceApp(state, {
type: actions.MODAL_CLOSE,
});
6 years ago
expect(newState.modal.open).toStrictEqual(false);
expect(newState.modal.modalState.name).toBeNull();
});
6 years ago
it('shows send token page', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_SEND_TOKEN_PAGE,
});
6 years ago
expect(state.warning).toBeNull();
});
6 years ago
it('locks Metamask', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.LOCK_METAMASK,
});
6 years ago
expect(state.warning).toBeNull();
});
6 years ago
it('goes home', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.GO_HOME,
});
6 years ago
expect(state.accountDetail.subview).toStrictEqual('transactions');
expect(state.accountDetail.accountExport).toStrictEqual('none');
expect(state.accountDetail.privateKey).toStrictEqual('');
expect(state.warning).toBeNull();
});
6 years ago
it('shows account detail', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_ACCOUNT_DETAIL,
value: 'context address',
});
expect(state.forgottenPassword).toBeNull(); // default
expect(state.accountDetail.subview).toStrictEqual('transactions'); // default
expect(state.accountDetail.accountExport).toStrictEqual('none'); // default
expect(state.accountDetail.privateKey).toStrictEqual(''); // default
});
6 years ago
it('clears account details', () => {
const exportPrivKeyModal = {
accountDetail: {
subview: 'export',
accountExport: 'completed',
privateKey: 'a-priv-key',
},
};
const state = { ...metamaskState, appState: { ...exportPrivKeyModal } };
const newState = reduceApp(state, {
type: actions.CLEAR_ACCOUNT_DETAILS,
});
expect(newState.accountDetail).toStrictEqual({});
});
it('shoes account page', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_ACCOUNTS_PAGE,
});
6 years ago
expect(state.isLoading).toStrictEqual(false);
expect(state.warning).toBeNull();
expect(state.scrollToBottom).toStrictEqual(false);
expect(state.forgottenPassword).toStrictEqual(false);
});
6 years ago
it('shows confirm tx page', () => {
6 years ago
const txs = {
unapprovedTxs: {
1: {
id: 1,
},
2: {
id: 2,
},
},
};
const oldState = { ...metamaskState, ...txs };
6 years ago
const state = reduceApp(oldState, {
type: actions.SHOW_CONF_TX_PAGE,
id: 2,
});
6 years ago
expect(state.txId).toStrictEqual(2);
expect(state.warning).toBeNull();
expect(state.isLoading).toStrictEqual(false);
});
6 years ago
it('completes tx continues to show pending txs current view context', () => {
6 years ago
const txs = {
unapprovedTxs: {
1: {
id: 1,
},
2: {
id: 2,
},
},
};
6 years ago
const oldState = { ...metamaskState, ...txs };
6 years ago
const state = reduceApp(oldState, {
type: actions.COMPLETED_TX,
value: {
id: 1,
},
});
6 years ago
expect(state.txId).toBeNull();
expect(state.warning).toBeNull();
});
6 years ago
it('returns to account detail page when no unconf actions completed tx', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.COMPLETED_TX,
value: {
unconfirmedActionsCount: 0,
},
});
6 years ago
expect(state.warning).toBeNull();
expect(state.accountDetail.subview).toStrictEqual('transactions');
});
6 years ago
it('sets default warning when unlock fails', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.UNLOCK_FAILED,
});
6 years ago
expect(state.warning).toStrictEqual('Incorrect password. Try again.');
});
6 years ago
it('sets errors when unlock fails', () => {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.UNLOCK_FAILED,
value: 'errors',
});
6 years ago
expect(state.warning).toStrictEqual('errors');
});
6 years ago
it('sets warning to empty string when unlock succeeds', () => {
const errorState = { warning: 'errors' };
const oldState = { ...metamaskState, ...errorState };
6 years ago
const state = reduceApp(oldState, {
type: actions.UNLOCK_SUCCEEDED,
});
6 years ago
expect(state.warning).toStrictEqual('');
});
6 years ago
it('sets hardware wallet default hd path', () => {
6 years ago
const hdPaths = {
trezor: "m/44'/60'/0'/0",
ledger: "m/44'/60'/0'",
};
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SET_HARDWARE_WALLET_DEFAULT_HD_PATH,
value: {
device: 'ledger',
path: "m/44'/60'/0'",
},
});
6 years ago
expect(state.defaultHdPaths).toStrictEqual(hdPaths);
});
6 years ago
it('shows loading message', () => {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.SHOW_LOADING,
value: 'loading',
});
6 years ago
expect(state.isLoading).toStrictEqual(true);
expect(state.loadingMessage).toStrictEqual('loading');
});
6 years ago
it('hides loading message', () => {
const loadingState = { isLoading: true };
const oldState = { ...metamaskState, ...loadingState };
6 years ago
const state = reduceApp(oldState, {
type: actions.HIDE_LOADING,
});
6 years ago
expect(state.isLoading).toStrictEqual(false);
});
6 years ago
it('displays warning', () => {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.DISPLAY_WARNING,
value: 'warning',
});
6 years ago
expect(state.isLoading).toStrictEqual(false);
expect(state.warning).toStrictEqual('warning');
});
6 years ago
it('hides warning', () => {
const displayWarningState = { warning: 'warning' };
const oldState = { ...metamaskState, ...displayWarningState };
6 years ago
const state = reduceApp(oldState, {
type: actions.HIDE_WARNING,
});
6 years ago
expect(state.warning).toBeUndefined();
});
6 years ago
it('shows private key', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_PRIVATE_KEY,
value: 'private key',
});
6 years ago
expect(state.accountDetail.subview).toStrictEqual('export');
expect(state.accountDetail.accountExport).toStrictEqual('completed');
expect(state.accountDetail.privateKey).toStrictEqual('private key');
});
6 years ago
it('set mouse user state', () => {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SET_MOUSE_USER_STATE,
value: true,
});
6 years ago
expect(state.isMouseUser).toStrictEqual(true);
});
});