Skip to content

Commit

Permalink
test: add tests (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
heorhi-deriv authored Jun 22, 2023
1 parent a6906dd commit 08b9fec
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
95 changes: 95 additions & 0 deletions packages/utils/src/__tests__/getWalletCurrencyIcon.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import getWalletCurrencyIcon from '../getWalletCurrencyIcon';

describe('getWalletCurrencyIcon', () => {
describe('Should return proper icons for cashier modal', () => {
it('should return proper icon for demo currency', () => {
expect(getWalletCurrencyIcon('demo', false, true)).toBe('IcWalletDerivDemoLight');
});

it('should return proper icon for USDT, eUSDT, tUSDT, UST currency in dark mode', () => {
const currencies = ['USDT', 'eUSDT', 'tUSDT', 'UST'];
currencies.forEach(currency => {
expect(getWalletCurrencyIcon(currency, true, true)).toBe('IcWalletModalTetherDark');
});
});

it('should return proper icon for USDT, eUSDT, tUSDT, UST currency in light mode', () => {
const currencies = ['USDT', 'eUSDT', 'tUSDT', 'UST'];
currencies.forEach(currency => {
expect(getWalletCurrencyIcon(currency, false, true)).toBe('IcWalletModalTetherLight');
});
});
});

describe('Should return proper icons for other components', () => {
it('should return proper icon for demo currency in dark mode', () => {
expect(getWalletCurrencyIcon('demo', false)).toBe('IcWalletDerivDemoLight');
});

it('should return proper icon for demo currency in light mode', () => {
expect(getWalletCurrencyIcon('demo', true)).toBe('IcWalletDerivDemoDark');
});

it('should return proper icon for USD currency in dark/light mode', () => {
expect(getWalletCurrencyIcon('USD')).toBe('IcWalletCurrencyUsd');
});

it('should return proper icon for EUR currency in dark/light mode', () => {
expect(getWalletCurrencyIcon('EUR')).toBe('IcWalletCurrencyEur');
});

it('should return proper icon for AUD currency in dark/light mode', () => {
expect(getWalletCurrencyIcon('AUD')).toBe('IcWalletCurrencyAud');
});

it('should return proper icon for GBP currency in dark/light mode', () => {
expect(getWalletCurrencyIcon('GBP')).toBe('IcWalletCurrencyGbp');
});

it('should return proper icon for BTC currency in dark mode', () => {
expect(getWalletCurrencyIcon('BTC', false)).toBe('IcWalletBitcoinLight');
});

it('should return proper icon for BTC currency in light mode', () => {
expect(getWalletCurrencyIcon('BTC', true)).toBe('IcWalletBitcoinDark');
});

it('should return proper icon for ETH currency in dark mode', () => {
expect(getWalletCurrencyIcon('ETH', false)).toBe('IcWalletEtheriumLight');
});

it('should return proper icon for ETH currency in light mode', () => {
expect(getWalletCurrencyIcon('ETH', true)).toBe('IcWalletEtheriumDark');
});

it('should return proper icon for USDT, eUSDT, tUSDT, UST currency in dark mode', () => {
const currencies = ['USDT', 'eUSDT', 'tUSDT', 'UST'];
currencies.forEach(currency => {
expect(getWalletCurrencyIcon(currency, true)).toBe('IcWalletTetherDark');
});
});

it('should return proper icon for USDT, eUSDT, tUSDT, UST currency in light mode', () => {
const currencies = ['USDT', 'eUSDT', 'tUSDT', 'UST'];
currencies.forEach(currency => {
expect(getWalletCurrencyIcon(currency, false)).toBe('IcWalletTetherLight');
});
});

it('should return proper icon for LTC currency in dark mode', () => {
expect(getWalletCurrencyIcon('LTC', false)).toBe('IcWalletLiteCoinLight');
});

it('should return proper icon for LTC currency in light mode', () => {
expect(getWalletCurrencyIcon('LTC', true)).toBe('IcWalletLiteCoinDark');
});

it('should return proper icon for USDC currency in dark mode', () => {
expect(getWalletCurrencyIcon('USDC', false)).toBe('IcWalletUsdCoinLight');
});

it('should return proper icon for USDC currency in light mode', () => {
expect(getWalletCurrencyIcon('USDC', true)).toBe('IcWalletUsdCoinDark');
});
});
});
33 changes: 33 additions & 0 deletions packages/utils/src/__tests__/groupTransactionsByDay.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import groupTransactionsByDay from '../groupTransactionsByDay';
import { Statement } from '@deriv/api-types';

describe('groupTransactionsByDay', () => {
it('should group transactions by day', () => {
const transactions: Statement['transactions'] = [
{
transaction_time: new Date('08 Jun 2023').getTime() / 1000,
},
{
transaction_time: new Date('10 Jun 2023').getTime() / 1000,
},
{
transaction_time: new Date('12 Jun 2023').getTime() / 1000,
},
{
transaction_time: new Date('08 Jun 2023').getTime() / 1000,
},
{
transaction_time: new Date('10 Jun 2023').getTime() / 1000,
},
{
transaction_time: new Date('12 Jun 2023').getTime() / 1000,
},
];

const groupped_transactions = groupTransactionsByDay(transactions);

expect(transactions.length).toBe(6);
expect(Object.keys(groupped_transactions).length).toBe(3);
expect(Object.keys(groupped_transactions)).toStrictEqual(['08 Jun 2023', '10 Jun 2023', '12 Jun 2023']);
});
});
2 changes: 1 addition & 1 deletion packages/utils/src/getWalletCurrencyIcon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getWalletCurrencyIcon = (currency: string, is_dark_mode_on: boolean, is_modal = false) => {
const getWalletCurrencyIcon = (currency: string, is_dark_mode_on = false, is_modal = false) => {
switch (currency) {
case 'demo':
if (is_modal) return 'IcWalletDerivDemoLight';
Expand Down

0 comments on commit 08b9fec

Please sign in to comment.