From 637581652bfaf60a87b72a38e927e21f97595cd7 Mon Sep 17 00:00:00 2001 From: tay suisin Date: Thu, 22 Dec 2022 17:43:47 +0800 Subject: [PATCH 1/2] refactor: ts migration for self-exclusion-footer.js --- ...footer.spec.js => self-exclusion-footer.spec.tsx} | 12 ++++++------ ...xclusion-footer.jsx => self-exclusion-footer.tsx} | 0 .../self-exclusion/self-exclusion-inputs.jsx | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename packages/account/src/Components/self-exclusion/__tests__/{self-exclusion-footer.spec.js => self-exclusion-footer.spec.tsx} (87%) rename packages/account/src/Components/self-exclusion/{self-exclusion-footer.jsx => self-exclusion-footer.tsx} (100%) diff --git a/packages/account/src/Components/self-exclusion/__tests__/self-exclusion-footer.spec.js b/packages/account/src/Components/self-exclusion/__tests__/self-exclusion-footer.spec.tsx similarity index 87% rename from packages/account/src/Components/self-exclusion/__tests__/self-exclusion-footer.spec.js rename to packages/account/src/Components/self-exclusion/__tests__/self-exclusion-footer.spec.tsx index a75a0d0e9ea5..b6c55bf88f50 100644 --- a/packages/account/src/Components/self-exclusion/__tests__/self-exclusion-footer.spec.js +++ b/packages/account/src/Components/self-exclusion/__tests__/self-exclusion-footer.spec.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Formik } from 'formik'; +import { Formik, FormikValues } from 'formik'; import * as formik from 'formik'; import { fireEvent, render, screen } from '@testing-library/react'; import SelfExclusionContext from '../self-exclusion-context'; @@ -8,7 +8,7 @@ import SelfExclusionFooter from '../self-exclusion-footer'; const portal_root = document.createElement('div'); document.body.appendChild(portal_root); -const mockUseFormikContext = jest.spyOn(formik, 'useFormikContext'); +const mockUseFormikContext = jest.spyOn(formik, 'useFormikContext') as any; describe('', () => { let mock_context = {}; @@ -26,7 +26,7 @@ describe('', () => { }); }); it('should not render SelfExclusionFooter component', () => { - mock_context.footer_ref = null; + (mock_context as FormikValues).footer_ref = null; render( @@ -39,7 +39,7 @@ describe('', () => { it('should render SelfExclusionFooter component', () => { render( - + @@ -50,10 +50,10 @@ describe('', () => { }); it('Should trigger click on the button', () => { - const mockGoToConfirm = mock_context.goToConfirm; + const mockGoToConfirm = (mock_context as FormikValues).goToConfirm; render( - + diff --git a/packages/account/src/Components/self-exclusion/self-exclusion-footer.jsx b/packages/account/src/Components/self-exclusion/self-exclusion-footer.tsx similarity index 100% rename from packages/account/src/Components/self-exclusion/self-exclusion-footer.jsx rename to packages/account/src/Components/self-exclusion/self-exclusion-footer.tsx diff --git a/packages/account/src/Components/self-exclusion/self-exclusion-inputs.jsx b/packages/account/src/Components/self-exclusion/self-exclusion-inputs.jsx index 110df8870525..a0ff2666a7e3 100644 --- a/packages/account/src/Components/self-exclusion/self-exclusion-inputs.jsx +++ b/packages/account/src/Components/self-exclusion/self-exclusion-inputs.jsx @@ -5,7 +5,7 @@ import { getBrandWebsiteName, epochToMoment, toMoment, PlatformContext, isMobile import { Localize, localize } from '@deriv/translations'; import { Field, useFormikContext } from 'formik'; import SelfExclusionContext from './self-exclusion-context'; -import SelfExclusionFooter from './self-exclusion-footer.jsx'; +import SelfExclusionFooter from './self-exclusion-footer'; const SectionTitle = ({ title, has_border_line }) => { return ( From 42ce3017921ee5e436deb05c755d3a24c4a6da5f Mon Sep 17 00:00:00 2001 From: tay suisin Date: Tue, 3 Jan 2023 14:12:59 +0800 Subject: [PATCH 2/2] refactor: fix ts error --- .../src/Components/self-exclusion/self-exclusion-context.tsx | 2 +- .../src/Components/self-exclusion/self-exclusion-footer.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/Components/self-exclusion/self-exclusion-context.tsx b/packages/account/src/Components/self-exclusion/self-exclusion-context.tsx index a7fafbda2f61..c0e9a6746e40 100644 --- a/packages/account/src/Components/self-exclusion/self-exclusion-context.tsx +++ b/packages/account/src/Components/self-exclusion/self-exclusion-context.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; type TSelfExclusionContext = { footer_ref?: React.RefObject; - goToConfirm?: () => void; + goToConfirm?: (values: unknown) => void; toggleArticle?: () => void; is_app_settings?: boolean; is_wrapper_bypassed?: boolean; diff --git a/packages/account/src/Components/self-exclusion/self-exclusion-footer.tsx b/packages/account/src/Components/self-exclusion/self-exclusion-footer.tsx index 9c07c2fc9621..44bc4a4029da 100644 --- a/packages/account/src/Components/self-exclusion/self-exclusion-footer.tsx +++ b/packages/account/src/Components/self-exclusion/self-exclusion-footer.tsx @@ -22,7 +22,7 @@ const SelfExclusionFooter = () => { primary className='da-self-exclusion__button' large - onClick={() => goToConfirm(values)} + onClick={() => goToConfirm?.(values)} type='button' >