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

refactor: ts migration for self-exclusion-footer.js #69

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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('<SelfExclusionFooter />', () => {
let mock_context = {};
Expand All @@ -26,7 +26,7 @@ describe('<SelfExclusionFooter />', () => {
});
});
it('should not render SelfExclusionFooter component', () => {
mock_context.footer_ref = null;
(mock_context as FormikValues).footer_ref = null;

render(
<SelfExclusionContext.Provider value={mock_context}>
Expand All @@ -39,7 +39,7 @@ describe('<SelfExclusionFooter />', () => {

it('should render SelfExclusionFooter component', () => {
render(
<Formik>
<Formik initialValues={{}} onSubmit={jest.fn()}>
<SelfExclusionContext.Provider value={mock_context}>
<SelfExclusionFooter />
</SelfExclusionContext.Provider>
Expand All @@ -50,10 +50,10 @@ describe('<SelfExclusionFooter />', () => {
});

it('Should trigger click on the button', () => {
const mockGoToConfirm = mock_context.goToConfirm;
const mockGoToConfirm = (mock_context as FormikValues).goToConfirm;

render(
<Formik>
<Formik initialValues={{}} onSubmit={jest.fn()}>
<SelfExclusionContext.Provider value={mock_context}>
<SelfExclusionFooter />
</SelfExclusionContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';

type TSelfExclusionContext = {
footer_ref?: React.RefObject<HTMLElement>;
goToConfirm?: () => void;
goToConfirm?: (values: unknown) => void;
toggleArticle?: () => void;
is_app_settings?: boolean;
is_wrapper_bypassed?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const SelfExclusionFooter = () => {
primary
className='da-self-exclusion__button'
large
onClick={() => goToConfirm(values)}
onClick={() => goToConfirm?.(values)}
type='button'
>
<Localize i18n_default_text='Next' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Choose a reason for hiding this comment

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

I believe we should also add types for all context variables in self-exclusion-footer.tsx

Copy link
Owner

Choose a reason for hiding this comment

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

yes.there are some ts errors in the file.

Copy link
Author

Choose a reason for hiding this comment

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

Done Updating the codes 🙏


const SectionTitle = ({ title, has_border_line }) => {
return (
Expand Down