fix(catalog): fix flaky entity page test by providing initial route and in-memory catalog
The test rendered at '/' instead of a URL matching the entity route pattern, causing useEntityFromUrl to sometimes fail to extract route params. Use initialRouteEntries to start at the correct entity URL, and switch from catalogApiMock.mock() to catalogApiMock() for a working in-memory catalog client. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -28,7 +28,6 @@ import {
|
||||
} from '@backstage/plugin-catalog-react/alpha';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
import {
|
||||
catalogApiRef,
|
||||
entityRouteRef,
|
||||
MockStarredEntitiesApi,
|
||||
starredEntitiesApiRef,
|
||||
@@ -108,8 +107,8 @@ describe('Entity page', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const mockCatalogApi = catalogApiMock.mock({
|
||||
getEntityByRef: async () => entityMock,
|
||||
const mockCatalogApi = catalogApiMock({
|
||||
entities: [entityMock as Entity],
|
||||
});
|
||||
|
||||
const mockStarredEntitiesApi = new MockStarredEntitiesApi();
|
||||
@@ -152,10 +151,8 @@ describe('Entity page', () => {
|
||||
.add(apidocsEntityContent);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -199,10 +196,8 @@ describe('Entity page', () => {
|
||||
.add(apidocsEntityContent);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -239,10 +234,8 @@ describe('Entity page', () => {
|
||||
});
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -292,10 +285,8 @@ describe('Entity page', () => {
|
||||
});
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -333,10 +324,8 @@ describe('Entity page', () => {
|
||||
});
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -367,10 +356,8 @@ describe('Entity page', () => {
|
||||
.add(overviewEntityContent);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -413,10 +400,8 @@ describe('Entity page', () => {
|
||||
.add(apidocsEntityContent);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -449,10 +434,8 @@ describe('Entity page', () => {
|
||||
.add(apidocsEntityContent);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -490,10 +473,8 @@ describe('Entity page', () => {
|
||||
.add(apidocsEntityContent);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -539,10 +520,8 @@ describe('Entity page', () => {
|
||||
.add(apidocsEntityContent);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -588,10 +567,8 @@ describe('Entity page', () => {
|
||||
});
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -625,10 +602,8 @@ describe('Entity page', () => {
|
||||
);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -664,10 +639,8 @@ describe('Entity page', () => {
|
||||
).add(customEntityHeader);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -723,10 +696,8 @@ describe('Entity page', () => {
|
||||
).add(menuItem);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -778,10 +749,8 @@ describe('Entity page', () => {
|
||||
).add(menuItem);
|
||||
|
||||
await renderInTestApp(tester.reactElement(), {
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
apis: [mockCatalogApi, [starredEntitiesApiRef, mockStarredEntitiesApi]],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
config: {
|
||||
app: {
|
||||
title: 'Custom app',
|
||||
@@ -882,9 +851,10 @@ describe('Entity page', () => {
|
||||
convertLegacyRouteRef(entityRouteRef),
|
||||
},
|
||||
apis: [
|
||||
[catalogApiRef, mockCatalogApi],
|
||||
mockCatalogApi,
|
||||
[starredEntitiesApiRef, mockStarredEntitiesApi],
|
||||
],
|
||||
initialRouteEntries: ['/catalog/default/component/artist-lookup'],
|
||||
});
|
||||
|
||||
await userEvent.click(await screen.findByTestId('menu-button'));
|
||||
|
||||
Reference in New Issue
Block a user