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

feat: 3rd party payment dispute reason added #8464

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
76 changes: 42 additions & 34 deletions packages/components/src/components/radio-group/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import React, { ChangeEvent } from 'react';
import classNames from 'classnames';
import Text from '../text';

type TItem = React.HTMLAttributes<HTMLDivElement> & { id?: string; value: string; label: string; disabled: boolean };
type TItem = React.HTMLAttributes<HTMLDivElement> & {
id?: string;
value: string;
label: string;
disabled: boolean;
is_hidden?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to give this a falsy default value so that the rest of the usage won't fail? (better to false than undefined in line no.55)

As you work on updating the shared component, please remember to incorporate the QA checklist for all the areas where this component has been utilised.

};
type TItemWrapper = {
should_wrap_items?: boolean;
};
Expand Down Expand Up @@ -45,41 +51,43 @@ const RadioGroup = ({
return (
<div className={classNames('dc-radio-group', className)}>
{Array.isArray(children) &&
children.map(item => (
<ItemWrapper key={item.props.value} should_wrap_items={should_wrap_items}>
<label
className={classNames('dc-radio-group__item', className, {
'dc-radio-group__item--selected': selected_option === item.props.value,
})}
>
<input
id={item.props.id}
name={name}
className='dc-radio-group__input'
type='radio'
value={item.props.value}
checked={selected_option === item.props.value}
onChange={onChange}
disabled={item.props.disabled}
required={required}
/>
<span
className={classNames('dc-radio-group__circle', {
'dc-radio-group__circle--selected': selected_option === item.props.value,
'dc-radio-group__circle--disabled': item.props.disabled,
})}
/>
<Text
size='xs'
className={classNames('dc-radio-group__label', {
'dc-radio-group__label--disabled': item.props.disabled,
children
.filter(item => !item.props.is_hidden)
.map(item => (
<ItemWrapper key={item.props.value} should_wrap_items={should_wrap_items}>
<label
className={classNames('dc-radio-group__item', className, {
'dc-radio-group__item--selected': selected_option === item.props.value,
})}
>
{item.props.label}
</Text>
</label>
</ItemWrapper>
))}
<input
id={item.props.id}
name={name}
className='dc-radio-group__input'
type='radio'
value={item.props.value}
checked={selected_option === item.props.value}
onChange={onChange}
disabled={item.props.disabled}
required={required}
/>
<span
className={classNames('dc-radio-group__circle', {
'dc-radio-group__circle--selected': selected_option === item.props.value,
'dc-radio-group__circle--disabled': item.props.disabled,
})}
/>
<Text
size='xs'
className={classNames('dc-radio-group__label', {
'dc-radio-group__label--disabled': item.props.disabled,
})}
>
{item.props.label}
</Text>
</label>
</ItemWrapper>
))}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ import { fireEvent, render, screen } from '@testing-library/react';
import OrderDetailsComplainModalRadioGroup from '../order-details-complain-modal-radio-group.jsx';

describe('<OrderDetailsComplainModalRadioGroup/>', () => {
it('should render component with 3 radio buttons', () => {
it('should render component with 4 radio buttons for sell order', () => {
render(<OrderDetailsComplainModalRadioGroup />);

expect(screen.getAllByRole('radio').length).toBe(3);
expect(screen.getAllByRole('radio').length).toBe(4);
nada-deriv marked this conversation as resolved.
Show resolved Hide resolved
});

it('should select the checkbox when a radio button is selected', () => {
it('should call handler function when checkbox is selected', () => {
const mockFn = jest.fn();
render(<OrderDetailsComplainModalRadioGroup onCheckboxChange={mockFn} />);
fireEvent.click(screen.getAllByRole('radio')[1]);

expect(mockFn).toHaveBeenCalledWith('buyer_underpaid');
});

it('should select the checkbox when a radio button is selected', () => {
it('should render all the 4 the options for sell order', () => {
nada-deriv marked this conversation as resolved.
Show resolved Hide resolved
render(<OrderDetailsComplainModalRadioGroup />);

expect(screen.getByLabelText('I’ve not received any payment.')).toBeInTheDocument();
expect(screen.getByLabelText('I’ve received less than the agreed amount.')).toBeInTheDocument();
expect(screen.getByLabelText('I’ve received more than the agreed amount.')).toBeInTheDocument();
expect(screen.getByText('I’ve received payment from 3rd party.')).toBeInTheDocument();
});

it('should select the checkbox when a radio button is selected', () => {
it('should render all the 3 oprions for buy order', () => {
render(<OrderDetailsComplainModalRadioGroup is_buy_order_for_user />);

expect(
Expand All @@ -34,4 +35,11 @@ describe('<OrderDetailsComplainModalRadioGroup/>', () => {
expect(screen.getByLabelText('I wasn’t able to make full payment.')).toBeInTheDocument();
expect(screen.getByLabelText('I’ve paid more than the agreed amount.')).toBeInTheDocument();
});
it('should call handler function with buyer_third_party_payment_method when i have received payment is selected for sell order', () => {
const mockFn = jest.fn();
render(<OrderDetailsComplainModalRadioGroup onCheckboxChange={mockFn} />);
fireEvent.click(screen.getAllByRole('radio')[3]);

expect(mockFn).toHaveBeenCalledWith('buyer_third_party_payment_method');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const OrderDetailsComplainModalRadioGroup = ({ dispute_reason, onCheckboxChange,
: localize('I’ve received more than the agreed amount.')
}
/>
<RadioGroup.Item
value='buyer_third_party_payment_method'
label={localize('I’ve received payment from 3rd party.')}
is_hidden={is_buy_order_for_user}
/>
</RadioGroup>
);

Expand Down