diff --git a/client/src/templates/Introduction/components/__snapshots__/block-intros.test.tsx.snap b/client/src/templates/Introduction/components/__snapshots__/block-intros.test.tsx.snap new file mode 100644 index 00000000000..4a813d8c8f4 --- /dev/null +++ b/client/src/templates/Introduction/components/__snapshots__/block-intros.test.tsx.snap @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` matches snapshot 1`] = ` +
+

+

+

+`; diff --git a/client/src/templates/Introduction/components/block-intros.test.tsx b/client/src/templates/Introduction/components/block-intros.test.tsx new file mode 100644 index 00000000000..2197c3016a6 --- /dev/null +++ b/client/src/templates/Introduction/components/block-intros.test.tsx @@ -0,0 +1,13 @@ +import React from 'react'; +import renderer from 'react-test-renderer'; + +import { BlockIntros } from './block'; + +const arrString = ['first paragraph', 'second paragraph']; + +describe('', () => { + it('matches snapshot', () => { + const tree = renderer.create(); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/client/src/templates/Introduction/components/block.tsx b/client/src/templates/Introduction/components/block.tsx index 676cd665e60..ae3ce857a52 100644 --- a/client/src/templates/Introduction/components/block.tsx +++ b/client/src/templates/Introduction/components/block.tsx @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import type { TFunction } from 'i18next'; +import type { DefaultTFuncReturn, TFunction } from 'i18next'; import { withTranslation } from 'react-i18next'; import { ProgressBar } from '@freecodecamp/react-bootstrap'; import { connect } from 'react-redux'; @@ -60,6 +60,17 @@ interface BlockProps { t: TFunction; toggleBlock: typeof toggleBlock; } + +export const BlockIntros = ({ intros }: { intros: string[] }): JSX.Element => { + return ( +
+ {intros.map((title, i) => ( +

+ ))} +

+ ); +}; + class Block extends Component { static displayName: string; constructor(props: BlockProps) { @@ -82,16 +93,6 @@ class Block extends Component { ); } - renderBlockIntros(arr: string[]): JSX.Element { - return ( -
- {arr.map((str, i) => ( -

- ))} -

- ); - } - render(): JSX.Element { const { blockDashedName, @@ -130,9 +131,12 @@ class Block extends Component { }); const blockTitle = t(`intro:${superBlock}.blocks.${blockDashedName}.title`); - const blockIntroArr = [ - t(`intro:${superBlock}.blocks.${blockDashedName}.intro`) - ]; + // the real type of TFunction is the type below, because intro can be an array of strings + // type RealTypeOFTFunction = TFunction & ((key: string) => string[]); + // But changing the type will require refactoring that isn't worth it for a wrong type. + const blockIntroArr = t( + `intro:${superBlock}.blocks.${blockDashedName}.intro` + ); const expandText = t('intro:misc-text.expand'); const collapseText = t('intro:misc-text.collapse'); @@ -167,7 +171,7 @@ class Block extends Component { )} - {this.renderBlockIntros(blockIntroArr)} +