Skip to content

Commit

Permalink
fix(citrus-simulator-ui): fix linter and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerfluri committed Sep 26, 2024
1 parent 59bdc79 commit ce1464a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
6 changes: 2 additions & 4 deletions simulator-ui/src/main/webapp/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerLocaleData } from '@angular/common';
import {HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import locale from '@angular/common/locales/en';
import { LOCALE_ID, NgModule } from '@angular/core';
import { BrowserModule, Title } from '@angular/platform-browser';
Expand Down Expand Up @@ -41,9 +41,7 @@ import MainModule from './layouts/main/main.module';
TranslationModule,
],
providers: [
provideHttpClient(
withInterceptorsFromDi(),
),
provideHttpClient(withInterceptorsFromDi()),
Title,
{ provide: LOCALE_ID, useValue: 'en' },
{ provide: NgbDateAdapter, useClass: NgbDateDayjsAdapter },
Expand Down
20 changes: 8 additions & 12 deletions simulator-ui/tests/error-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import { expect, Page, test } from '@playwright/test';
import {
mockResponseForAllNavbarLinkedSites, navbarElementLinkPairs
} from './helpers/helper-functions';
import {NavbarElementLinkPair} from "./helpers/helper-interfaces";
import { mockResponseForAllNavbarLinkedSites, navbarElementLinkPairs } from './helpers/helper-functions';
import { NavbarElementLinkPair } from './helpers/helper-interfaces';

const goToSiteAndVerifyErrorBannerIsVisible = (site: NavbarElementLinkPair): void => {
test(`${site.testName}`, async ({ page }) => {
if(site.apiLink && site.linkSuffix) {
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.describe('should show error banner if there is a 500 error returned while loading any page', async () => {
test.describe('should show error banner if there is a 500 error returned while loading any page', () => {
test.beforeEach(async ({ page }) => {
await mockResponseForAllNavbarLinkedSites(page, mock500ErrorResponseForApiURL);
});

navbarElementLinkPairs.forEach((element: NavbarElementLinkPair) => {
if(element.childElements){
for(const child of element.childElements){
if (element.childElements) {
for (const child of element.childElements) {
goToSiteAndVerifyErrorBannerIsVisible(child);
}
}
Expand All @@ -35,7 +31,7 @@ const mock500ErrorResponseForApiURL = async (page: Page, apiLink: string): Promi
await page.route(apiLink, async route => {
await route.fulfill({
status: 500,
body: JSON.stringify({"message": "hello"}),
body: JSON.stringify({ message: 'hello' }),
});
});
};
40 changes: 34 additions & 6 deletions simulator-ui/tests/helpers/helper-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,53 @@ import { NavbarElementLinkPair } from './helper-interfaces';
// a list of every navbar link-pair, which appears under the "Entity" dropdown
export const entityChildLinks: NavbarElementLinkPair[] = [
{ testName: 'navigationEntitiesMessageLink', expectedLinkRegex: /.*\/message*/, linkSuffix: '/message', apiLink: '**/api/messages*' },
{ testName: 'navigationEntitiesMessageHeaderLink', expectedLinkRegex: /.*\/message-header*/, linkSuffix: '/message-header', apiLink: '**/api/message-headers*' },
{
testName: 'navigationEntitiesMessageHeaderLink',
expectedLinkRegex: /.*\/message-header*/,
linkSuffix: '/message-header',
apiLink: '**/api/message-headers*',
},
{
testName: 'navigationEntitiesScenarioExecutionLink',
expectedLinkRegex: /.*\/scenario-execution*/,
linkSuffix: '/scenario-execution',
apiLink: '**/api/scenario-executions*',
},
{ testName: 'navigationEntitiesScenarioActionLink', expectedLinkRegex: /.*\/scenario-action*/, linkSuffix: '/scenario-action', apiLink: '**/api/scenario-actions*' },
{
testName: 'navigationEntitiesScenarioActionLink',
expectedLinkRegex: /.*\/scenario-action*/,
linkSuffix: '/scenario-action',
apiLink: '**/api/scenario-actions*',
},
{
testName: 'navigationEntitiesScenarioParameterLink',
expectedLinkRegex: /.*\/scenario-parameter*/,
linkSuffix: '/scenario-parameter',
apiLink: '**/api/scenario-parameters*',
},
{ testName: 'navigationEntitiesTestResultLink', expectedLinkRegex: /.*\/test-result*/, linkSuffix: '/test-result', apiLink: '**/api/test-results*' },
{ testName: 'navigationEntitiesParameterLink', expectedLinkRegex: /.*\/test-parameter*/, linkSuffix: '/test-parameter', apiLink: '**/api/test-parameters*' },
{
testName: 'navigationEntitiesTestResultLink',
expectedLinkRegex: /.*\/test-result*/,
linkSuffix: '/test-result',
apiLink: '**/api/test-results*',
},
{
testName: 'navigationEntitiesParameterLink',
expectedLinkRegex: /.*\/test-parameter*/,
linkSuffix: '/test-parameter',
apiLink: '**/api/test-parameters*',
},
];

// a list of every navbar element, which leads directly to another page
export const navbarElementLinkPairs: NavbarElementLinkPair[] = [
{ testName: 'navigationScenariosLink', expectedLinkRegex: /.*\/scenario*/, linkSuffix: '/scenario', apiLink: '**/api/scenarios*' },
{ testName: 'navigationScenarioExecutionsLink', expectedLinkRegex: /.*\/scenario-result*/, linkSuffix: '/scenario-result',apiLink: '**/api/scenario-executions*' },
{
testName: 'navigationScenarioExecutionsLink',
expectedLinkRegex: /.*\/scenario-result*/,
linkSuffix: '/scenario-result',
apiLink: '**/api/scenario-executions*',
},
{ testName: 'navigationEntitiesLink', childElements: entityChildLinks },
];

Expand Down Expand Up @@ -60,7 +85,10 @@ export const mockBackendResponse = async (
});
};

export const mockResponseForAllNavbarLinkedSites = async (page: Page, responseMockFunction: (page: Page, apiLink: string) => Promise<void>): Promise<void> => {
export const mockResponseForAllNavbarLinkedSites = async (
page: Page,
responseMockFunction: (page: Page, apiLink: string) => Promise<void>,
): Promise<void> => {
for (const element of navbarElementLinkPairs) {
if (element.childElements) {
for (const child of element.childElements) {
Expand Down
6 changes: 3 additions & 3 deletions simulator-ui/tests/no-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { expect, Page, test } from '@playwright/test';
import {
goToAllNavigationTabsAndOptionallyValidateContent,
mockBackendResponse,
mockResponseForAllNavbarLinkedSites
mockResponseForAllNavbarLinkedSites,
} from './helpers/helper-functions';

test.beforeEach(async ({ page }) => {
await mockResponseForAllNavbarLinkedSites(page, mockEmptyResponseForApiURL)
await mockResponseForAllNavbarLinkedSites(page, mockEmptyResponseForApiURL);
await page.goto('http://localhost:9000/');
});

Expand All @@ -19,5 +19,5 @@ const verifyNoDataFoundBannerIsVisible = async (page: Page): Promise<void> => {
};

const mockEmptyResponseForApiURL = async (page: Page, apiLink: string): Promise<void> => {
await mockBackendResponse(page, apiLink, [], { 'x-total-count': '0' })
await mockBackendResponse(page, apiLink, [], { 'x-total-count': '0' });
};

0 comments on commit ce1464a

Please sign in to comment.