fix: add test for i18n CTAs (#51164)

This commit is contained in:
Riya Dhawan
2023-08-15 17:05:57 +05:30
committed by GitHub
parent da17fc6a00
commit 98c7e2e7ae
2 changed files with 133 additions and 3 deletions

View File

@@ -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;

View 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();
});
});