forked from citrusframework/citrus-simulator
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(citrus-simulator-ui): parameterize and fix tests for 500 error in…
… 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}), | ||
}); | ||
}); | ||
}; |