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.
- Loading branch information
1 parent
23e4c60
commit 60c4da1
Showing
31 changed files
with
1,292 additions
and
37 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
packages/p2p/src/components/composite-calendar/__tests__/calendar-icon.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,11 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import CalendarIcon from '../calendar-icon'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('<CalendarIcon />', () => { | ||
it('should render icon', () => { | ||
render(<CalendarIcon onClick={jest.fn()} />); | ||
expect(screen.getByTestId('dt_calendar_icon')).toBeInTheDocument(); | ||
}); | ||
}); |
124 changes: 124 additions & 0 deletions
124
packages/p2p/src/components/composite-calendar/__tests__/composite-calendar.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,124 @@ | ||
import React from 'react'; | ||
import { act, render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
import CompositeCalendar from '../composite-calendar'; | ||
import TwoMonthPicker from '../two-month-picker'; | ||
import { toMoment } from '@deriv/shared'; | ||
|
||
const mock_props = { | ||
input_date_range: { | ||
value: 'last_7_days', | ||
label: 'Last 7 days', | ||
duration: 7, | ||
onClick: jest.fn(), | ||
}, | ||
from: 1696319493, | ||
onChange: jest.fn(), | ||
to: 1696928512, | ||
}; | ||
|
||
jest.mock('../composite-calendar-mobile', () => jest.fn(() => <div>CompositeCalendarMobile</div>)); | ||
|
||
// jest.mock('../calendar-side-list', () =>jest.fn(() => <div>CalendarSideList</div>)); | ||
|
||
jest.mock('../two-month-picker', () => jest.fn(() => <div>TwoMonthPicker</div>)); | ||
|
||
describe('<CompositeCalendar />', () => { | ||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mockStore({})}>{children}</StoreProvider> | ||
); | ||
it('should render the component', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
expect(screen.getByTestId('dt_calendar_input_from')).toBeInTheDocument(); | ||
expect(screen.getByTestId('dt_calendar_input_to')).toBeInTheDocument(); | ||
}); | ||
it('should handle onclick for "from date" input', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
expect(screen.getByText('Last 7 days')).toBeInTheDocument(); | ||
}); | ||
it('should handle onclick for "to date" input', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const to_input = screen.getByTestId('dt_calendar_input_to'); | ||
userEvent.click(to_input); | ||
expect(screen.getByText('Last 7 days')).toBeInTheDocument(); | ||
}); | ||
it('should handle setToDate function click', async () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const to_input = screen.getByTestId('dt_calendar_input_to'); | ||
userEvent.click(to_input); | ||
act(() => { | ||
(TwoMonthPicker as unknown as jest.Mock).mock.calls[0][0].onChange(); | ||
}); | ||
await waitFor(() => { | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
}); | ||
it('should handle setFromDate function click', async () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
act(() => { | ||
(TwoMonthPicker as unknown as jest.Mock).mock.calls[0][0].onChange(); | ||
}); | ||
await waitFor(() => { | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
}); | ||
it('should handle onclick for "All time" option', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
userEvent.click(screen.getByText('All time')); | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
it('should handle onclick for "Today" option', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
userEvent.click(screen.getByText('Today')); | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
it('should handle onclick for "Last 7 days" option', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
userEvent.click(screen.getByText('Last 7 days')); | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
it('should handle onclick for "Last 30 days" option', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
userEvent.click(screen.getByText('Last 30 days')); | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
it('should handle onclick for "Last quarter" option', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
userEvent.click(screen.getByText('Last quarter')); | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
it('should disable date before from date in "to input" section ', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const to_input = screen.getByTestId('dt_calendar_input_to'); | ||
userEvent.click(to_input); | ||
expect( | ||
(TwoMonthPicker as unknown as jest.Mock).mock.calls[0][0].isPeriodDisabled(toMoment('2023-10-02')) | ||
).toBeTruthy(); | ||
}); | ||
it('should disable date after to date in "from input" section ', () => { | ||
render(<CompositeCalendar {...mock_props} />, { wrapper }); | ||
const from_input = screen.getByTestId('dt_calendar_input_from'); | ||
userEvent.click(from_input); | ||
expect( | ||
(TwoMonthPicker as unknown as jest.Mock).mock.calls[0][0].isPeriodDisabled(toMoment('2023-10-02')) | ||
).toBeFalsy(); | ||
expect( | ||
(TwoMonthPicker as unknown as jest.Mock).mock.calls[0][0].isPeriodDisabled(toMoment('2023-10-12')) | ||
).toBeTruthy(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/p2p/src/components/composite-calendar/__tests__/two-month-picker.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,16 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import TwoMonthPicker from '../two-month-picker'; | ||
|
||
const mock_props = { | ||
onChange: jest.fn(), | ||
isPeriodDisabled: jest.fn(), | ||
value: 1696319493, // 2023-10-04 | ||
}; | ||
|
||
describe('TwoMonthPicker', () => { | ||
it('should render the component', () => { | ||
render(<TwoMonthPicker {...mock_props} />); | ||
expect(screen.getByText('Sep')).toBeInTheDocument(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/p2p/src/components/composite-calendar/calendar-icon.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,12 @@ | ||
import React from 'react'; | ||
import { Icon } from '@deriv/components'; | ||
|
||
type TCalendarIcon = { | ||
onClick: () => void; | ||
}; | ||
|
||
const CalendarIcon = ({ onClick }: TCalendarIcon) => ( | ||
<Icon onClick={onClick} icon='IcCalendarDatefrom' className='inline-icon' data_testid='dt_calendar_icon' /> | ||
); | ||
|
||
export default CalendarIcon; |
23 changes: 23 additions & 0 deletions
23
...mponents/composite-calendar/calendar-radio-buton/__tests__/calendar-radio-button.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,23 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import CalendarRadioButton from '../calendar-radio-button'; | ||
|
||
const mock_props = { | ||
id: '1', | ||
value: 'all_time', | ||
label: 'All time', | ||
onChange: jest.fn(), | ||
}; | ||
|
||
describe('CalendarRadioButton', () => { | ||
it('should render the radio button', () => { | ||
render(<CalendarRadioButton {...mock_props} />); | ||
expect(screen.getByText('All time')).toBeInTheDocument(); | ||
}); | ||
it('should handle on click of radio button', () => { | ||
render(<CalendarRadioButton {...mock_props} />); | ||
userEvent.click(screen.getByText('All time')); | ||
expect(mock_props.onChange).toHaveBeenCalled(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...ges/p2p/src/components/composite-calendar/calendar-radio-buton/calendar-radio-button.scss
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,32 @@ | ||
.calendar-radio-button { | ||
display: flex; | ||
align-items: center; | ||
padding: 0.7rem 0.8rem; | ||
border: 1px solid; | ||
border-color: var(--border-normal); | ||
border-radius: 4px; | ||
margin: 0.8rem 0.8rem 2.4rem; | ||
|
||
&__input { | ||
display: none; | ||
} | ||
&__circle { | ||
border: 2px solid var(--text-less-prominent); | ||
border-radius: 50%; | ||
box-shadow: 0 0 1px 0 var(--shadow-menu); | ||
width: 1.6rem; | ||
height: 1.6rem; | ||
transition: all 0.3s ease-in-out; | ||
margin-right: 0.8rem; | ||
align-self: center; | ||
|
||
&--selected { | ||
border-width: 4px; | ||
border-color: var(--brand-red-coral); | ||
} | ||
} | ||
&--selected { | ||
border-color: var(--brand-secondary); | ||
font-weight: bold; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ages/p2p/src/components/composite-calendar/calendar-radio-buton/calendar-radio-button.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,42 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { Text } from '@deriv/components'; | ||
|
||
type TCalendarRadioButtonProps = { | ||
id: string; | ||
className?: string; | ||
selected_value?: string; | ||
value: string; | ||
label: string; | ||
onChange: (value: { label?: string; value?: string }) => void; | ||
}; | ||
|
||
const CalendarRadioButton = ({ id, className, selected_value, value, label, onChange }: TCalendarRadioButtonProps) => { | ||
return ( | ||
<label | ||
htmlFor={id} | ||
className={classNames('calendar-radio-button', className, { | ||
'calendar-radio-button--selected': selected_value === value, | ||
})} | ||
onClick={() => onChange({ label, value })} | ||
> | ||
<input className='calendar-radio-button__input' id={id} type='radio' value={value} /> | ||
<span | ||
className={classNames('calendar-radio-button__circle', { | ||
'calendar-radio-button__circle--selected': selected_value === value, | ||
})} | ||
/> | ||
<Text | ||
as='p' | ||
color='prominent' | ||
size='xs' | ||
line_height='unset' | ||
weight={selected_value === value ? 'bold' : 'normal'} | ||
> | ||
{label} | ||
</Text> | ||
</label> | ||
); | ||
}; | ||
|
||
export default CalendarRadioButton; |
Oops, something went wrong.