Skip to content

Commit

Permalink
fix: failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nada-deriv committed Jun 6, 2024
1 parent 7735336 commit 1cf87cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/CopyAdForm/CopyAdForm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

& .mobile-wrapper__body {
margin-top: 1.6rem;
overflow: auto;
}

& .mobile-wrapper__footer {
Expand Down
15 changes: 11 additions & 4 deletions src/components/CopyAdForm/CopyAdForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type TCopyAdFormProps = NonUndefined<THooks.AdvertiserAdverts.Get>[0] & {
formValues: TSavedFormValues;
} & {
isModalOpen: boolean;
onClickCancel: () => void;
onClickCancel: (values: TSavedFormValues) => void;
onFormSubmit: (values: TSavedFormValues) => void;
onRequestClose: () => void;
};
Expand Down Expand Up @@ -121,7 +121,14 @@ const CopyAdForm = ({
<CopyAdFormDisplayWrapper
isModalOpen={isModalOpen}
isValid={isValid}
onClickCancel={onClickCancel}
onClickCancel={() =>
onClickCancel({
amount: getValues('amount'),
maxOrder: getValues('max-order'),
minOrder: getValues('min-order'),
rateValue: getValues('rate-value'),
})
}
onRequestClose={onRequestClose}
onSubmit={onSubmit}
>
Expand Down Expand Up @@ -227,10 +234,10 @@ const CopyAdForm = ({
</div>
{hasCounterpartyConditions && (
<div className='flex flex-col w-full mt-[1.6rem]'>
<Text color='less-prominent' size='xs'>
<Text color='less-prominent' size={labelSize}>
<Localize i18n_default_text='Counterparty conditions' />
</Text>
<Text as='ul' className='copy-advert-form__list' color='prominent' size='sm'>
<Text as='ul' size={valueSize}>
{minJoinDays > 0 && (
<li>
<Localize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ jest.mock('@deriv-com/ui', () => ({
useDevice: () => ({ isMobile: false }),
}));

jest.mock('@/hooks/api/useInvalidateQuery', () => jest.fn(() => jest.fn()));

describe('CreateEditAd', () => {
it('should render the create edit ad component', () => {
render(<CreateEditAd />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ const MyAdsTableRowView = ({
createAd(payload as TMutatePayload);
};

const onClickCancel = () => {
const onClickCancel = (values: TFormValues) => {
setFormValues(values);
showModal('AdCancelCreateEditModal');
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,29 @@ jest.mock('@/hooks/custom-hooks', () => {
jest.mock('@/hooks', () => ({
api: {
advert: {
useCreate: jest.fn().mockReturnValue({ error: null, isError: false, isSuccess: false, mutate: jest.fn() }),
useDelete: jest.fn().mockReturnValue({ error: null, isError: false, mutate: jest.fn() }),
useUpdate: jest.fn().mockReturnValue({ error: null, isError: false, mutate: jest.fn() }),
},
paymentMethods: {
useGet: jest.fn().mockReturnValue({ data: [] }),
},
settings: {
useSettings: jest.fn(() => ({
data: {
localCurrency: 'USD',
},
})),
},
},
}));

jest.mock('@/hooks/api/useInvalidateQuery', () => jest.fn(() => jest.fn()));

jest.mock('@/components/Modals', () => ({
AdCancelCreateEditModal: () => <div>AdCancelCreateEditModal</div>,
AdCreateEditErrorModal: () => <div>AdCreateEditErrorModal</div>,
AdCreateEditSuccessModal: () => <div>AdCreateEditSuccessModal</div>,
AdErrorTooltipModal: () => <div>AdErrorTooltipModal</div>,
AdRateSwitchModal: () => <div>AdRateSwitchModal</div>,
AdVisibilityErrorModal: () => <div>AdVisibilityErrorModal</div>,
Expand All @@ -118,6 +132,11 @@ jest.mock('@/components/CopyAdForm', () => ({
CopyAdForm: () => <div>CopyAdForm</div>,
}));

jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
useDevice: () => ({ isMobile: false }),
}));

jest.mock('../MyAdsTableRow', () => {
return jest.fn().mockImplementation(({ onClickIcon }) => {
return (
Expand Down

0 comments on commit 1cf87cd

Please sign in to comment.