Skip to content

Commit

Permalink
Kate / DTRA-249 / Code refactoring and removing duplicated files (#13)
Browse files Browse the repository at this point in the history
* refactor: remove duplicated file

* refactor: test improvements

* fix: removed forgotten import

* chore: empty commit to retrigger checks

* refactor: apply suggestion
  • Loading branch information
kate-deriv committed Jul 4, 2023
1 parent ccd55ef commit 1cf1f08
Show file tree
Hide file tree
Showing 15 changed files with 616 additions and 1,038 deletions.
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 TGetSupportedContractsKey = keyof ReturnType<typeof getSupportedContracts>;
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 TGetSupportedContractsKey, 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 TGetSupportedContractsKey, 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 TGetSupportedContractsKey)).toBe('top');
});
});
Loading

0 comments on commit 1cf1f08

Please sign in to comment.