Skip to content

Commit

Permalink
fix(citrus-simulator-ui): run prettier write
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerfluri committed Sep 17, 2024
1 parent 8b73c67 commit 8e652d7
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 163 deletions.
78 changes: 36 additions & 42 deletions simulator-ui/tests/entities.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import {expect, Page, test} from '@playwright/test';
import {EntityPageContentObject} from './helpers/helper-interfaces';
import {
messageHeaderJson,
messageJson,
scenarioActionJson,
scenarioExecutionJson,
testResultJson,
} from './helpers/entity-jsons';
import {mockBackendResponse} from './helpers/helper-functions';
import { expect, Page, test } from '@playwright/test';
import { EntityPageContentObject } from './helpers/helper-interfaces';
import { messageHeaderJson, messageJson, scenarioActionJson, scenarioExecutionJson, testResultJson } from './helpers/entity-jsons';
import { mockBackendResponse } from './helpers/helper-functions';

const exampleDate = '23 Aug 2024 08:25:31';
const entityPageContentMap: EntityPageContentObject[] = [
Expand All @@ -25,12 +19,12 @@ const entityPageContentMap: EntityPageContentObject[] = [
'th :text("Last Modified Date")',
],
testIdsAndExpectedValues: [
{testId: 'messageEntityMessageId', expectedValue: '1'},
{testId: 'messageEntityMessageDirection', expectedValue: 'INBOUND'},
{testId: 'messageEntityMessagePayload', expectedValue: '<Default>Should trigger default scenario</Default>'},
{testId: 'messageEntityMessageCitrusMessage', expectedValue: '5605967b-bfd6-42bb-ba3b-a2404d20783a'},
{testId: 'messageEntityMessageCreatedDate', expectedValue: exampleDate},
{testId: 'messageEntityMessageLastModified', expectedValue: exampleDate},
{ testId: 'messageEntityMessageId', expectedValue: '1' },
{ testId: 'messageEntityMessageDirection', expectedValue: 'INBOUND' },
{ testId: 'messageEntityMessagePayload', expectedValue: '<Default>Should trigger default scenario</Default>' },
{ testId: 'messageEntityMessageCitrusMessage', expectedValue: '5605967b-bfd6-42bb-ba3b-a2404d20783a' },
{ testId: 'messageEntityMessageCreatedDate', expectedValue: exampleDate },
{ testId: 'messageEntityMessageLastModified', expectedValue: exampleDate },
],
testIdToBeVisible: ['filterOtherEntityButton'],
},
Expand All @@ -41,9 +35,9 @@ const entityPageContentMap: EntityPageContentObject[] = [
contentJson: messageHeaderJson,
locators: ['th :text("Name")', 'th :text("Value")'],
testIdsAndExpectedValues: [
{testId: 'messageHeaderEntityId', expectedValue: '13'},
{testId: 'messageHeaderEntityName', expectedValue: 'Content-Type'},
{testId: 'messageHeaderEntityValue', expectedValue: 'application/xml;charset=UTF-8'},
{ testId: 'messageHeaderEntityId', expectedValue: '13' },
{ testId: 'messageHeaderEntityName', expectedValue: 'Content-Type' },
{ testId: 'messageHeaderEntityValue', expectedValue: 'application/xml;charset=UTF-8' },
],
testIdToBeVisible: [],
},
Expand All @@ -54,12 +48,12 @@ const entityPageContentMap: EntityPageContentObject[] = [
contentJson: scenarioExecutionJson,
locators: ['th :text("Name")', 'th :text("Start Date")', 'th :text("End Date")', 'th :text("Status")', 'th :text("Error Message")'],
testIdsAndExpectedValues: [
{testId: 'scenarioExecutionEntityScenarioExecutionLink', expectedValue: '1'},
{testId: 'scenarioExecutionEntityScenarioName', expectedValue: 'Default'},
{testId: 'scenarioExecutionEntityStartDate', expectedValue: exampleDate},
{testId: 'scenarioExecutionEntityEndDate', expectedValue: exampleDate},
{testId: 'scenarioExecutionEntityStatus', expectedValue: 'FAILURE'},
{testId: 'scenarioExecutionEntityTestResult', expectedValue: 'New Error'},
{ testId: 'scenarioExecutionEntityScenarioExecutionLink', expectedValue: '1' },
{ testId: 'scenarioExecutionEntityScenarioName', expectedValue: 'Default' },
{ testId: 'scenarioExecutionEntityStartDate', expectedValue: exampleDate },
{ testId: 'scenarioExecutionEntityEndDate', expectedValue: exampleDate },
{ testId: 'scenarioExecutionEntityStatus', expectedValue: 'FAILURE' },
{ testId: 'scenarioExecutionEntityTestResult', expectedValue: 'New Error' },
],
testIdToBeVisible: [],
},
Expand All @@ -70,10 +64,10 @@ const entityPageContentMap: EntityPageContentObject[] = [
contentJson: scenarioActionJson,
locators: ['th :text("Name")', 'th :text("Start Date")', 'th :text("End Date")', 'th :text("Scenario Execution")'],
testIdsAndExpectedValues: [
{testId: 'scenarioActionEntitiesId', expectedValue: '1'},
{testId: 'scenarioActionEntitiesName', expectedValue: 'http:receive-request'},
{testId: 'scenarioActionEntitiesStartDate', expectedValue: exampleDate},
{testId: 'scenarioActionEntitiesEndDate', expectedValue: exampleDate},
{ testId: 'scenarioActionEntitiesId', expectedValue: '1' },
{ testId: 'scenarioActionEntitiesName', expectedValue: 'http:receive-request' },
{ testId: 'scenarioActionEntitiesStartDate', expectedValue: exampleDate },
{ testId: 'scenarioActionEntitiesEndDate', expectedValue: exampleDate },
],
testIdToBeVisible: [],
},
Expand All @@ -90,22 +84,22 @@ const entityPageContentMap: EntityPageContentObject[] = [
'th :text("Stack Trace")',
],
testIdsAndExpectedValues: [
{testId: 'testResultEntitiesId', expectedValue: '1'},
{testId: 'testResultEntitiesStatus', expectedValue: 'FAILURE'},
{testId: 'testResultEntitiesTestName', expectedValue: 'Scenario(Default)'},
{testId: 'testResultEntitiesClassName', expectedValue: 'DefaultTestCase'},
{testId: 'testResultEntitiesErrorMessage', expectedValue: 'New Error'},
{testId: 'testResultEntitiesStackTrace', expectedValue: 'New Stacktrace'},
{testId: 'testResultEntitiesFailureType', expectedValue: ''},
{testId: 'testResultEntitiesCreatedDate', expectedValue: exampleDate},
{testId: 'testResultEntitiesLastModifiedDate', expectedValue: exampleDate},
{ testId: 'testResultEntitiesId', expectedValue: '1' },
{ testId: 'testResultEntitiesStatus', expectedValue: 'FAILURE' },
{ testId: 'testResultEntitiesTestName', expectedValue: 'Scenario(Default)' },
{ testId: 'testResultEntitiesClassName', expectedValue: 'DefaultTestCase' },
{ testId: 'testResultEntitiesErrorMessage', expectedValue: 'New Error' },
{ testId: 'testResultEntitiesStackTrace', expectedValue: 'New Stacktrace' },
{ testId: 'testResultEntitiesFailureType', expectedValue: '' },
{ testId: 'testResultEntitiesCreatedDate', expectedValue: exampleDate },
{ testId: 'testResultEntitiesLastModifiedDate', expectedValue: exampleDate },
],
testIdToBeVisible: [],
},
];

