mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-09 18:45:38 +00:00
Update Jest & Enzyme, Add snapshot tests (#307)
* Add disclaimer modal to footer * Remove duplicate code & unnecessary styles * Fix formatting noise * remove un-used css style * Fix tslint error & add media query for modals * Nest Media Query * Update Jest & Enzyme, Add snapshot tests * Fix tslint errors in /spec, Update mock localstorage * Update types in tests, Fix tslint error * Specify module versions for browser * Update sendTransaction snapshot
This commit is contained in:
parent
9095fc0986
commit
70a2b3ca9a
@ -12,10 +12,10 @@ interface ABITypedSlot {
|
|||||||
|
|
||||||
interface ABIMethod {
|
interface ABIMethod {
|
||||||
name: string;
|
name: string;
|
||||||
type: 'function';
|
type: string;
|
||||||
constant: boolean;
|
constant?: boolean;
|
||||||
inputs: ABITypedSlot[];
|
inputs: ABITypedSlot[];
|
||||||
outputs: ABITypedSlot[];
|
outputs?: ABITypedSlot[];
|
||||||
// default - false
|
// default - false
|
||||||
payable?: boolean;
|
payable?: boolean;
|
||||||
}
|
}
|
||||||
|
1
jest_config/__mocks__/fileMock.ts
Normal file
1
jest_config/__mocks__/fileMock.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = 'test-file-stub';
|
@ -1,4 +1,4 @@
|
|||||||
export default class LocalStorageMock {
|
class LocalStorageMock {
|
||||||
private store: object;
|
private store: object;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -21,3 +21,7 @@ export default class LocalStorageMock {
|
|||||||
delete this.store[key];
|
delete this.store[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(window, 'localStorage', {
|
||||||
|
value: new LocalStorageMock()
|
||||||
|
});
|
1
jest_config/__mocks__/styleMock.ts
Normal file
1
jest_config/__mocks__/styleMock.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = {};
|
@ -1,17 +1,22 @@
|
|||||||
{
|
{
|
||||||
|
"rootDir": "../",
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
|
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
|
||||||
},
|
},
|
||||||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||||||
"moduleFileExtensions": [
|
"moduleDirectories": ["node_modules", "common"],
|
||||||
"ts",
|
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json"],
|
||||||
"tsx",
|
"moduleNameMapper": {
|
||||||
"js",
|
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
|
||||||
"jsx",
|
"<rootDir>/jest_config/__mocks__/fileMock.ts",
|
||||||
"json"
|
"\\.(css|scss|less)$": "<rootDir>/jest_config/__mocks__/styleMock.ts"
|
||||||
],
|
},
|
||||||
"testPathIgnorePatterns": ["<rootDir>/common/config"],
|
"testPathIgnorePatterns": ["<rootDir>/common/config"],
|
||||||
"setupFiles": ["<rootDir>/jest_config/setupJest.js"],
|
"setupFiles": [
|
||||||
|
"<rootDir>/jest_config/setupJest.js",
|
||||||
|
"<rootDir>/jest_config/__mocks__/localStorage.ts"
|
||||||
|
],
|
||||||
"automock": false,
|
"automock": false,
|
||||||
"moduleDirectories": ["node_modules", "common"]
|
"snapshotSerializers": ["enzyme-to-json/serializer"],
|
||||||
|
"browser": true
|
||||||
}
|
}
|
||||||
|
1802
package-lock.json
generated
1802
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -46,7 +46,7 @@
|
|||||||
"@types/bignumber.js": "^4.0.2",
|
"@types/bignumber.js": "^4.0.2",
|
||||||
"@types/classnames": "^2.2.3",
|
"@types/classnames": "^2.2.3",
|
||||||
"@types/history": "^4.6.0",
|
"@types/history": "^4.6.0",
|
||||||
"@types/jest": "^21.1.0",
|
"@types/jest": "^21.1.4",
|
||||||
"@types/lodash": "^4.14.74",
|
"@types/lodash": "^4.14.74",
|
||||||
"@types/moment": "^2.13.0",
|
"@types/moment": "^2.13.0",
|
||||||
"@types/prop-types": "^15.5.1",
|
"@types/prop-types": "^15.5.1",
|
||||||
@ -72,7 +72,9 @@
|
|||||||
"copy-webpack-plugin": "^4.0.1",
|
"copy-webpack-plugin": "^4.0.1",
|
||||||
"css-loader": "^0.28.7",
|
"css-loader": "^0.28.7",
|
||||||
"empty": "^0.10.1",
|
"empty": "^0.10.1",
|
||||||
"enzyme": "^2.8.0",
|
"enzyme": "^3.1.0",
|
||||||
|
"enzyme-adapter-react-16": "^1.0.2",
|
||||||
|
"enzyme-to-json": "^3.1.4",
|
||||||
"express": "^4.15.4",
|
"express": "^4.15.4",
|
||||||
"extract-text-webpack-plugin": "^3.0.0",
|
"extract-text-webpack-plugin": "^3.0.0",
|
||||||
"file-loader": "^0.11.0",
|
"file-loader": "^0.11.0",
|
||||||
@ -81,7 +83,7 @@
|
|||||||
"html-webpack-plugin": "^2.30.1",
|
"html-webpack-plugin": "^2.30.1",
|
||||||
"husky": "^0.14.3",
|
"husky": "^0.14.3",
|
||||||
"image-webpack-loader": "^3.4.2",
|
"image-webpack-loader": "^3.4.2",
|
||||||
"jest": "^19.0.2",
|
"jest": "^21.2.1",
|
||||||
"less": "^2.7.2",
|
"less": "^2.7.2",
|
||||||
"less-loader": "^4.0.3",
|
"less-loader": "^4.0.3",
|
||||||
"lint-staged": "^4.2.2",
|
"lint-staged": "^4.2.2",
|
||||||
@ -92,12 +94,14 @@
|
|||||||
"prettier": "^1.7.0",
|
"prettier": "^1.7.0",
|
||||||
"progress": "^2.0.0",
|
"progress": "^2.0.0",
|
||||||
"react-hot-loader": "^3.0.0-beta.6",
|
"react-hot-loader": "^3.0.0-beta.6",
|
||||||
|
"react-test-renderer": "^16.0.0",
|
||||||
"redux-devtools-extension": "^2.13.0",
|
"redux-devtools-extension": "^2.13.0",
|
||||||
|
"redux-test-utils": "^0.1.3",
|
||||||
"resolve-url-loader": "^2.0.0",
|
"resolve-url-loader": "^2.0.0",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"sass-loader": "^6.0.2",
|
"sass-loader": "^6.0.2",
|
||||||
"style-loader": "^0.18.2",
|
"style-loader": "^0.18.2",
|
||||||
"ts-jest": "^21.0.1",
|
"ts-jest": "^21.1.3",
|
||||||
"tslint": "^5.7.0",
|
"tslint": "^5.7.0",
|
||||||
"tslint-config-prettier": "^1.5.0",
|
"tslint-config-prettier": "^1.5.0",
|
||||||
"tslint-react": "^3.2.0",
|
"tslint-react": "^3.2.0",
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import Contract from 'libs/contract';
|
import Contract from 'libs/contract';
|
||||||
import Big from 'bignumber.js';
|
|
||||||
|
|
||||||
describe('Contract', () => {
|
describe('Contract', () => {
|
||||||
// From the ABI docs
|
// From the ABI docs
|
||||||
@ -7,16 +6,16 @@ describe('Contract', () => {
|
|||||||
const testAbi = [
|
const testAbi = [
|
||||||
{
|
{
|
||||||
type: 'event',
|
type: 'event',
|
||||||
|
name: 'Event',
|
||||||
inputs: [
|
inputs: [
|
||||||
{ name: 'a', type: 'uint256', indexed: true },
|
{ name: 'a', type: 'uint256', indexed: true },
|
||||||
{ name: 'b', type: 'bytes32', indexed: false }
|
{ name: 'b', type: 'bytes32', indexed: false }
|
||||||
],
|
]
|
||||||
name: 'Event'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'function',
|
type: 'function',
|
||||||
inputs: [{ name: 'a', type: 'uint256' }],
|
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
|
inputs: [{ name: 'a', type: 'uint256' }],
|
||||||
outputs: []
|
outputs: []
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -6,50 +6,52 @@ import {
|
|||||||
decryptMnemonicToPrivKey
|
decryptMnemonicToPrivKey
|
||||||
} from '../../common/libs/decrypt';
|
} from '../../common/libs/decrypt';
|
||||||
|
|
||||||
//deconstructed elements of a V1 encrypted priv key
|
// Elements of a V1 encrypted priv key
|
||||||
const encpkey =
|
const v1 = {
|
||||||
'U2FsdGVkX19us8qXfYyeQhxyzV7aFlXckG/KrRLajoCGBKO4/saefxGs/3PrCLWxZEbx2vn6V0VDWrkDUkL+8S4MK7FL9LCiIKxeCq/ciwX9YQepsRRetG2MExuUWkQ6365d';
|
encpkey:
|
||||||
const pass = 'testtesttest';
|
'U2FsdGVkX19us8qXfYyeQhxyzV7aFlXckG/KrRLajoCGBKO4/saefxGs/3PrCLWxZEbx2vn6V0VDWrkDUkL+8S4MK7FL9LCiIKxeCq/ciwX9YQepsRRetG2MExuUWkQ6365d',
|
||||||
const salt = 'brPKl32MnkI=';
|
pass: 'testtesttest',
|
||||||
const ciphertext =
|
salt: 'brPKl32MnkI=',
|
||||||
'HHLNXtoWVdyQb8qtEtqOgIYEo7j+xp5/Eaz/c+sItbFkRvHa+fpXRUNauQNSQv7xLgwrsUv0sKIgrF4Kr9yLBf1hB6mxFF60bYwTG5RaRDrfrl0=';
|
ciphertext:
|
||||||
const iv = 'k9YWF8ZBCoyuFS6CfGS+7w==';
|
'HHLNXtoWVdyQb8qtEtqOgIYEo7j+xp5/Eaz/c+sItbFkRvHa+fpXRUNauQNSQv7xLgwrsUv0sKIgrF4Kr9yLBf1hB6mxFF60bYwTG5RaRDrfrl0=',
|
||||||
const key = 'u9uhwRmBQDJ12MUBkIrO5EzMQZTYEf6hTBDzSJBKJ2k=';
|
iv: 'k9YWF8ZBCoyuFS6CfGS+7w==',
|
||||||
const pkey = 'a56d4f23449a10ddcdd94bad56f895640097800406840aa8fe545d324d422c02';
|
key: 'u9uhwRmBQDJ12MUBkIrO5EzMQZTYEf6hTBDzSJBKJ2k=',
|
||||||
|
pkey: 'a56d4f23449a10ddcdd94bad56f895640097800406840aa8fe545d324d422c02'
|
||||||
|
};
|
||||||
|
|
||||||
describe('decryptPrivKey', () => {
|
describe('decryptPrivKey', () => {
|
||||||
it('should decrypt encrypted pkey string to pkey buffer', () => {
|
it('should decrypt encrypted pkey string to pkey buffer', () => {
|
||||||
const decrypt = decryptPrivKey(encpkey, pass);
|
const decrypt = decryptPrivKey(v1.encpkey, v1.pass);
|
||||||
|
|
||||||
expect(decrypt).toBeInstanceOf(Buffer);
|
expect(decrypt).toBeInstanceOf(Buffer);
|
||||||
expect(decrypt.toString('hex')).toEqual(pkey);
|
expect(decrypt.toString('hex')).toEqual(v1.pkey);
|
||||||
expect(decrypt.length).toEqual(32);
|
expect(decrypt.length).toEqual(32);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('decodeCryptojsSalt', () => {
|
describe('decodeCryptojsSalt', () => {
|
||||||
it('should derive correct salt and ciphertext from pkey string', () => {
|
it('should derive correct salt and ciphertext from pkey string', () => {
|
||||||
const decode = decodeCryptojsSalt(encpkey);
|
const decode = decodeCryptojsSalt(v1.encpkey);
|
||||||
|
|
||||||
expect(decode.salt).toBeInstanceOf(Buffer);
|
expect(decode.salt).toBeInstanceOf(Buffer);
|
||||||
expect(decode.ciphertext).toBeInstanceOf(Buffer);
|
expect(decode.ciphertext).toBeInstanceOf(Buffer);
|
||||||
expect(decode.salt.toString('base64')).toEqual(salt);
|
expect(decode.salt.toString('base64')).toEqual(v1.salt);
|
||||||
expect(decode.ciphertext.toString('base64')).toEqual(ciphertext);
|
expect(decode.ciphertext.toString('base64')).toEqual(v1.ciphertext);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('evp_kdf', () => {
|
describe('evp_kdf', () => {
|
||||||
it('should derive correct key and iv', () => {
|
it('should derive correct key and iv', () => {
|
||||||
const result = evp_kdf(
|
const result = evp_kdf(
|
||||||
new Buffer(pass, 'utf8'),
|
new Buffer(v1.pass, 'utf8'),
|
||||||
new Buffer(salt, 'base64'),
|
new Buffer(v1.salt, 'base64'),
|
||||||
{ keysize: 32, ivsize: 16 }
|
{ keysize: 32, ivsize: 16 }
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result.key).toBeInstanceOf(Buffer);
|
expect(result.key).toBeInstanceOf(Buffer);
|
||||||
expect(result.iv).toBeInstanceOf(Buffer);
|
expect(result.iv).toBeInstanceOf(Buffer);
|
||||||
expect(result.key.toString('base64')).toEqual(key);
|
expect(result.key.toString('base64')).toEqual(v1.key);
|
||||||
expect(result.iv.toString('base64')).toEqual(iv);
|
expect(result.iv.toString('base64')).toEqual(v1.iv);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import Big from 'bignumber.js';
|
import Big from 'bignumber.js';
|
||||||
import ERC20 from 'libs/erc20';
|
import ERC20 from 'libs/erc20';
|
||||||
import abi from 'ethereumjs-abi';
|
|
||||||
const MEW_ADDRESS = '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8';
|
const MEW_ADDRESS = '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8';
|
||||||
|
|
||||||
describe('ERC20', () => {
|
describe('ERC20', () => {
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import Big from 'bignumber.js';
|
import Big from 'bignumber.js';
|
||||||
import { toWei, toUnit } from '../../common/libs/units';
|
import { toWei, toUnit, UnitKey } from '../../common/libs/units';
|
||||||
|
|
||||||
describe('Units', () => {
|
describe('Units', () => {
|
||||||
describe('toWei', () => {
|
describe('toWei', () => {
|
||||||
const conversions = [
|
const conversions = [
|
||||||
{
|
{
|
||||||
value: '0.001371',
|
value: '0.001371',
|
||||||
unit: 'ether',
|
unit: 'ether' as UnitKey,
|
||||||
wei: '1371000000000000'
|
wei: '1371000000000000'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: '9',
|
value: '9',
|
||||||
unit: 'gwei',
|
unit: 'gwei' as UnitKey,
|
||||||
wei: '9000000000'
|
wei: '9000000000'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@ -28,14 +28,14 @@ describe('Units', () => {
|
|||||||
const conversions = [
|
const conversions = [
|
||||||
{
|
{
|
||||||
value: '.41849',
|
value: '.41849',
|
||||||
fromUnit: 'ether',
|
fromUnit: 'ether' as UnitKey,
|
||||||
toUnit: 'gwei',
|
toUnit: 'gwei' as UnitKey,
|
||||||
output: '418490000'
|
output: '418490000'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: '4924.71',
|
value: '4924.71',
|
||||||
fromUnit: 'nanoether',
|
fromUnit: 'nanoether' as UnitKey,
|
||||||
toUnit: 'szabo',
|
toUnit: 'szabo' as UnitKey,
|
||||||
output: '4.92471'
|
output: '4.92471'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
16
spec/pages/ENS.spec.tsx
Normal file
16
spec/pages/ENS.spec.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Enzyme from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
import ENS from 'containers/Tabs/ENS';
|
||||||
|
import shallowWithStore from '../utils/shallowWithStore';
|
||||||
|
import { createMockStore } from 'redux-test-utils';
|
||||||
|
|
||||||
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
|
it('render snapshot', () => {
|
||||||
|
const testState = {};
|
||||||
|
const store = createMockStore(testState);
|
||||||
|
const component = shallowWithStore(<ENS />, store);
|
||||||
|
|
||||||
|
expect(component).toMatchSnapshot();
|
||||||
|
});
|
25
spec/pages/GenerateWallet.spec.tsx
Normal file
25
spec/pages/GenerateWallet.spec.tsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Enzyme from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
import GenerateWallet from 'containers/Tabs/GenerateWallet';
|
||||||
|
import shallowWithStore from '../utils/shallowWithStore';
|
||||||
|
import { createMockStore } from 'redux-test-utils';
|
||||||
|
|
||||||
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
|
it('render snapshot', () => {
|
||||||
|
const testState = {
|
||||||
|
form: {
|
||||||
|
walletPasswordForm: {}
|
||||||
|
},
|
||||||
|
generateWallet: {
|
||||||
|
activeStep: {},
|
||||||
|
password: {},
|
||||||
|
wallet: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const store = createMockStore(testState);
|
||||||
|
const component = shallowWithStore(<GenerateWallet />, store);
|
||||||
|
|
||||||
|
expect(component).toMatchSnapshot();
|
||||||
|
});
|
44
spec/pages/SendTransaction.spec.tsx
Normal file
44
spec/pages/SendTransaction.spec.tsx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Enzyme from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
import SendTransaction from 'containers/Tabs/SendTransaction';
|
||||||
|
import shallowWithStore from '../utils/shallowWithStore';
|
||||||
|
import { createMockStore } from 'redux-test-utils';
|
||||||
|
|
||||||
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
|
it('render snapshot', () => {
|
||||||
|
const testStateConfig = {
|
||||||
|
languageSelection: 'en',
|
||||||
|
nodeSelection: 'rop_mew',
|
||||||
|
gasPriceGwei: 21,
|
||||||
|
offline: false,
|
||||||
|
forceOffline: false
|
||||||
|
};
|
||||||
|
const testState = {
|
||||||
|
wallet: {},
|
||||||
|
balance: {},
|
||||||
|
tokenBalances: {},
|
||||||
|
node: {},
|
||||||
|
nodeLib: {},
|
||||||
|
network: {},
|
||||||
|
tokens: [],
|
||||||
|
gasPrice: {},
|
||||||
|
transactions: {},
|
||||||
|
offline: {},
|
||||||
|
forceOffline: {},
|
||||||
|
config: testStateConfig,
|
||||||
|
customTokens: []
|
||||||
|
};
|
||||||
|
const location = {
|
||||||
|
search:
|
||||||
|
'?to=73640ebefe93e4d0d6e9030ee9c1866ad1f3b9f1feeb403e978c4952d8369b39'
|
||||||
|
};
|
||||||
|
const store = createMockStore(testState);
|
||||||
|
const component = shallowWithStore(
|
||||||
|
<SendTransaction location={location} />,
|
||||||
|
store
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(component).toMatchSnapshot();
|
||||||
|
});
|
35
spec/pages/Swap.spec.tsx
Normal file
35
spec/pages/Swap.spec.tsx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Enzyme from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
import Swap from 'containers/Tabs/Swap';
|
||||||
|
import shallowWithStore from '../utils/shallowWithStore';
|
||||||
|
import { createMockStore } from 'redux-test-utils';
|
||||||
|
|
||||||
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
|
it('render snapshot', () => {
|
||||||
|
const testState = {
|
||||||
|
swap: {
|
||||||
|
originAmount: {},
|
||||||
|
destinationAmount: {},
|
||||||
|
originKind: {},
|
||||||
|
destinationKind: {},
|
||||||
|
destinationKindOptions: {},
|
||||||
|
originKindOptions: {},
|
||||||
|
step: {},
|
||||||
|
bityRates: {},
|
||||||
|
bityOrder: {},
|
||||||
|
destinationAddress: {},
|
||||||
|
isFetchingRates: {},
|
||||||
|
secondsRemaining: {},
|
||||||
|
outputTx: {},
|
||||||
|
isPostingOrder: {},
|
||||||
|
orderStatus: {},
|
||||||
|
paymentAddress: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const store = createMockStore(testState);
|
||||||
|
const component = shallowWithStore(<Swap />, store);
|
||||||
|
|
||||||
|
expect(component).toMatchSnapshot();
|
||||||
|
});
|
16
spec/pages/ViewWallet.spec.tsx
Normal file
16
spec/pages/ViewWallet.spec.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Enzyme from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
import ViewWallet from 'containers/Tabs/ViewWallet';
|
||||||
|
import shallowWithStore from '../utils/shallowWithStore';
|
||||||
|
import { createMockStore } from 'redux-test-utils';
|
||||||
|
|
||||||
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
|
it('render snapshot', () => {
|
||||||
|
const testState = {};
|
||||||
|
const store = createMockStore(testState);
|
||||||
|
const component = shallowWithStore(<ViewWallet />, store);
|
||||||
|
|
||||||
|
expect(component).toMatchSnapshot();
|
||||||
|
});
|
7
spec/pages/__snapshots__/ENS.spec.tsx.snap
Normal file
7
spec/pages/__snapshots__/ENS.spec.tsx.snap
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`render snapshot 1`] = `
|
||||||
|
<ENS
|
||||||
|
dispatch={[Function]}
|
||||||
|
/>
|
||||||
|
`;
|
13
spec/pages/__snapshots__/GenerateWallet.spec.tsx.snap
Normal file
13
spec/pages/__snapshots__/GenerateWallet.spec.tsx.snap
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`render snapshot 1`] = `
|
||||||
|
<GenerateWallet
|
||||||
|
activeStep={Object {}}
|
||||||
|
continueToPaper={[Function]}
|
||||||
|
generateNewWallet={[Function]}
|
||||||
|
password={Object {}}
|
||||||
|
resetGenerateWallet={[Function]}
|
||||||
|
wallet={Object {}}
|
||||||
|
walletPasswordForm={Object {}}
|
||||||
|
/>
|
||||||
|
`;
|
77
spec/pages/__snapshots__/SendTransaction.spec.tsx.snap
Normal file
77
spec/pages/__snapshots__/SendTransaction.spec.tsx.snap
Normal file
File diff suppressed because one or more lines are too long
37
spec/pages/__snapshots__/Swap.spec.tsx.snap
Normal file
37
spec/pages/__snapshots__/Swap.spec.tsx.snap
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`render snapshot 1`] = `
|
||||||
|
<Swap
|
||||||
|
bityOrder={Object {}}
|
||||||
|
bityOrderCreateRequestedSwap={[Function]}
|
||||||
|
bityRates={Object {}}
|
||||||
|
changeStepSwap={[Function]}
|
||||||
|
destinationAddress={Object {}}
|
||||||
|
destinationAddressSwap={[Function]}
|
||||||
|
destinationAmount={Object {}}
|
||||||
|
destinationAmountSwap={[Function]}
|
||||||
|
destinationKind={Object {}}
|
||||||
|
destinationKindOptions={Object {}}
|
||||||
|
destinationKindSwap={[Function]}
|
||||||
|
isFetchingRates={Object {}}
|
||||||
|
isPostingOrder={Object {}}
|
||||||
|
loadBityRatesRequestedSwap={[Function]}
|
||||||
|
orderStatus={Object {}}
|
||||||
|
originAmount={Object {}}
|
||||||
|
originAmountSwap={[Function]}
|
||||||
|
originKind={Object {}}
|
||||||
|
originKindOptions={Object {}}
|
||||||
|
originKindSwap={[Function]}
|
||||||
|
outputTx={Object {}}
|
||||||
|
paymentAddress={Object {}}
|
||||||
|
restartSwap={[Function]}
|
||||||
|
secondsRemaining={Object {}}
|
||||||
|
showNotification={[Function]}
|
||||||
|
startOrderTimerSwap={[Function]}
|
||||||
|
startPollBityOrderStatus={[Function]}
|
||||||
|
step={Object {}}
|
||||||
|
stopLoadBityRatesSwap={[Function]}
|
||||||
|
stopOrderTimerSwap={[Function]}
|
||||||
|
stopPollBityOrderStatus={[Function]}
|
||||||
|
/>
|
||||||
|
`;
|
34
spec/pages/__snapshots__/ViewWallet.spec.tsx.snap
Normal file
34
spec/pages/__snapshots__/ViewWallet.spec.tsx.snap
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`render snapshot 1`] = `
|
||||||
|
<Connect(TabSection)>
|
||||||
|
<section
|
||||||
|
className="container"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="tab-content"
|
||||||
|
>
|
||||||
|
<article
|
||||||
|
className="tab-pane active"
|
||||||
|
>
|
||||||
|
<article
|
||||||
|
className="collapse-container"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h1>
|
||||||
|
View Wallet Info
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<Translate
|
||||||
|
translationKey="VIEWWALLET_Subtitle"
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</Connect(TabSection)>
|
||||||
|
`;
|
@ -3,10 +3,6 @@ import * as configActions from 'actions/config';
|
|||||||
import { NODES } from 'config/data';
|
import { NODES } from 'config/data';
|
||||||
|
|
||||||
describe('config reducer', () => {
|
describe('config reducer', () => {
|
||||||
it('should return the initial state', () => {
|
|
||||||
expect(config(undefined, {})).toEqual(INITIAL_STATE);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle CONFIG_LANGUAGE_CHANGE', () => {
|
it('should handle CONFIG_LANGUAGE_CHANGE', () => {
|
||||||
const language = 'en';
|
const language = 'en';
|
||||||
expect(config(undefined, configActions.changeLanguage(language))).toEqual({
|
expect(config(undefined, configActions.changeLanguage(language))).toEqual({
|
||||||
@ -16,7 +12,7 @@ describe('config reducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle CONFIG_NODE_CHANGE', () => {
|
it('should handle CONFIG_NODE_CHANGE', () => {
|
||||||
const node = NODES[0];
|
const node = Object.keys(NODES)[0];
|
||||||
|
|
||||||
expect(config(undefined, configActions.changeNode(node))).toEqual({
|
expect(config(undefined, configActions.changeNode(node))).toEqual({
|
||||||
...INITIAL_STATE,
|
...INITIAL_STATE,
|
||||||
|
@ -2,10 +2,6 @@ import { generateWallet, INITIAL_STATE } from 'reducers/generateWallet';
|
|||||||
import * as generateWalletActions from 'actions/generateWallet';
|
import * as generateWalletActions from 'actions/generateWallet';
|
||||||
|
|
||||||
describe('generateWallet reducer', () => {
|
describe('generateWallet reducer', () => {
|
||||||
it('should return the initial state', () => {
|
|
||||||
expect(generateWallet(undefined, {})).toEqual(INITIAL_STATE);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle GENERATE_WALLET_CONTINUE_TO_PAPER', () => {
|
it('should handle GENERATE_WALLET_CONTINUE_TO_PAPER', () => {
|
||||||
expect(
|
expect(
|
||||||
generateWallet(undefined, generateWalletActions.continueToPaper())
|
generateWallet(undefined, generateWalletActions.continueToPaper())
|
||||||
|
@ -8,10 +8,6 @@ import * as swapActions from 'actions/swap';
|
|||||||
import without from 'lodash/without';
|
import without from 'lodash/without';
|
||||||
|
|
||||||
describe('swap reducer', () => {
|
describe('swap reducer', () => {
|
||||||
it('should return the initial state', () => {
|
|
||||||
expect(swap(undefined, {})).toEqual(INITIAL_STATE);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle SWAP_ORIGIN_KIND', () => {
|
it('should handle SWAP_ORIGIN_KIND', () => {
|
||||||
const newOriginKind = 'ETH';
|
const newOriginKind = 'ETH';
|
||||||
const newDestinationKind = buildDestinationKind(
|
const newDestinationKind = buildDestinationKind(
|
||||||
@ -84,7 +80,9 @@ describe('swap reducer', () => {
|
|||||||
it('should handle SWAP_LOAD_BITY_RATES_SUCCEEDED', () => {
|
it('should handle SWAP_LOAD_BITY_RATES_SUCCEEDED', () => {
|
||||||
const bityRates = {
|
const bityRates = {
|
||||||
BTCETH: 0.01,
|
BTCETH: 0.01,
|
||||||
ETHREP: 10
|
ETHREP: 10,
|
||||||
|
ETHBTC: 0,
|
||||||
|
BTCREP: 0
|
||||||
};
|
};
|
||||||
expect(
|
expect(
|
||||||
swap(undefined, swapActions.loadBityRatesSucceededSwap(bityRates))
|
swap(undefined, swapActions.loadBityRatesSucceededSwap(bityRates))
|
||||||
@ -134,14 +132,22 @@ describe('swap reducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle SWAP_ORDER_CREATE_REQUESTED', () => {
|
it('should handle SWAP_ORDER_CREATE_REQUESTED', () => {
|
||||||
expect(swap(undefined, { type: 'SWAP_ORDER_CREATE_REQUESTED' })).toEqual({
|
expect(
|
||||||
|
swap(undefined, {
|
||||||
|
type: 'SWAP_ORDER_CREATE_REQUESTED'
|
||||||
|
} as swapActions.SwapAction)
|
||||||
|
).toEqual({
|
||||||
...INITIAL_STATE,
|
...INITIAL_STATE,
|
||||||
isPostingOrder: true
|
isPostingOrder: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle SWAP_ORDER_CREATE_FAILED', () => {
|
it('should handle SWAP_ORDER_CREATE_FAILED', () => {
|
||||||
expect(swap(undefined, { type: 'SWAP_ORDER_CREATE_FAILED' })).toEqual({
|
expect(
|
||||||
|
swap(undefined, {
|
||||||
|
type: 'SWAP_ORDER_CREATE_FAILED'
|
||||||
|
} as swapActions.SwapAction)
|
||||||
|
).toEqual({
|
||||||
...INITIAL_STATE,
|
...INITIAL_STATE,
|
||||||
isPostingOrder: false
|
isPostingOrder: false
|
||||||
});
|
});
|
||||||
@ -166,7 +172,9 @@ describe('swap reducer', () => {
|
|||||||
|
|
||||||
it('should handle SWAP_LOAD_BITY_RATES_REQUESTED', () => {
|
it('should handle SWAP_LOAD_BITY_RATES_REQUESTED', () => {
|
||||||
expect(
|
expect(
|
||||||
swap(undefined, { type: 'SWAP_LOAD_BITY_RATES_REQUESTED' })
|
swap(undefined, {
|
||||||
|
type: 'SWAP_LOAD_BITY_RATES_REQUESTED'
|
||||||
|
} as swapActions.SwapAction)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
...INITIAL_STATE,
|
...INITIAL_STATE,
|
||||||
isFetchingRates: true
|
isFetchingRates: true
|
||||||
@ -174,7 +182,11 @@ describe('swap reducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle SWAP_STOP_LOAD_BITY_RATES', () => {
|
it('should handle SWAP_STOP_LOAD_BITY_RATES', () => {
|
||||||
expect(swap(undefined, { type: 'SWAP_STOP_LOAD_BITY_RATES' })).toEqual({
|
expect(
|
||||||
|
swap(undefined, {
|
||||||
|
type: 'SWAP_STOP_LOAD_BITY_RATES'
|
||||||
|
} as swapActions.SwapAction)
|
||||||
|
).toEqual({
|
||||||
...INITIAL_STATE,
|
...INITIAL_STATE,
|
||||||
isFetchingRates: false
|
isFetchingRates: false
|
||||||
});
|
});
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
import { wallet, INITIAL_STATE } from 'reducers/wallet';
|
import { wallet, INITIAL_STATE } from 'reducers/wallet';
|
||||||
import * as walletActions from 'actions/wallet';
|
import * as walletActions from 'actions/wallet';
|
||||||
import Big from 'bignumber.js';
|
import Big from 'bignumber.js';
|
||||||
import { Ether } from 'libs/units';
|
|
||||||
|
|
||||||
describe('wallet reducer', () => {
|
describe('wallet reducer', () => {
|
||||||
it('should return the initial state', () => {
|
|
||||||
expect(wallet(undefined, {})).toEqual(INITIAL_STATE);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle WALLET_SET', () => {
|
it('should handle WALLET_SET', () => {
|
||||||
const walletInstance = { wallet: true };
|
const doSomething = new Promise<string>(resolve => {
|
||||||
|
setTimeout(() => resolve('Success'), 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
const walletInstance = {
|
||||||
|
getAddress: () => doSomething,
|
||||||
|
signRawTransaction: () => doSomething
|
||||||
|
};
|
||||||
|
|
||||||
expect(wallet(undefined, walletActions.setWallet(walletInstance))).toEqual({
|
expect(wallet(undefined, walletActions.setWallet(walletInstance))).toEqual({
|
||||||
...INITIAL_STATE,
|
...INITIAL_STATE,
|
||||||
inst: walletInstance,
|
inst: walletInstance,
|
||||||
|
@ -25,15 +25,18 @@ describe('formatNumber', () => {
|
|||||||
const pairs = [
|
const pairs = [
|
||||||
{
|
{
|
||||||
input: new Big('0.0127491'),
|
input: new Big('0.0127491'),
|
||||||
output: '0.013'
|
output: '0.013',
|
||||||
|
digits: undefined
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: new Big('21.87468421'),
|
input: new Big('21.87468421'),
|
||||||
output: '21.875'
|
output: '21.875',
|
||||||
|
digits: undefined
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: new Big(0),
|
input: new Big(0),
|
||||||
output: '0'
|
output: '0',
|
||||||
|
digits: undefined
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: new Big('354.4728173'),
|
input: new Big('354.4728173'),
|
||||||
@ -48,7 +51,7 @@ describe('formatNumber', () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
pairs.forEach(pair => {
|
pairs.forEach(pair => {
|
||||||
const digits = pair.digits === undefined ? 'default' : pair.digits;
|
const digits = pair.digits;
|
||||||
it(`should convert ${pair.input.toString()} to ${pair.output} when using ${digits} digits`, () => {
|
it(`should convert ${pair.input.toString()} to ${pair.output} when using ${digits} digits`, () => {
|
||||||
expect(formatNumber(pair.input, pair.digits)).toEqual(pair.output);
|
expect(formatNumber(pair.input, pair.digits)).toEqual(pair.output);
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import LocalStorageMock from '../mocks/localStorage';
|
|
||||||
import {
|
import {
|
||||||
loadState,
|
loadState,
|
||||||
saveState,
|
saveState,
|
||||||
@ -6,15 +5,15 @@ import {
|
|||||||
REDUX_STATE
|
REDUX_STATE
|
||||||
} from '../../common/utils/localStorage';
|
} from '../../common/utils/localStorage';
|
||||||
|
|
||||||
window.localStorage = new LocalStorageMock();
|
|
||||||
|
|
||||||
describe('saveState', () => {
|
describe('saveState', () => {
|
||||||
it('should serialize and persist state to local storage under key: "REDUX_STATE"', () => {
|
it('should serialize and persist state to local storage under key: "REDUX_STATE"', () => {
|
||||||
const persistMe = {
|
const persistMe = {
|
||||||
foo: 'bar'
|
foo: 'bar'
|
||||||
};
|
};
|
||||||
saveState(persistMe);
|
saveState(persistMe);
|
||||||
expect(JSON.parse(localStorage.getItem(REDUX_STATE))).toEqual(persistMe);
|
expect(JSON.parse(localStorage.getItem(REDUX_STATE) as string)).toEqual(
|
||||||
|
persistMe
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
10
spec/utils/shallowWithStore.ts
Normal file
10
spec/utils/shallowWithStore.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
const shallowWithStore = (component, store) => {
|
||||||
|
const context = {
|
||||||
|
store
|
||||||
|
};
|
||||||
|
return shallow(component, { context });
|
||||||
|
};
|
||||||
|
|
||||||
|
export default shallowWithStore;
|
@ -17,6 +17,7 @@
|
|||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./common/",
|
"./common/",
|
||||||
|
"spec",
|
||||||
"./node_modules/types-rlp/index.d.ts",
|
"./node_modules/types-rlp/index.d.ts",
|
||||||
"./node_modules/types-bn/index.d.ts"
|
"./node_modules/types-bn/index.d.ts"
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user