use the catalog mock in more tests
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { Content } from './Content';
|
||||
import React from 'react';
|
||||
import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
|
||||
const docsEntities = [
|
||||
{
|
||||
@@ -34,20 +35,14 @@ const docsEntities = [
|
||||
];
|
||||
|
||||
describe('<FeaturedDocsCard />', () => {
|
||||
const mockCatalogApi = {
|
||||
getEntities: jest
|
||||
.fn()
|
||||
.mockImplementation(async () => ({ items: docsEntities })),
|
||||
};
|
||||
let Wrapper: React.ComponentType<React.PropsWithChildren<{}>>;
|
||||
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
|
||||
<TestApiProvider
|
||||
apis={[[catalogApiRef, catalogApiMock({ entities: docsEntities })]]}
|
||||
>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
);
|
||||
|
||||
beforeAll(() => {
|
||||
Wrapper = ({ children }: { children?: React.ReactNode }) => (
|
||||
<TestApiProvider apis={[[catalogApiRef, mockCatalogApi]]}>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
);
|
||||
});
|
||||
it('should show expected featured doc and title', async () => {
|
||||
const { getByTestId, getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
|
||||
@@ -18,6 +18,7 @@ import { FeaturedDocsCard } from '../../plugin';
|
||||
import React, { ComponentType, PropsWithChildren } from 'react';
|
||||
import { wrapInTestApp, TestApiProvider } from '@backstage/test-utils';
|
||||
import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
import Grid from '@material-ui/core/Grid';
|
||||
|
||||
const docsEntities = [
|
||||
@@ -36,16 +37,14 @@ const docsEntities = [
|
||||
},
|
||||
];
|
||||
|
||||
const mockCatalogApi = {
|
||||
getEntities: async () => ({ items: docsEntities }),
|
||||
};
|
||||
|
||||
export default {
|
||||
title: 'Plugins/Home/Components/FeaturedDocsCard',
|
||||
decorators: [
|
||||
(Story: ComponentType<PropsWithChildren<{}>>) =>
|
||||
wrapInTestApp(
|
||||
<TestApiProvider apis={[[catalogApiRef, mockCatalogApi]]}>
|
||||
<TestApiProvider
|
||||
apis={[[catalogApiRef, catalogApiMock({ entities: docsEntities })]]}
|
||||
>
|
||||
<Story />
|
||||
</TestApiProvider>,
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
|
||||
import {
|
||||
catalogApiRef,
|
||||
@@ -20,6 +21,7 @@ import {
|
||||
MockStarredEntitiesApi,
|
||||
entityRouteRef,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
import React from 'react';
|
||||
import { Content } from './Content';
|
||||
|
||||
@@ -48,11 +50,7 @@ describe('StarredEntitiesContent', () => {
|
||||
mockedApi.toggleStarred('component:default/mock-starred-entity-2');
|
||||
mockedApi.toggleStarred('component:default/mock-starred-entity-3');
|
||||
|
||||
const mockCatalogApi = {
|
||||
getEntitiesByRefs: jest
|
||||
.fn()
|
||||
.mockImplementation(async () => ({ items: entities })),
|
||||
};
|
||||
const mockCatalogApi = catalogApiMock({ entities });
|
||||
|
||||
const { getByText, queryByText } = await renderInTestApp(
|
||||
<TestApiProvider
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
MockStarredEntitiesApi,
|
||||
entityRouteRef,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
import Grid from '@material-ui/core/Grid';
|
||||
import React, { ComponentType, PropsWithChildren } from 'react';
|
||||
|
||||
@@ -66,9 +67,7 @@ const entities = [
|
||||
},
|
||||
];
|
||||
|
||||
const mockCatalogApi = {
|
||||
getEntities: async () => ({ items: entities }),
|
||||
};
|
||||
const mockCatalogApi = catalogApiMock({ entities });
|
||||
|
||||
export default {
|
||||
title: 'Plugins/Home/Components/StarredEntities',
|
||||
|
||||
Reference in New Issue
Block a user