diff --git a/simulator-ui/tests/helpers/helper-functions.ts b/simulator-ui/tests/helpers/helper-functions.ts index 034a504a..94f56d9b 100644 --- a/simulator-ui/tests/helpers/helper-functions.ts +++ b/simulator-ui/tests/helpers/helper-functions.ts @@ -58,29 +58,21 @@ export const mockBackendResponse = async ( }); }; -export const mockErrorResponseForAllNavbarLinkedSites = async (page: Page): Promise => { +export const mockResponseForAllNavbarLinkedSites = async (page: Page, responseMockFunction: (page: Page, apiLink: string) => Promise): Promise => { 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 => { - await page.route(apiLink, async route => { - await route.fulfill({ - status: 500, - }); - }); -}; - export const goToAllNavigationTabsAndOptionallyValidateContent = async ( page: Page, validatePageContent?: (page: Page) => Promise, diff --git a/simulator-ui/tests/no-data.spec.ts b/simulator-ui/tests/no-data.spec.ts index 1a3affa0..c5b916c4 100644 --- a/simulator-ui/tests/no-data.spec.ts +++ b/simulator-ui/tests/no-data.spec.ts @@ -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/'); }); @@ -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 => { await expect(page.getByTestId('noDataFound')).toBeVisible(); }; + +const mockEmptyResponseForApiURL = async (page: Page, apiLink: string): Promise => { + await mockBackendResponse(page, apiLink, [], { 'x-total-count': '0' }) +};