mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-07 22:00:56 -04:00
fix: add test for i18n CTAs (#51164)
This commit is contained in:
@@ -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;
|
||||
|
||||
130
client/src/templates/Introduction/components/block.test.tsx
Normal file
130
client/src/templates/Introduction/components/block.test.tsx
Normal file
@@ -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('<Block />', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('The "Help us translate" badge does not appear on any English blocks', () => {
|
||||
render(
|
||||
<Provider store={createStore()}>
|
||||
<Block {...defaultProps} />
|
||||
</Provider>
|
||||
);
|
||||
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(
|
||||
<Provider store={createStore()}>
|
||||
<Block {...defaultProps} />
|
||||
</Provider>
|
||||
);
|
||||
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(
|
||||
<Provider store={createStore()}>
|
||||
<Block {...defaultProps} />
|
||||
</Provider>
|
||||
);
|
||||
expect(screen.getByText(/misc.translation-pending/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user