Skip to content

Commit

Permalink
Merge pull request #20 from farrah-deriv/build-checks
Browse files Browse the repository at this point in the history
farrah/ fix: type errors
  • Loading branch information
farrah-deriv authored Apr 25, 2024
2 parents b75546b + df34f6e commit 5528c57
Show file tree
Hide file tree
Showing 56 changed files with 118 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/components/AdvertiserName/AdvertiserNameStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DeepPartial, TAdvertiserStats } from 'types';
import { OnlineStatusIcon, OnlineStatusLabel, StarRating } from '@/components';
import { getCurrentRoute } from '@/utils';
import { Text, useDevice } from '@deriv-com/ui';
import ThumbUpIcon from '../../public/ic-thumb-up.svg';
import ThumbUpIcon from '../../public/ic-thumb-up.svg?react';
import BlockedUserOutlineIcon from '../../public/ic-user-blocked-outline.svg?react';
import './AdvertiserNameStats.scss';

Expand Down
3 changes: 2 additions & 1 deletion src/components/BuySellForm/BuySellAmount/BuySellAmount.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { TCurrency } from 'types';
import { LightDivider } from '@/components';
import { floatingPointValidator } from '@/utils';
import { Input, Text, useDevice } from '@deriv-com/ui';
Expand All @@ -13,7 +14,7 @@ type TBuySellAmountProps = {
control: ReturnType<typeof useForm>['control'];
isBuy: boolean;
isDisabled: boolean;
localCurrency: string;
localCurrency: TCurrency;
maxLimit: string;
minLimit: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BuySellFormFooter from '../BuySellFormFooter';
const mockProps = {
isDisabled: false,
onClickCancel: jest.fn(),
onSubmit: jest.fn(),
};
jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
Expand All @@ -27,11 +28,10 @@ describe('BuySellFormFooter', () => {
expect(mockProps.onClickCancel).toHaveBeenCalled();
});
it('should handle onclick for confirm button', () => {
const newProps = { mockProps, onSubmit: jest.fn() };
render(<BuySellFormFooter {...newProps} />);
render(<BuySellFormFooter {...mockProps} />);
const confirmButton = screen.getByRole('button', { name: 'Confirm' });
confirmButton.click();
expect(newProps.onSubmit).toHaveBeenCalled();
expect(mockProps.onSubmit).toHaveBeenCalled();
});
it('should render as expected in responsive view as well', () => {
mockUseDevice.mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BuySellPaymentSection from '../BuySellPaymentSection';
const mockProps = {
availablePaymentMethods: [],
onSelectPaymentMethodCard: jest.fn(),
selectedPaymentMethodIds: ['123'],
selectedPaymentMethodIds: [123],
};

const mockAvailablePaymentMethods = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Clipboard/Clipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { useEffect, useRef, useState } from 'react';
import { useCopyToClipboard } from 'usehooks-ts';
import { Tooltip } from '@deriv-com/ui';
import CheckmarkCircle from '../../public/ic-checkmark-circle.svg';
import CopyIcon from '../../public/ic-clipboard.svg';
import CheckmarkCircle from '../../public/ic-checkmark-circle.svg?react';
import CopyIcon from '../../public/ic-clipboard.svg?react';
import './Clipboard.scss';

type TClipboardProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { memo, useCallback } from 'react';
import { TFile } from '@/utils';
import { DerivLightIcCloudUploadIcon, StandaloneCircleXmarkBoldIcon } from '@deriv/quill-icons';
import { Text } from '@deriv-com/ui';
import { FileDropzone } from '../FileDropzone';
Expand All @@ -10,8 +11,8 @@ type TFileUploaderComponentProps = {
maxSize: number;
multiple?: boolean;
onClickClose: () => void;
onDropAccepted: (files: File[]) => void;
onDropRejected: (files: File[]) => void;
onDropAccepted: (files: TFile[]) => void;
onDropRejected: (files: TFile[]) => void;
uploadedMessage: string;
validationErrorMessage: string | null;
value: (File & { file: Blob })[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('<FilterModal />', () => {
});

it('should populate the payment methods list with the data from the API', async () => {
mockData = undefined;
mockData = [];
const { rerender } = render(<FilterModal {...mockProps} />);

const paymentMethodsText = screen.getByText('Payment methods');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ jest.mock('@/providers/AdvertiserInfoStateProvider', () => ({

describe('NicknameModal', () => {
it('should render title and description correctly', () => {
render(<NicknameModal isModalOpen setIsModalOpen={jest.fn()} />);
render(<NicknameModal isModalOpen onRequestClose={jest.fn()} />);
expect(screen.getByText('What’s your nickname?')).toBeVisible();
expect(screen.getByText('Others will see this on your profile, ads and charts.')).toBeVisible();
});
it('should allow users to type and submit nickname', async () => {
render(<NicknameModal isModalOpen setIsModalOpen={jest.fn()} />);
render(<NicknameModal isModalOpen onRequestClose={jest.fn()} />);

const nicknameInput = screen.getByTestId('dt_nickname_modal_input');

Expand Down Expand Up @@ -85,7 +85,7 @@ describe('NicknameModal', () => {
}));

await (() => {
render(<NicknameModal isModalOpen setIsModalOpen={jest.fn()} />);
render(<NicknameModal isModalOpen onRequestClose={jest.fn()} />);
});

expect(mockedReset).toBeCalled();
Expand All @@ -99,7 +99,7 @@ describe('NicknameModal', () => {
reset: mockedReset,
}));
const mockIsModalOpen = jest.fn();
render(<NicknameModal isModalOpen setIsModalOpen={mockIsModalOpen} />);
render(<NicknameModal isModalOpen onRequestClose={mockIsModalOpen} />);

const cancelBtn = screen.getByRole('button', {
name: 'Cancel',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { PropsWithChildren } from 'react';
import { render, screen } from '@testing-library/react';
import PaymentMethodErrorModal from '../PaymentMethodErrorModal';

const wrapper = ({ children }: PropsWithChildren<unknown>) => <div id='v2_modal_root'>{children}</div>;
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => <div id='v2_modal_root'>{children}</div>;

jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { PropsWithChildren } from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import PaymentMethodModal from '../PaymentMethodModal';

const wrapper = ({ children }: PropsWithChildren<unknown>) => <div id='v2_modal_root'>{children}</div>;
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => <div id='v2_modal_root'>{children}</div>;

jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
Expand Down
6 changes: 3 additions & 3 deletions src/components/Modals/ShareAdsModal/ShareAdsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { api } from '@/hooks';
import { useCopyToClipboard } from '@/hooks/custom-hooks';
import { Button, Divider, Modal, Text, useDevice } from '@deriv-com/ui';
//TODO: replace below icons with the one from quill once available
import CheckmarkCircle from '../../../public/ic-checkmark-circle.svg';
import ShareIcon from '../../../public/ic-share.svg';
import ShareLinkIcon from '../../../public/ic-share-link.svg';
import CheckmarkCircle from '../../../public/ic-checkmark-circle.svg?react';
import ShareIcon from '../../../public/ic-share.svg?react';
import ShareLinkIcon from '../../../public/ic-share-link.svg?react';
import ShareMyAdsCard from './ShareAdsCard';
import ShareMyAdsSocials from './ShareAdsSocials';
import './ShareAdsModal.scss';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/ShareAdsModal/ShareAdsSocials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SocialGoogleBrandIcon,
SocialTelegramBrandIcon,
} from '@deriv/quill-icons';
import WhatsappIcon from '../../../public/ic-whatsapp-filled.svg';
import WhatsappIcon from '../../../public/ic-whatsapp-filled.svg?react';
import './ShareAdsSocials.scss';

type TShareMyAdsSocialsProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { THooks } from 'types';
import { FlyoutMenu } from '@/components';
import { LabelPairedEllipsisVerticalXlRegularIcon } from '@deriv/quill-icons';
import { Button, Checkbox } from '@deriv-com/ui';
import IcCashierBankTransfer from '../../../public/ic-cashier-bank-transfer.svg';
import IcCashierEwallet from '../../../public/ic-cashier-ewallet.svg';
import IcCashierOther from '../../../public/ic-cashier-other.svg';
import IcCashierBankTransfer from '../../../public/ic-cashier-bank-transfer.svg?react';
import IcCashierEwallet from '../../../public/ic-cashier-ewallet.svg?react';
import IcCashierOther from '../../../public/ic-cashier-other.svg?react';
import './PaymentMethodCardHeader.scss';

type TPaymentMethodCardHeaderProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/react';
import { PaymentMethodCardHeader } from '../PaymentMethodCardHeader';

jest.mock('../../../public/ic-cashier-ewallet.svg', () => 'span');
jest.mock('../../../public/ic-cashier-ewallet.svg?react', () => 'span');

describe('PaymentMethodCardHeader', () => {
it('should render the component correctly', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PaymentMethodForm/PaymentMethodForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const PaymentMethodForm = ({ onAdd, onResetFormState, ...rest }: TPaymentMethodF
reset,
} = useForm({ mode: 'all' });
const [isModalOpen, setIsModalOpen] = useState(false);
const { actionType, selectedPaymentMethod, title } = rest.formState;
const { actionType, selectedPaymentMethod, title = '' } = rest.formState;
const { data: availablePaymentMethods } = api.paymentMethods.useGet();
const { create, error: createError, isSuccess: isCreateSuccessful } = api.advertiserPaymentMethods.useCreate();
const { error: updateError, isSuccess: isUpdateSuccessful, update } = api.advertiserPaymentMethods.useUpdate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TFormState, THooks, TSelectedPaymentMethod } from 'types';
import { Dropdown } from '@/components';
import { Button, Input, Text } from '@deriv-com/ui';
import CloseCircle from '../../../public/ic-close-circle.svg';
import CloseCircle from '../../../public/ic-close-circle.svg?react';

type TPaymentMethodFormAutocompleteProps = {
actionType: TFormState['actionType'];
Expand Down
5 changes: 3 additions & 2 deletions src/components/PaymentMethodLabel/PaymentMethodLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { TGenericSizes, TTextColors } from '@/utils';
import { Text } from '@deriv-com/ui';

type TPaymentMethodLabelProps = {
color?: string;
color?: TTextColors;
paymentMethodName: string;
size?: string;
size?: TGenericSizes;
};

const PaymentMethodLabel = ({ color = 'general', paymentMethodName, size = 'sm' }: TPaymentMethodLabelProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import clsx from 'clsx';
import { THooks } from 'types';
import { TGenericSizes } from '@/utils';
import { Text } from '@deriv-com/ui';
import IcCashierBankTransfer from '../../public/ic-cashier-bank-transfer.svg';
import IcCashierEwallet from '../../public/ic-cashier-ewallet.svg';
import IcCashierOther from '../../public/ic-cashier-other.svg';
import IcCashierBankTransfer from '../../public/ic-cashier-bank-transfer.svg?react';
import IcCashierEwallet from '../../public/ic-cashier-ewallet.svg?react';
import IcCashierOther from '../../public/ic-cashier-other.svg?react';

type TPaymentMethodWithIconProps = {
className: string;
className?: string;
name: string;
textSize?: TGenericSizes;
type: THooks.AdvertiserPaymentMethods.Get[number]['type'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let mockProps = {

describe('<ProfileStats />', () => {
it('should render no results if advertiserStats is empty', () => {
render(<ProfileStats />);
render(<ProfileStats advertiserStats={{}} />);

expect(screen.queryByText('Buy completion 30d')).not.toBeInTheDocument();
expect(screen.queryByText('Sell completion 30d')).not.toBeInTheDocument();
Expand Down
14 changes: 8 additions & 6 deletions src/hooks/__tests__/useModalManager.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('useModalManager', () => {
it('should render and show the correct modal states when showModal is called', async () => {
const history = createMemoryHistory();
const originalLocation = window.location;
const wrapper = ({ children }: { children: JSX.Element }) => {
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
return <Router history={history}>{children}</Router>;
};

Expand Down Expand Up @@ -113,7 +113,7 @@ describe('useModalManager', () => {
});
it('should hide the modals and show previous modal when current modal hidden', () => {
const history = createMemoryHistory();
const wrapper = ({ children }: { children: JSX.Element }) => {
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
return <Router history={history}>{children}</Router>;
};

Expand Down Expand Up @@ -193,7 +193,7 @@ describe('useModalManager', () => {
});
it('should show the modals when URL is initialized with default modal states', () => {
const history = createMemoryHistory();
const wrapper = ({ children }: { children: JSX.Element }) => {
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
return <Router history={history}>{children}</Router>;
};

Expand Down Expand Up @@ -223,7 +223,7 @@ describe('useModalManager', () => {
});
it('should should not show the modals on navigated back when shouldReinitializeModals is set to false', () => {
const history = createMemoryHistory();
const wrapper = ({ children }: { children: JSX.Element }) => {
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
return <Router history={history}>{children}</Router>;
};

Expand Down Expand Up @@ -255,7 +255,7 @@ describe('useModalManager', () => {
});
it('should should show the modals on navigated back when shouldReinitializeModals is set to true', () => {
const history = createMemoryHistory();
const wrapper = ({ children }: { children: JSX.Element }) => {
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
return <Router history={history}>{children}</Router>;
};

Expand Down Expand Up @@ -291,7 +291,7 @@ describe('useModalManager', () => {
});
it('should should stack the modals in mobile', () => {
const history = createMemoryHistory();
const wrapper = ({ children }: { children: JSX.Element }) => {
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
return <Router history={history}>{children}</Router>;
};

Expand All @@ -302,7 +302,9 @@ describe('useModalManager', () => {
search: '?modal=ModalA,ModalB,ModalC',
}));
mockedUseDevice.mockImplementation(() => ({
isDesktop: false,
isMobile: true,
isTablet: false,
}));
mockedUseQueryString.mockImplementationOnce(() => ({
queryString: {
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/__tests__/usePoiPoaStatus.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ describe('usePoiPoaStatus', () => {
identity: {
status: 'verified',
},
needs_verification: false,
},
p2p_poa_required: false,
p2p_poa_required: 0,
},
});
const { result } = renderHook(() => usePoiPoaStatus());
Expand Down
4 changes: 3 additions & 1 deletion src/pages/advertiser/screens/Advertiser/Advertiser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const Advertiser = () => {
hasBorder={isMobile}
onClick={() =>
history.push(
location.state?.from === 'MyProfile' ? `${MY_PROFILE_URL}?tab=My+counterparties` : BUY_SELL_URL
(location.state as { from: string })?.from === 'MyProfile'
? `${MY_PROFILE_URL}?tab=My+counterparties`
: BUY_SELL_URL
)
}
pageTitle='Advertiser’s page'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
import AdvertiserAdvertsTable from '../AdvertiserAdvertsTable';

let mockApiValues = {
data: [{}],
isFetching: false,
isLoading: true,
loadMoreAdverts: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const CurrencyDropdown = ({ selectedCurrency, setSelectedCurrency }: TCurrencyDr
const localCurrencies = useMemo(() => {
return data?.currency_list
? data.currency_list
.sort((a, b) => a.value.localeCompare(b.value))
.sort((a, b) => (a?.value ?? '').localeCompare(b?.value ?? ''))
.sort((a, b) => {
if (a.value === selectedCurrency) return -1;
if (b.value === selectedCurrency) return 1;
if (a?.value === selectedCurrency) return -1;
if (b?.value === selectedCurrency) return 1;
return 0;
})
: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import CurrencyDropdown from '../CurrencyDropdown';

const wrapper = ({ children }: { children: JSX.Element }) => (
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<div>
<div>Click me</div>
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSortByValues } from '@/utils';
import { LabelPairedChevronDownMdRegularIcon } from '@deriv/quill-icons';
import { Button, Dropdown, useDevice } from '@deriv-com/ui';
import SortIcon from '../../../../public/ic-cashier-sort.svg';
import SortIcon from '../../../../public/ic-cashier-sort.svg?react';
import './SortDropdown.scss';

type TSortDropdownProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type TBuySellTableRowRendererProps = {
};

const BuySellTableRenderer = ({
data,
data = [],
isFetching,
isLoading,
loadMoreAdverts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ const mockUseDevice = useDevice as jest.Mock;

describe('AdConditionContentHeader', () => {
it('should render the component as expected with given type', () => {
render(<AdConditionContentHeader type='type' />);
render(<AdConditionContentHeader type='completionRates' />);
expect(screen.getByText('title')).toBeInTheDocument();
});
it('should handle clicking the tooltip icon', async () => {
mockUseDevice.mockReturnValue({ isMobile: true });
render(<AdConditionContentHeader type='type' />);
render(<AdConditionContentHeader type='completionRates' />);
await userEvent.click(screen.getByTestId('dt_ad_condition_tooltip_icon'));
const okButton = screen.getByRole('button', { name: 'OK' });
expect(okButton).toBeInTheDocument();
Expand Down
Loading

0 comments on commit 5528c57

Please sign in to comment.