feat: support i18n for core component

Signed-off-by: rui ma <ruima@alauda.io>
This commit is contained in:
rui ma
2024-01-08 23:55:00 +08:00
parent 94c4fe2782
commit ff7e12632d
37 changed files with 575 additions and 248 deletions
+1
View File
@@ -52,6 +52,7 @@
"@backstage/cli": "workspace:^",
"@backstage/core-app-api": "workspace:^",
"@backstage/dev-utils": "workspace:^",
"@backstage/test-utils": "workspace:^",
"@testing-library/dom": "^9.0.0",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^14.0.0",
@@ -21,6 +21,10 @@ import { Features } from './Features';
import { mockCalverProject } from '../test-helpers/test-helpers';
import { TEST_IDS } from '../test-helpers/test-ids';
import { mockApiClient } from '../test-helpers/mock-api-client';
import { MockErrorApi, TestApiProvider } from '@backstage/test-utils';
import { translationApiRef } from '@backstage/core-plugin-api/alpha';
import { MockTranslationApi } from '@backstage/test-utils';
import { errorApiRef } from '@backstage/core-plugin-api';
jest.mock('@backstage/core-plugin-api', () => ({
...jest.requireActual('@backstage/core-plugin-api'),
@@ -35,18 +39,26 @@ jest.mock('../contexts/ProjectContext', () => ({
describe('Features', () => {
it('should omit features omitted via configuration', async () => {
const { getByTestId } = render(
<Features
features={{
info: { omit: false },
createRc: { omit: true },
promoteRc: { omit: true },
patch: { omit: true },
custom: {
// shouldn't trigger "missing key" warning in console
factory: () => [<div>Custom 1</div>, <div>Custom 2</div>],
},
}}
/>,
<TestApiProvider
apis={[
[translationApiRef, MockTranslationApi.create()],
[errorApiRef, new MockErrorApi()],
]}
>
<Features
features={{
info: { omit: false },
createRc: { omit: true },
promoteRc: { omit: true },
patch: { omit: true },
custom: {
// shouldn't trigger "missing key" warning in console
factory: () => [<div>Custom 1</div>, <div>Custom 2</div>],
},
}}
/>
,
</TestApiProvider>,
);
await waitFor(() => getByTestId(TEST_IDS.info.info));
@@ -15,14 +15,13 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import {
mockCalverProject,
mockReleaseBranch,
mockReleaseCandidateCalver,
} from '../../test-helpers/test-helpers';
import { Info } from './Info';
import { renderInTestApp } from '@backstage/test-utils';
jest.mock('../../contexts/ProjectContext', () => ({
useProjectContext: () => ({
@@ -32,7 +31,7 @@ jest.mock('../../contexts/ProjectContext', () => ({
describe('Info', () => {
it('should return early if no latestRelease exists', async () => {
const { findByText } = render(
const { findByText } = await renderInTestApp(
<Info
latestRelease={mockReleaseCandidateCalver}
releaseBranch={mockReleaseBranch}
@@ -15,7 +15,7 @@
*/
import React from 'react';
import { render, waitFor, screen } from '@testing-library/react';
import { waitFor, screen, render } from '@testing-library/react';
import {
mockBumpedTag,
@@ -29,6 +29,10 @@ import {
import { mockApiClient } from '../../test-helpers/mock-api-client';
import { PatchBody } from './PatchBody';
import { TEST_IDS } from '../../test-helpers/test-ids';
import { MockErrorApi, TestApiProvider } from '@backstage/test-utils';
import { translationApiRef } from '@backstage/core-plugin-api/alpha';
import { MockTranslationApi } from '@backstage/test-utils/alpha';
import { errorApiRef } from '@backstage/core-plugin-api';
jest.mock('@backstage/core-plugin-api', () => ({
...jest.requireActual('@backstage/core-plugin-api'),
@@ -56,13 +60,21 @@ describe('PatchBody', () => {
});
const { getByTestId } = render(
<PatchBody
bumpedTag={mockBumpedTag}
latestRelease={mockReleaseCandidateCalver}
releaseBranch={mockReleaseBranch}
tagParts={mockTagParts}
ctaMessage={mockCtaMessage}
/>,
<TestApiProvider
apis={[
[translationApiRef, MockTranslationApi.create()],
[errorApiRef, new MockErrorApi()],
]}
>
<PatchBody
bumpedTag={mockBumpedTag}
latestRelease={mockReleaseCandidateCalver}
releaseBranch={mockReleaseBranch}
tagParts={mockTagParts}
ctaMessage={mockCtaMessage}
/>
,
</TestApiProvider>,
);
expect(getByTestId(TEST_IDS.patch.loading)).toBeInTheDocument();
@@ -74,13 +86,20 @@ describe('PatchBody', () => {
it('should render not-prerelease description', async () => {
const { getByTestId } = render(
<PatchBody
latestRelease={mockReleaseVersionCalver}
releaseBranch={mockReleaseBranch}
bumpedTag={mockBumpedTag}
tagParts={mockTagParts}
ctaMessage={mockCtaMessage}
/>,
<TestApiProvider
apis={[
[translationApiRef, MockTranslationApi.create()],
[errorApiRef, new MockErrorApi()],
]}
>
<PatchBody
latestRelease={mockReleaseVersionCalver}
releaseBranch={mockReleaseBranch}
bumpedTag={mockBumpedTag}
tagParts={mockTagParts}
ctaMessage={mockCtaMessage}
/>
</TestApiProvider>,
);
expect(getByTestId(TEST_IDS.patch.loading)).toBeInTheDocument();