entityPageContentMap.forEach((contentObject: EntityPageContentObject) => {
test(`${contentObject.testName}`, async ({page}) => {
test(`${contentObject.testName}`, async ({ page }) => {
await mockBackendResponse(page, contentObject.apiUrl, contentObject.contentJson);

await page.goto(contentObject.entityUrl);
Expand All @@ -117,7 +111,7 @@ entityPageContentMap.forEach((contentObject: EntityPageContentObject) => {
});

test.describe('message entity table', () => {
test('should show message headers when clicking button', async ({page}) => {
test('should show message headers when clicking button', async ({ page }) => {
const contentObject = entityPageContentMap[0];
await mockBackendResponse(page, contentObject.apiUrl, contentObject.contentJson);

Expand All @@ -130,7 +124,7 @@ test.describe('message entity table', () => {
});

test.describe('test results entity table', () => {
test('should show test parameters when clicking on button', async ({page}) => {
test('should show test parameters when clicking on button', async ({ page }) => {
const contentObject = entityPageContentMap[4];
await mockBackendResponse(page, contentObject.apiUrl, contentObject.contentJson);

Expand All @@ -142,7 +136,7 @@ test.describe('test results entity table', () => {
});
});

test('should display table of test parameters', async ({page}) => {
test('should display table of test parameters', async ({ page }) => {
const contentObject = entityPageContentMap[5];
await mockBackendResponse(page, contentObject.apiUrl, contentObject.contentJson);

Expand Down
11 changes: 4 additions & 7 deletions simulator-ui/tests/error-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {expect, Page, test} from '@playwright/test';
import {
goToAllNavigationTabsAndOptionallyValidateContent,
mockErrorResponseForAllNavbarLinkedSites
} from './helpers/helper-functions';
import { expect, Page, test } from '@playwright/test';
import { goToAllNavigationTabsAndOptionallyValidateContent, mockErrorResponseForAllNavbarLinkedSites } from './helpers/helper-functions';

test.beforeEach(async ({page}) => {
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}) => {
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 goToAllNavigationTabsAndOptionallyValidateContent(page, verifyErrorBannerIsVisible);
Expand Down
34 changes: 19 additions & 15 deletions simulator-ui/tests/helpers/helper-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const entityChildLinks: NavbarElementLinkPair[] = [

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

export const clickOnLinkAndCheckIfTabOpensWithCorrectURL = async (
Expand Down Expand Up @@ -60,48 +60,52 @@ export const mockBackendResponse = async (

export const mockErrorResponseForAllNavbarLinkedSites = async (page: Page): Promise<void> => {
for (const element of navbarElementLinkPairs) {
if(element.childElements){
for(const child of element.childElements){
if(child.apiLink){
if (element.childElements) {
for (const child of element.childElements) {
if (child.apiLink) {
await mock500ErrorResponseForApiURL(page, child.apiLink);
}
}
}
if(element.apiLink){
if (element.apiLink) {
await mock500ErrorResponseForApiURL(page, element.apiLink);
}
}
};

const mock500ErrorResponseForApiURL = async (page: Page, apiLink: string) : Promise<void> => {
const mock500ErrorResponseForApiURL = async (page: Page, apiLink: string): Promise<void> => {
await page.route(apiLink, async route => {
await route.fulfill({
status: 500,
});
});
}
};

export const goToAllNavigationTabsAndOptionallyValidateContent = async (
page: Page,
validatePageContent?: (page: Page) => Promise<void>,
): Promise<void> => {
for (const element of navbarElementLinkPairs) {
if(element.childElements){
for(const child of element.childElements){
if (element.childElements) {
for (const child of element.childElements) {
await page.getByTestId(element.testName).click();
await clickOnNavbarElementAndOptionallyValidateContent(page, child, validatePageContent);
}
}
await clickOnNavbarElementAndOptionallyValidateContent(page, element, validatePageContent);
await clickOnNavbarElementAndOptionallyValidateContent(page, element, validatePageContent);
}
};

const clickOnNavbarElementAndOptionallyValidateContent = async (page: Page, navbarElement: NavbarElementLinkPair, validatePageContent?: (page: Page) => Promise<void>) : Promise<void> => {
const clickOnNavbarElementAndOptionallyValidateContent = async (
page: Page,
navbarElement: NavbarElementLinkPair,
validatePageContent?: (page: Page) => Promise<void>,
): Promise<void> => {
await page.getByTestId(navbarElement.testName).click();
if(navbarElement.link){
if (navbarElement.link) {
await expect(page).toHaveURL(navbarElement.link);
}
if (validatePageContent) {
await validatePageContent(page);
}
}
};
42 changes: 21 additions & 21 deletions simulator-ui/tests/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import {expect, Page, test} from '@playwright/test';
import { expect, Page, test } from '@playwright/test';

import {clickOnLinkAndCheckIfTabOpensWithCorrectURL, mockBackendResponse} from './helpers/helper-functions';
import { clickOnLinkAndCheckIfTabOpensWithCorrectURL, mockBackendResponse } from './helpers/helper-functions';

let nbOfSuccessfulTests = 90;
let nbOfFailedTests = 10;
let nbOfTotalTests = nbOfSuccessfulTests + nbOfFailedTests;

const scenarioSummariesLinkFilterTriples = [
{testName: 'totalSimulationsButton', link: /.*\/scenario-result*/, filterText: ''},
{testName: 'successfulSimulationsButton', link: /.*\/scenario-result*/, filterText: 'SUCCESS'},
{testName: 'failedSimulationsButton', link: /.*\/scenario-result*/, filterText: 'FAILURE'},
{ testName: 'totalSimulationsButton', link: /.*\/scenario-result*/, filterText: '' },
{ testName: 'successfulSimulationsButton', link: /.*\/scenario-result*/, filterText: 'SUCCESS' },
{ testName: 'failedSimulationsButton', link: /.*\/scenario-result*/, filterText: 'FAILURE' },
];

test.beforeEach(async ({page}) => {
test.beforeEach(async ({ page }) => {
await mockBackendResponse(page, '**/api/test-results/count-by-status', {
successful: nbOfSuccessfulTests,
failed: nbOfFailedTests,
total: nbOfTotalTests,
});
await mockBackendResponse(page, '**/api/manage/info', {
config: {'reset-results-enabled': 'true',}
config: { 'reset-results-enabled': 'true' },
});
await page.goto('http://localhost:9000/');
});

test('should have title, disclaimer, refresh button, reset button, feedback option, summary-tabs and footer', async ({page}) => {
test('should have title, disclaimer, refresh button, reset button, feedback option, summary-tabs and footer', async ({ page }) => {
const visibleElements: string[] = [
'disclaimer',
'refreshListButton',
Expand All @@ -42,11 +42,11 @@ test('should have title, disclaimer, refresh button, reset button, feedback opti
}
});

test('check if summary-tab displays right percentage with round numbers', async ({page}) => {
test('check if summary-tab displays right percentage with round numbers', async ({ page }) => {
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);
});

test('total, successful, failed tabs should display percentage in simulations count rounded to two decimal numbers', async ({page}) => {
test('total, successful, failed tabs should display percentage in simulations count rounded to two decimal numbers', async ({ page }) => {
const successfulTestsBig = 746039;
const failedTestsBig = 490;
const totalTestsBig = successfulTestsBig + failedTestsBig;
Expand All @@ -61,12 +61,12 @@ test('total, successful, failed tabs should display percentage in simulations co
await checkIfSummaryTabsAreDisplayingRightNumbers(page, totalTestsBig, successfulTestsBig, failedTestsBig);
});

test('should move to right page with feedback resp suggestion link', async ({page}) => {
test('should move to right page with feedback resp suggestion link', async ({ page }) => {
await clickOnLinkAndCheckIfTabOpensWithCorrectURL(page, 'feedbackLinkStarGithub', /.*\/github\.com\/citrusframework\/citrus-simulator/);
await clickOnLinkAndCheckIfTabOpensWithCorrectURL(page, 'feedbackAndSuggestionLink', /.*\/github\.com.*issue/);
});

test('should move to scenario-results page with right search field params after click on detail buttons', async ({page}) => {
test('should move to scenario-results page with right search field params after click on detail buttons', async ({ page }) => {
for (const element of scenarioSummariesLinkFilterTriples) {
await page.goto('http://localhost:9000/');
await page.getByTestId(element.testName).click();
Expand All @@ -75,7 +75,7 @@ test('should move to scenario-results page with right search field params after
}
});

test('should have updated total, successful, failed tabs after refresh button clicked positive test', async ({page}) => {
test('should have updated total, successful, failed tabs after refresh button clicked positive test', async ({ page }) => {
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);

nbOfFailedTests -= 10;
Expand All @@ -91,8 +91,8 @@ test('should have updated total, successful, failed tabs after refresh button cl
});

test('(test if frontend trusts backend blindly) should have updated total, successful, failed tabs after refresh button clicked negative test with false total', async ({
page,
}) => {
page,
}) => {
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);
nbOfFailedTests -= 10; // so the total will be wrong!
const newCorrectTotal: number = nbOfTotalTests - 10;
Expand All @@ -108,7 +108,7 @@ test('(test if frontend trusts backend blindly) should have updated total, succe
expect(nbOfTotalTests === newCorrectTotal).toBeFalsy();
});

test('should have same total, successful, failed tabs after cancel deletion via close-Button and cancel-Button', async ({page}) => {
test('should have same total, successful, failed tabs after cancel deletion via close-Button and cancel-Button', async ({ page }) => {
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);
const closeButtons = ['testResultDeleteDialogCloseButton', 'testResultDeleteDialogCancelButton'];
let deleteRequestWasMade = false;
Expand All @@ -129,7 +129,7 @@ test('should have same total, successful, failed tabs after cancel deletion via
}
});

test('should have reset total, successful, failed tabs after confirmed deletion with (200, OK) response', async ({page}) => {
test('should have reset total, successful, failed tabs after confirmed deletion with (200, OK) response', async ({ page }) => {
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);
await page.getByTestId('resetButton').click();
await expect(page.getByTestId('testResultDeleteDialogHeading')).toBeVisible();
Expand Down Expand Up @@ -182,10 +182,10 @@ const checkIfSummaryTabsAreDisplayingRightNumbers = async (
for (const percentageDisplay of summarySelectorToAbsoluteValueMapping) {
await expect(page.getByTestId(percentageDisplay.testSelector)).toHaveText(
percentageDisplay.value +
` (${((percentageDisplay.value / totalTests) * 100).toLocaleString(undefined, {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
})} %)`,
` (${((percentageDisplay.value / totalTests) * 100).toLocaleString(undefined, {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
})} %)`,
);
}
};
Loading

0 comments on commit 8e652d7

Please sign in to comment.