forked from deriv-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.
[DTRA]/DTRA-1467/Ahmad/Duration Params (deriv-com#16537)
* chore: still goin * chore: fix * fix: type * fix: fix * chore: fixed * chore: fixed ts error * chore: remove unused thing * fix: test case * fix: test case * chore: small height fix * revert: extra non-aligned file from master * revert: extra non-aligned file from master * chore: review comments * chore: review comments * fix: barrier fix * chore: review fix * chore: test case fix
- Loading branch information
1 parent
aa78845
commit a46d5c2
Showing
20 changed files
with
775 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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
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
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
71 changes: 71 additions & 0 deletions
71
packages/trader/src/AppV2/Components/TradeParameters/Duration/__tests__/duration.spec.tsx
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,71 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Duration from '../index'; | ||
import TraderProviders from '../../../../../trader-providers'; | ||
import { mockStore } from '@deriv/stores'; | ||
import { TCoreStores } from '@deriv/stores/types'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
global.ResizeObserver = jest.fn().mockImplementation(() => ({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
})); | ||
|
||
global.ResizeObserver = ResizeObserver; | ||
|
||
describe('Duration', () => { | ||
const default_trade_store = mockStore({ | ||
modules: { | ||
trade: { | ||
onChange: jest.fn(), | ||
validation_errors: { barrier_1: [] }, | ||
duration: 10, | ||
duration_unit: 'm', | ||
expiry_type: 'duration', | ||
}, | ||
}, | ||
}); | ||
|
||
const mockDuration = (mocked_store: TCoreStores) => { | ||
render( | ||
<TraderProviders store={mocked_store}> | ||
<Duration /> | ||
</TraderProviders> | ||
); | ||
}; | ||
|
||
it('should render the Duration component with default values', () => { | ||
default_trade_store.modules.trade.duration = 30; | ||
|
||
mockDuration(default_trade_store); | ||
expect(screen.getByLabelText('Duration')).toBeInTheDocument(); | ||
expect(screen.getByDisplayValue('30 minutes')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the correct value for duration in hours and minutes', () => { | ||
default_trade_store.modules.trade.duration = 125; | ||
mockDuration(default_trade_store); | ||
expect(screen.getByLabelText('Duration')).toBeInTheDocument(); | ||
expect(screen.getByDisplayValue('2 hours 5 minutes')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should open the ActionSheet when the text field is clicked', () => { | ||
default_trade_store.modules.trade.duration = 30; | ||
default_trade_store.modules.trade.expiry_time = '12:30'; | ||
mockDuration(default_trade_store); | ||
const textField = screen.getByLabelText('Duration'); | ||
expect(textField).toBeInTheDocument(); | ||
userEvent.click(textField); | ||
|
||
expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display expiry time in GMT when expiry_type is "time"', () => { | ||
default_trade_store.modules.trade.duration = 30; | ||
default_trade_store.modules.trade.expiry_type = 'end time'; | ||
default_trade_store.modules.trade.expiry_time = '12:30'; | ||
mockDuration(default_trade_store); | ||
expect(screen.getByDisplayValue('Ends at 12:30 GMT')).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.