forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kate / DTRA-249 / Code refactoring and removing duplicated files (#13)
* refactor: remove duplicated file * refactor: test improvements * fix: removed forgotten import * chore: empty commit to retrigger checks * refactor: apply suggestion
- Loading branch information
1 parent
ccd55ef
commit 1cf1f08
Showing
15 changed files
with
616 additions
and
1,038 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
91
packages/shared/src/utils/constants/__tests__/contract.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
Oops, something went wrong.