chore(utils): split sort-by functions

This commit is contained in:
George Lima 2019-02-11 16:36:29 -03:00
parent cf195f8083
commit 71ab42ec4b
6 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,13 @@
// @flow
import 'jest-dom/extend-expect';
import { sortByDescend } from '../../app/utils/sort-by-descend';
describe('truncateAddress', () => {
test('should truncate ZEC address', () => {
expect(
sortByDescend('id')([{ id: 5 }, { id: 2 }, { id: 1 }, { id: 0 }, { id: 1 }, { id: 1 }]),
).toEqual([{ id: 5 }, { id: 2 }, { id: 1 }, { id: 1 }, { id: 1 }, { id: 0 }]);
});
});

View File

@ -0,0 +1,13 @@
// @flow
import 'jest-dom/extend-expect';
import { sortBy } from '../../app/utils/sort-by';
describe('truncateAddress', () => {
test('should truncate ZEC address', () => {
expect(
sortBy('id')([{ id: 5 }, { id: 2 }, { id: 1 }, { id: 0 }, { id: 1 }, { id: 1 }]),
).toEqual([{ id: 0 }, { id: 1 }, { id: 1 }, { id: 1 }, { id: 2 }, { id: 5 }]);
});
});

View File

@ -15,7 +15,7 @@ import {
loadWalletSummarySuccess,
loadWalletSummaryError,
} from '../redux/modules/wallet';
import { sortByDescend } from '../utils/sort-by';
import { sortByDescend } from '../utils/sort-by-descend';
import type { AppState } from '../types/app-state';
import type { Dispatch } from '../types/redux';

View File

@ -17,7 +17,7 @@ import rpc from '../../services/api';
import { listShieldedTransactions } from '../../services/shielded-transactions';
import store from '../../config/electron-store';
import { sortByDescend } from '../utils/sort-by';
import { sortByDescend } from '../utils/sort-by-descend';
import type { AppState } from '../types/app-state';
import type { Dispatch } from '../types/redux';

View File

@ -0,0 +1,5 @@
// @flow
/* eslint-disable max-len */
// $FlowFixMe
export const sortByDescend = <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] < b[field] ? 1 : -1));

View File

@ -3,6 +3,3 @@
// $FlowFixMe
export const sortBy = <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] > b[field] ? 1 : -1));
// $FlowFixMe
export const sortByDescend = <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] < b[field] ? 1 : -1));