From 4d1f8bbb95557aa9a117be7a81ba2cccd9e12396 Mon Sep 17 00:00:00 2001 From: muellerfluri Date: Tue, 17 Sep 2024 14:18:53 +0200 Subject: [PATCH] refactor(citrus-simulator-ui): refactor error-banner test --- simulator-ui/tests/error-banner.spec.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/simulator-ui/tests/error-banner.spec.ts b/simulator-ui/tests/error-banner.spec.ts index 06674d13..90abdb62 100644 --- a/simulator-ui/tests/error-banner.spec.ts +++ b/simulator-ui/tests/error-banner.spec.ts @@ -1,14 +1,25 @@ import { expect, Page, test } from '@playwright/test'; -import { goToAllNavigationTabsAndOptionallyValidateContent, mockErrorResponseForAllNavbarLinkedSites } from './helpers/helper-functions'; +import { + goToAllNavigationTabsAndOptionallyValidateContent, + mockResponseForAllNavbarLinkedSites +} from './helpers/helper-functions'; test.beforeEach(async ({ page }) => { await page.goto('http://localhost:9000/'); }); test('should show error banner if there is an error code in the backend response while loading any page', async ({ page }) => { - await mockErrorResponseForAllNavbarLinkedSites(page); + await mockResponseForAllNavbarLinkedSites(page, mock500ErrorResponseForApiURL); await goToAllNavigationTabsAndOptionallyValidateContent(page, verifyErrorBannerIsVisible); }); const verifyErrorBannerIsVisible = async (pageToPass: Page): Promise => await expect(pageToPass.getByTestId('error')).toBeVisible(); + +const mock500ErrorResponseForApiURL = async (page: Page, apiLink: string): Promise => { + await page.route(apiLink, async route => { + await route.fulfill({ + status: 500, + }); + }); +};