api-docs: fix flaky tests

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-10-03 19:26:14 +02:00
parent 1fd53fa0c6
commit db647a72fe
@@ -52,6 +52,10 @@ describe('DefaultApiExplorerPage', () => {
kind: 'API',
metadata: {
name: 'Entity1',
annotations: {
'backstage.io/view-url': 'viewurl',
'backstage.io/edit-url': 'editurl',
},
},
spec: { type: 'openapi' },
},
@@ -63,6 +67,11 @@ describe('DefaultApiExplorerPage', () => {
getEntityFacets: async () => ({
facets: { 'relations.ownedBy': [] },
}),
queryEntities: async () => ({
items: [],
pageInfo: {},
totalItems: 0,
}),
};
const configApi: ConfigApi = new ConfigReader({
@@ -152,37 +161,39 @@ describe('DefaultApiExplorerPage', () => {
it('should render the default actions of an item in the grid', async () => {
await renderWrapped(<DefaultApiExplorerPage />);
expect(await screen.findByText(/All apis \(1\)/)).toBeInTheDocument();
expect(await screen.findByTitle(/View/)).toBeInTheDocument();
expect(await screen.findByTitle(/View/)).toBeInTheDocument();
expect(await screen.findByTitle(/Edit/)).toBeInTheDocument();
expect(await screen.findByTitle(/Add to favorites/)).toBeInTheDocument();
await waitFor(() => {
expect(screen.getByText(/All apis \(1\)/)).toBeInTheDocument();
});
await waitFor(() => {
expect(screen.getByRole('button', { name: /view/i })).toBeInTheDocument();
});
expect(screen.getByRole('button', { name: /edit/i })).toBeInTheDocument();
expect(screen.getByTitle(/Add to favorites/)).toBeInTheDocument();
});
it('should render the custom actions of an item passed as prop', async () => {
const actions: TableProps<CatalogTableRow>['actions'] = [
() => {
return {
icon: () => <DashboardIcon fontSize="small" />,
tooltip: 'Foo Action',
disabled: false,
onClick: () => jest.fn(),
};
{
icon: () => <DashboardIcon fontSize="small" />,
tooltip: 'Foo Action',
disabled: false,
onClick: jest.fn(),
},
() => {
return {
icon: () => <DashboardIcon fontSize="small" />,
tooltip: 'Bar Action',
disabled: true,
onClick: () => jest.fn(),
};
{
icon: () => <DashboardIcon fontSize="small" />,
tooltip: 'Bar Action',
disabled: true,
onClick: jest.fn(),
},
];
await renderWrapped(<DefaultApiExplorerPage actions={actions} />);
expect(await screen.findByText(/All apis \(1\)/)).toBeInTheDocument();
expect(await screen.findByTitle(/Foo Action/)).toBeInTheDocument();
expect(await screen.findByTitle(/Bar Action/)).toBeInTheDocument();
expect((await screen.findByTitle(/Bar Action/)).firstChild).toBeDisabled();
await waitFor(() => {
expect(screen.getByText(/All apis \(1\)/)).toBeInTheDocument();
});
expect(screen.getByTitle(/Foo Action/)).toBeInTheDocument();
expect(screen.getByTitle(/Bar Action/)).toBeInTheDocument();
expect(screen.getByTitle(/Bar Action/).firstChild).toBeDisabled();
});
});