diff --git a/client/src/redux/prop-types.ts b/client/src/redux/prop-types.ts index b6c83a5553f..5ca91a6cc25 100644 --- a/client/src/redux/prop-types.ts +++ b/client/src/redux/prop-types.ts @@ -47,12 +47,12 @@ export type MarkdownRemark = { }; }; -type Question = { +export type Question = { text: string; answers: string[]; solution: number; }; -type Fields = { +export type Fields = { slug: string; blockHashSlug: string; blockName: string; @@ -321,7 +321,7 @@ export type PortfolioProjectData = { description: string; }; -type FileKeyChallenge = { +export type FileKeyChallenge = { contents: string; ext: Ext; head: string; diff --git a/client/src/templates/Introduction/components/block.test.tsx b/client/src/templates/Introduction/components/block.test.tsx new file mode 100644 index 00000000000..78345bccd28 --- /dev/null +++ b/client/src/templates/Introduction/components/block.test.tsx @@ -0,0 +1,130 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import { SuperBlocks } from '../../../../../config/superblocks'; +import { createStore } from '../../../redux/create-store'; +import { + ChallengeFiles, + PrerequisiteChallenge, + Test, + Fields, + Question, + FileKeyChallenge, + BilibiliIds +} from '../../../redux/prop-types'; +import { isAuditedSuperBlock } from '../../../../../utils/is-audited'; +import Block from './block'; + +jest.mock('../../../../../utils/is-audited', () => ({ + isAuditedSuperBlock: jest.fn().mockReturnValueOnce(true) +})); + +const defaultProps = { + blockDashedName: 'test-block', + challenges: [ + { + challenge: { + block: 'testblock', + certification: 'mockCertification', + challengeOrder: 1, + challengeType: 0, + dashedName: 'mock-dashed-name', + description: 'mockDescription', + challengeFiles: {} as ChallengeFiles, + fields: {} as Fields, + forumTopicId: 12345, + guideUrl: 'https://mockurl.com', + head: ['mockHead'], + hasEditableBoundaries: false, + helpCategory: 'mockHelpCategory', + id: 'mockId', + instructions: 'mockInstructions', + isComingSoon: false, + internal: { + content: 'mockContent', + contentDigest: 'mockContentDigest', + description: 'mockInternalDescription', + fieldOwners: ['mockOwner'], + ignoreType: null, + mediaType: 'mockMediaType', + owner: 'mockOwner', + type: 'mockType' + }, + notes: 'mockNotes', + prerequisites: [] as PrerequisiteChallenge[], + removeComments: false, + isLocked: false, + isPrivate: false, + order: 1, + question: {} as Question, + assignments: ['mockAssignment'], + required: [], + solutions: { + ['indexhtml']: {} as FileKeyChallenge, + ['scriptjs']: {} as FileKeyChallenge, + ['stylescss']: {} as FileKeyChallenge, + ['indexjsx']: {} as FileKeyChallenge + }, + sourceInstanceName: 'mockSourceInstanceName', + superOrder: 1, + superBlock: SuperBlocks.UpcomingPython, + tail: ['mockTail'], + template: 'mockTemplate', + tests: [] as Test[], + time: 'mockTime', + title: 'mockTitle', + translationPending: false, + url: 'https://mockurl.com', + usesMultifileEditor: false, + videoId: 'mockVideoId', + videoLocaleIds: {}, + bilibiliIds: {} as BilibiliIds, + videoUrl: 'https://mockvideourl.com' + } + } + ], + completedChallengeIds: ['testchallengeIds'], + isExpanded: false, + t: jest.fn((key: string) => [key]), + superBlock: SuperBlocks.RespWebDesign, + toggleBlock: jest.fn() +}; + +describe('', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + it('The "Help us translate" badge does not appear on any English blocks', () => { + render( + + + + ); + expect( + screen.queryByText(/misc.translation-pending/) + ).not.toBeInTheDocument(); + }); + + it(`The "Help us translate" badge does not appear on any i18n blocks when the superblock is audited`, () => { + (isAuditedSuperBlock as jest.Mock).mockReturnValue(true); + render( + + + + ); + expect( + screen.queryByText(/misc.translation-pending/) + ).not.toBeInTheDocument(); + }); + + it(`The "Help us translate" badge does appear on i18n blocks when the superblock is not audited`, () => { + (isAuditedSuperBlock as jest.Mock).mockReturnValue(false); + render( + + + + ); + expect(screen.getByText(/misc.translation-pending/)).toBeInTheDocument(); + }); +});