implement the beginnings of mockApis

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-10-08 17:03:22 +02:00
parent f91809d6f6
commit 9cc7dd6cfd
45 changed files with 632 additions and 299 deletions
+2 -2
View File
@@ -18,7 +18,7 @@ import { UrlPatternDiscovery } from '@backstage/core-app-api';
import { IdentityApi } from '@backstage/core-plugin-api';
import { NotFoundError } from '@backstage/errors';
import { fetchEventSource } from '@microsoft/fetch-event-source';
import { MockConfigApi, MockFetchApi } from '@backstage/test-utils';
import { mockApis, MockFetchApi } from '@backstage/test-utils';
import { TechDocsStorageClient } from './client';
jest.mock('@microsoft/fetch-event-source');
@@ -34,7 +34,7 @@ const mockEntity = {
describe('TechDocsStorageClient', () => {
const mockBaseUrl = 'http://backstage:9191/api/techdocs';
const configApi = new MockConfigApi({});
const configApi = mockApis.config();
const discoveryApi = UrlPatternDiscovery.compile(mockBaseUrl);
const identityApi: jest.Mocked<IdentityApi> = {
getCredentials: jest.fn(),
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { scmIntegrationsApiRef } from '@backstage/integration-react';
import { entityRouteRef } from '@backstage/plugin-catalog-react';
import {
MockConfigApi,
mockApis,
renderInTestApp,
TestApiProvider,
} from '@backstage/test-utils';
@@ -106,10 +107,8 @@ jest.mock('@backstage/core-components', () => ({
Page: jest.fn(),
}));
const configApi = new MockConfigApi({
app: {
baseUrl: 'http://localhost:3000',
},
const configApi = mockApis.config({
data: { app: { baseUrl: 'http://localhost:3000' } },
});
const Wrapper = ({ children }: { children: React.ReactNode }) => {
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import {
MockConfigApi,
mockApis,
renderInTestApp,
TestApiProvider,
} from '@backstage/test-utils';
@@ -55,16 +56,7 @@ describe('useNavigateUrl', () => {
const baseUrl = 'http://localhost:3000';
await renderInTestApp(
<TestApiProvider
apis={[
[
configApiRef,
new MockConfigApi({
app: {
baseUrl,
},
}),
],
]}
apis={[[configApiRef, mockApis.config({ data: { app: { baseUrl } } })]]}
>
<Component to={`${baseUrl}/test`} />
</TestApiProvider>,
@@ -75,16 +67,7 @@ describe('useNavigateUrl', () => {
const baseUrl = 'http://localhost:3000/instance';
await renderInTestApp(
<TestApiProvider
apis={[
[
configApiRef,
new MockConfigApi({
app: {
baseUrl,
},
}),
],
]}
apis={[[configApiRef, mockApis.config({ data: { app: { baseUrl } } })]]}
>
<Component to={`${baseUrl}/test`} />
</TestApiProvider>,
@@ -95,16 +78,7 @@ describe('useNavigateUrl', () => {
const baseUrl = 'http://localhost:3000';
await renderInTestApp(
<TestApiProvider
apis={[
[
configApiRef,
new MockConfigApi({
app: {
baseUrl,
},
}),
],
]}
apis={[[configApiRef, mockApis.config({ data: { app: { baseUrl } } })]]}
>
<Component to="/test" />
</TestApiProvider>,