feat(frontend-test-utils): start migrating renderInTestApp

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2023-12-01 12:07:53 +01:00
parent 0da9a65b89
commit 5adfd1447f
5 changed files with 75 additions and 3 deletions
@@ -3,6 +3,8 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
/// <reference types="react" />
import { ErrorWithContext } from '@backstage/test-utils';
import { ExtensionDefinition } from '@backstage/frontend-plugin-api';
import { JsonObject } from '@backstage/types';
@@ -63,6 +65,9 @@ export { MockStorageApi };
export { MockStorageBucket };
// @public
export function renderInTestApp(element: JSX.Element): RenderResult;
export { setupRequestMockHandlers };
export { TestApiProvider };
@@ -18,3 +18,5 @@ export {
createExtensionTester,
type ExtensionTester,
} from './createExtensionTester';
export { renderInTestApp } from './renderInTestApp';
@@ -0,0 +1,27 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { screen } from '@testing-library/react';
import { renderInTestApp } from './renderInTestApp';
describe('renderInTestApp', () => {
it('should render the given component in a page', async () => {
const Component = () => <div>Test</div>;
renderInTestApp(<Component />);
expect(screen.getByText('Test')).toBeInTheDocument();
});
});
@@ -0,0 +1,38 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
coreExtensionData,
createExtension,
} from '@backstage/frontend-plugin-api';
import { createExtensionTester } from './createExtensionTester';
/**
* @public
* Renders the given element in a test app, for use in unit tests.
*/
export function renderInTestApp(element: JSX.Element) {
const extension = createExtension({
namespace: 'test',
attachTo: { id: 'core', input: 'root' },
output: {
element: coreExtensionData.reactElement,
},
factory: () => ({ element }),
});
const tester = createExtensionTester(extension);
return tester.render();
}
+3 -3
View File
@@ -3916,7 +3916,7 @@ __metadata:
languageName: node
linkType: hard
"@backstage/core-components@npm:^0.13.7, @backstage/core-components@npm:^0.13.8":
"@backstage/core-components@npm:^0.13.8":
version: 0.13.8
resolution: "@backstage/core-components@npm:0.13.8"
dependencies:
@@ -4042,7 +4042,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/core-plugin-api@npm:^1.3.0, @backstage/core-plugin-api@npm:^1.5.0, @backstage/core-plugin-api@npm:^1.7.0, @backstage/core-plugin-api@npm:^1.8.0":
"@backstage/core-plugin-api@npm:^1.3.0, @backstage/core-plugin-api@npm:^1.5.0, @backstage/core-plugin-api@npm:^1.8.0":
version: 1.8.0
resolution: "@backstage/core-plugin-api@npm:1.8.0"
dependencies:
@@ -5950,7 +5950,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-catalog-react@npm:^1.2.4, @backstage/plugin-catalog-react@npm:^1.8.5, @backstage/plugin-catalog-react@npm:^1.9.1":
"@backstage/plugin-catalog-react@npm:^1.2.4, @backstage/plugin-catalog-react@npm:^1.9.1":
version: 1.9.1
resolution: "@backstage/plugin-catalog-react@npm:1.9.1"
dependencies: