Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kate / DTRA-249 / Code refactoring and removing duplicated files #13

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 0 additions & 238 deletions packages/core/src/Constants/contract.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/src/Constants/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './contract';
export * from './ui';
91 changes: 91 additions & 0 deletions packages/shared/src/utils/constants/__tests__/contract.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { localize } from '@deriv/translations';
import {
getCardLabels,
getMarketNamesMap,
getUnsupportedContracts,
getSupportedContracts,
getContractConfig,
getContractTypeDisplay,
getContractTypePosition,
} from '../contract';

type TTest = keyof ReturnType<typeof getSupportedContracts>;
kate-deriv marked this conversation as resolved.
Show resolved Hide resolved
const card_label = localize('Apply');
const markets_name = localize('AUD/CAD');
const unsupported_contract = {
name: localize('Ends Outside'),
position: 'top',
};
const supported_high_low = {
name: localize('Higher'),
position: 'top',
};
const not_supported_high_low = {
name: localize('Rise'),
position: 'top',
};

describe('getCardLabels', () => {
it('should return an object with card labels, e.g. such as Apply', () => {
expect(getCardLabels().APPLY).toEqual(card_label);
});
});

describe('getMarketNamesMap', () => {
it('should return an object with markets names, e.g. such as AUD/CAD', () => {
expect(getMarketNamesMap().FRXAUDCAD).toEqual(markets_name);
});
});

describe('getUnsupportedContracts', () => {
it('should return an object with unsupported contracts, e.g. such as Ends Outside', () => {
expect(getUnsupportedContracts().EXPIRYMISS).toEqual(unsupported_contract);
});
});

describe('getSupportedContracts', () => {
it('should return an object with specific supported contracts if is_high_low === true', () => {
expect(getSupportedContracts(true).CALL).toEqual(supported_high_low);
});

it('should return an object with specific supported contracts if is_high_low === false', () => {
expect(getSupportedContracts(false).CALL).toEqual(not_supported_high_low);
});
});

describe('getContractConfig', () => {
it('should return an object with specific contracts if is_high_low === true', () => {
expect(getContractConfig(true).CALL).toEqual(supported_high_low);
});

it('should return object with specific contracts if is_high_low === false', () => {
expect(getContractConfig(false).CALL).toEqual(not_supported_high_low);
});
});

describe('getContractTypeDisplay', () => {
it('should return a specific button name if show_button_name === true and contract_config has a button_name field', () => {
expect(getContractTypeDisplay('ACCU', false, true)).toEqual(localize('Buy'));
});
it('should return a specific contract name if show_button_name === false but contract_config has a button_name field', () => {
expect(getContractTypeDisplay('ACCU')).toEqual(localize('Accumulator'));
});
it('should return a specific contract name if show_button_name === true but contract_config has no button_name field', () => {
expect(getContractTypeDisplay('MULTDOWN', true, true)).toEqual(localize('Down'));
});
it('should return an empty string if show_button_name === false and contract_config has no name field', () => {
expect(getContractTypeDisplay('TEST' as TTest, true, false)).toBe('');
});
it('should return an empty string if show_button_name === true and contract_config has no name field and no button_name', () => {
expect(getContractTypeDisplay('TEST' as TTest, true, true)).toBe('');
});
});

describe('getContractTypePosition', () => {
it('should return a specific button position if such type exist', () => {
expect(getContractTypePosition('NOTOUCH')).toBe('bottom');
});
it('should return a top position if such type does not exist', () => {
expect(getContractTypePosition('TEST' as TTest)).toBe('top');
});
});
Loading