Skip to content

Commit

Permalink
fix(citrus-simulator-ui): fix no-data banner test
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerfluri committed Sep 17, 2024
1 parent 8e652d7 commit 87c6c51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 3 additions & 11 deletions simulator-ui/tests/helpers/helper-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,21 @@ export const mockBackendResponse = async (
});
};

export const mockErrorResponseForAllNavbarLinkedSites = async (page: Page): Promise<void> => {
export const mockResponseForAllNavbarLinkedSites = async (page: Page, responseMockFunction: (page: Page, apiLink: string) => Promise<void>): Promise<void> => {
for (const element of navbarElementLinkPairs) {
if (element.childElements) {
for (const child of element.childElements) {
if (child.apiLink) {
await mock500ErrorResponseForApiURL(page, child.apiLink);
await responseMockFunction(page, child.apiLink);
}
}
}
if (element.apiLink) {
await mock500ErrorResponseForApiURL(page, element.apiLink);
await responseMockFunction(page, element.apiLink);
}
}
};

const mock500ErrorResponseForApiURL = async (page: Page, apiLink: string): Promise<void> => {
await page.route(apiLink, async route => {
await route.fulfill({
status: 500,
});
});
};

export const goToAllNavigationTabsAndOptionallyValidateContent = async (
page: Page,
validatePageContent?: (page: Page) => Promise<void>,
Expand Down
11 changes: 10 additions & 1 deletion simulator-ui/tests/no-data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { expect, Page, test } from '@playwright/test';
import { goToAllNavigationTabsAndOptionallyValidateContent } from './helpers/helper-functions';
import {
goToAllNavigationTabsAndOptionallyValidateContent,
mockBackendResponse,
mockResponseForAllNavbarLinkedSites
} from './helpers/helper-functions';

test.beforeEach(async ({ page }) => {
await mockResponseForAllNavbarLinkedSites(page, mockEmptyResponseForApiURL)
await page.goto('http://localhost:9000/');
});

Expand All @@ -12,3 +17,7 @@ test('should show no-data-banner if there is an empty backend response on all pa
const verifyNoDataFoundBannerIsVisible = async (page: Page): Promise<void> => {
await expect(page.getByTestId('noDataFound')).toBeVisible();
};

const mockEmptyResponseForApiURL = async (page: Page, apiLink: string): Promise<void> => {
await mockBackendResponse(page, apiLink, [], { 'x-total-count': '0' })
};

0 comments on commit 87c6c51

Please sign in to comment.