Skip to content

Commit

Permalink
fix(citrus-simulator-ui): parameterize and fix tests for 500 error in…
Browse files Browse the repository at this point in the history
… error-banner.spec.ts
  • Loading branch information
muellerfluri committed Sep 26, 2024
1 parent 789804d commit 213f867
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions simulator-ui/tests/error-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -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<void> => 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<void> => {
await page.route(apiLink, async route => {
await route.fulfill({
status: 500,
body: JSON.stringify({"message": "hello"}),
});
});
};

0 comments on commit 213f867

Please sign in to comment.