From 213f867afab3a13b4bae81662925d76aba9a8701 Mon Sep 17 00:00:00 2001 From: muellerfluri Date: Thu, 26 Sep 2024 15:52:46 +0200 Subject: [PATCH] fix(citrus-simulator-ui): parameterize and fix tests for 500 error in error-banner.spec.ts --- simulator-ui/tests/error-banner.spec.ts | 36 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/simulator-ui/tests/error-banner.spec.ts b/simulator-ui/tests/error-banner.spec.ts index 90abdb62..6870f456 100644 --- a/simulator-ui/tests/error-banner.spec.ts +++ b/simulator-ui/tests/error-banner.spec.ts @@ -1,25 +1,41 @@ import { expect, Page, test } from '@playwright/test'; import { - goToAllNavigationTabsAndOptionallyValidateContent, - mockResponseForAllNavbarLinkedSites + mockResponseForAllNavbarLinkedSites, navbarElementLinkPairs } from './helpers/helper-functions'; +import {NavbarElementLinkPair} from "./helpers/helper-interfaces"; -test.beforeEach(async ({ page }) => { - await page.goto('http://localhost:9000/'); -}); +const goToSiteAndVerifyErrorBannerIsVisible = (site: NavbarElementLinkPair): void => { + test(`${site.testName}`, async ({ page }) => { + if(site.apiLink && site.linkSuffix) { + await mock500ErrorResponseForApiURL(page, site.apiLink); + await page.goto(`http://localhost:9000${site.linkSuffix}`); + await expect(page.getByTestId('error')).toBeVisible(); + } + }); +} -test('should show error banner if there is an error code in the backend response while loading any page', async ({ page }) => { - await mockResponseForAllNavbarLinkedSites(page, mock500ErrorResponseForApiURL); - await goToAllNavigationTabsAndOptionallyValidateContent(page, verifyErrorBannerIsVisible); -}); -const verifyErrorBannerIsVisible = async (pageToPass: Page): Promise => await expect(pageToPass.getByTestId('error')).toBeVisible(); +test.describe('should show error banner if there is a 500 error returned while loading any page', async () => { + test.beforeEach(async ({ page }) => { + await mockResponseForAllNavbarLinkedSites(page, mock500ErrorResponseForApiURL); + }); + + navbarElementLinkPairs.forEach((element: NavbarElementLinkPair) => { + if(element.childElements){ + for(const child of element.childElements){ + goToSiteAndVerifyErrorBannerIsVisible(child); + } + } + goToSiteAndVerifyErrorBannerIsVisible(element); + }); +}); const mock500ErrorResponseForApiURL = async (page: Page, apiLink: string): Promise => { await page.route(apiLink, async route => { await route.fulfill({ status: 500, + body: JSON.stringify({"message": "hello"}), }); }); };