Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(citrus-simulator-ui):run prettier:format
Browse files Browse the repository at this point in the history
muellerfluri committed Sep 3, 2024
1 parent 7837d30 commit 6d6b582
Showing 5 changed files with 30 additions and 34 deletions.
3 changes: 1 addition & 2 deletions simulator-ui/tests/entities.spec.ts
Original file line number Diff line number Diff line change
@@ -126,8 +126,7 @@ const entityPageContentMap: EntityPageContentObject[] = [
},
];


entityPageContentMap.forEach(( contentObject: EntityPageContentObject ) => {
entityPageContentMap.forEach((contentObject: EntityPageContentObject) => {
test(`${contentObject.testName}`, async ({ page }) => {
//'first test'
await mockBackendResponse(page, contentObject.apiUrl, contentObject.contentJson);
7 changes: 1 addition & 6 deletions simulator-ui/tests/error-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { expect, Page, test } from '@playwright/test';
import {
goToAllPagesAndCheckURLPlusContent,
mockBackendResponse,
mockErrorResponseOfAllApiUrls
} from './helpers/helper-functions';
import { goToAllPagesAndCheckURLPlusContent, mockBackendResponse, mockErrorResponseOfAllApiUrls } 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 }) => {

const thingsToCheckOnAllPages = async (pageToPass: Page): Promise<void> => {
await expect(pageToPass.getByTestId('error')).toBeVisible();
};
19 changes: 11 additions & 8 deletions simulator-ui/tests/helpers/helper-functions.ts
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@ import { expect, Page } from '@playwright/test';
import { navbarElementLinkPair } from './helper-interfaces';

export const elementLinkPairNoDropdown: navbarElementLinkPair[] = [
{ testName: 'navigationScenariosLink', link: /.*scenario*/, apiLink: '**/api/scenarios*'},
{ testName: 'navigationScenariosLink', link: /.*scenario*/, apiLink: '**/api/scenarios*' },
{ testName: 'navigationScenarioExecutionsLink', link: /.*scenario-result*/, apiLink: '**/api/scenario-executions*' },
];
export const elementLinkPairEntityDroptdown: navbarElementLinkPair[] = [
{ testName: 'navigationEntitiesMessageLink', link: /.*\/message*/ , apiLink: '**/api/messages*'},
{ testName: 'navigationEntitiesMessageHeaderLink', link: /.*\/message-header*/, apiLink: '**/api/message-headers*'},
{ testName: 'navigationEntitiesScenarioExecutionLink', link: /.*\/scenario-execution*/, apiLink: '**/api/scenario-executions*'},
{ testName: 'navigationEntitiesMessageLink', link: /.*\/message*/, apiLink: '**/api/messages*' },
{ testName: 'navigationEntitiesMessageHeaderLink', link: /.*\/message-header*/, apiLink: '**/api/message-headers*' },
{ testName: 'navigationEntitiesScenarioExecutionLink', link: /.*\/scenario-execution*/, apiLink: '**/api/scenario-executions*' },
{ testName: 'navigationEntitiesScenarioActionLink', link: /.*\/scenario-action*/, apiLink: '**/api/scenario-actions*' },
{ testName: 'navigationEntitiesScenarioParameterLink', link: /.*\/scenario-parameter*/, apiLink: '**/api/scenario-parameters*' },
{ testName: 'navigationEntitiesTestResultLink', link: /.*\/test-result*/, apiLink: '**/api/test-results*' },
@@ -31,11 +31,14 @@ export const clickOnLinkAndCheckIfTabOpensWithCorrectURL = async (
await expect(newTab).toHaveURL(expectedURL);
};

export const mockBackendResponse = async (page: Page, apiURL: string, responseJson: object, headers?: {[key: string]: string; }): Promise<any> => {
export const mockBackendResponse = async (
page: Page,
apiURL: string,
responseJson: object,
headers?: { [key: string]: string },
): Promise<any> => {
await page.route(apiURL, async route => {
headers
? await route.fulfill({ json: responseJson , headers: headers })
: await route.fulfill({ json: responseJson })
headers ? await route.fulfill({ json: responseJson, headers: headers }) : await route.fulfill({ json: responseJson });
});
};

9 changes: 5 additions & 4 deletions simulator-ui/tests/home.spec.ts
Original file line number Diff line number Diff line change
@@ -87,7 +87,9 @@ test('should have updated total, successful, failed tabs after refresh button cl
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);
});

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 }) => {
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,
}) => {
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);
nbOfFailedTests -= 10; // so the total will be wrong!
const newCorrectTotal: number = nbOfTotalTests - 10;
@@ -109,9 +111,8 @@ test('should have same total, successful, failed tabs after cancel deletion via
let deleteRequestWasMade = false;

page.on('request', request => {
if (request.method() == 'DELETE')
deleteRequestWasMade = true
})
if (request.method() == 'DELETE') deleteRequestWasMade = true;
});
for (const button of closeButtons) {
await page.getByTestId('resetButton').click();
await expect(page.getByTestId('testResultDeleteDialogHeading')).toBeVisible();
26 changes: 12 additions & 14 deletions simulator-ui/tests/scenario.spec.ts
Original file line number Diff line number Diff line change
@@ -14,11 +14,11 @@ const scenarioJson = [
{ name: 'HiStarter', type: 'STARTER' },
];

const addititonalPageJson=[
const addititonalPageJson = [
{ name: 'One', type: 'STARTER' },
{ name: 'Two', type: 'STARTER' },
{ name: 'Three', type: 'STARTER' },
]
];

const orderedJson = [
{ name: 'Fail', type: 'MESSAGE_TRIGGERED' },
@@ -43,13 +43,13 @@ const parameterJson = [
const availableScenarios: number = addititonalPageJson.length + scenarioJson.length;

test.beforeEach(async ({ page }) => {
await mockBackendResponse(page, '**/api/scenarios**page=0**', scenarioJson, {'x-total-count': availableScenarios.toString()})
await mockBackendResponse(page, '**/api/scenarios**page=0**', scenarioJson, { 'x-total-count': availableScenarios.toString() });
await page.goto('http://localhost:9000/scenario');
await page.getByTestId('itemsPerPageSelect').selectOption('10');
});

test('should display all scenario information of a starter scenario', async ({ page }) => {
await mockBackendResponse(page, '**/api/scenarios**', [{ name: 'Test', type: 'STARTER' }], {'x-total-count': '1'});
await mockBackendResponse(page, '**/api/scenarios**', [{ name: 'Test', type: 'STARTER' }], { 'x-total-count': '1' });

await page.goto('http://localhost:9000/scenario');

@@ -61,7 +61,7 @@ test('should display all scenario information of a starter scenario', async ({ p
});

test('should display all scenario information of a non-starter scenario', async ({ page }) => {
await mockBackendResponse(page, '**/api/scenarios**', [{ name: 'Test', type: 'MESSAGE_TRIGGERED' }], {'x-total-count': '1'});
await mockBackendResponse(page, '**/api/scenarios**', [{ name: 'Test', type: 'MESSAGE_TRIGGERED' }], { 'x-total-count': '1' });

await page.goto('http://localhost:9000/scenario');

@@ -71,13 +71,11 @@ test('should display all scenario information of a non-starter scenario', async
await expect(page.getByTestId('scenarioExecutionButton')).toBeVisible();
});

test('should have the first 10 of 13 elements displayed in the table and display right nb of visible elements', async ({
page,
}) => {
test('should have the first 10 of 13 elements displayed in the table and display right nb of visible elements', async ({ page }) => {
await checkIfAllJsonContentIsVisible(page, 10, availableScenarios, scenarioJson);
});

test('should have the last 3 of 13 elements displayed in the table after clicking on 2. page', async ({page,}) => {
test('should have the last 3 of 13 elements displayed in the table after clicking on 2. page', async ({ page }) => {
await mockBackendResponse(page, '**/api/scenarios**page=1**', addititonalPageJson);
await page.getByRole('link', { name: '2' }).click();
await checkIfAllJsonContentIsVisible(page, 10, availableScenarios, addititonalPageJson);
@@ -92,7 +90,7 @@ test('see if frontend trusts backend to send only as much data as requested', as

await page.getByTestId('itemsPerPageSelect').selectOption(selectedPageSize.toString());

await checkIfAllJsonContentIsVisible(page, selectedPageSize, availableScenarios, scenarioJson)
await checkIfAllJsonContentIsVisible(page, selectedPageSize, availableScenarios, scenarioJson);
await expect(page.getByTestId('itemsPerPageSelect')).toHaveValue(selectedPageSize.toString());
scenarioJson.pop();
});
@@ -109,11 +107,11 @@ test('should have updated displayed scenarios after refresh button was clicked a
for (const option of selectOptionsForNumberOfScenariosToDisplay) {
await page.getByTestId('itemsPerPageSelect').selectOption(option.toString());
scenarioJson.pop();
await mockBackendResponse(page, '**/api/scenarios**', scenarioJson, {'x-total-count': scenarioJson.length.toString()});
await mockBackendResponse(page, '**/api/scenarios**', scenarioJson, { 'x-total-count': scenarioJson.length.toString() });

await page.getByTestId('refreshListButton').click();
await checkIfAllJsonContentIsVisible(page, option, scenarioJson.length, scenarioJson);
scenarioJson.push({ name: 'HiStarter', type: 'STARTER' },);
scenarioJson.push({ name: 'HiStarter', type: 'STARTER' });
}
});

@@ -176,7 +174,7 @@ test('should go to detail view of a scenario (not type starter) and then go back
});

test('should go to detail view of a scenario type STARTER check for content and go back', async ({ page }) => {
await mockBackendResponse(page, '**/api/scenarios/ByeStarter/parameters', parameterJson)
await mockBackendResponse(page, '**/api/scenarios/ByeStarter/parameters', parameterJson);
const allVisibleDetailElements = [
'scenarioDetailsHeading',
'scenarioDetailsName',
@@ -219,7 +217,7 @@ const applyFilterAAndCheckCorrectness = async (page: Page): Promise<any> => {
const pageSize: number = 20;
await page.getByTestId('itemsPerPageSelect').selectOption(pageSize.toString());
await checkIfAllJsonContentIsVisible(page, pageSize, availableScenarios, scenarioJson);
await mockBackendResponse(page, '**/api/scenarios?**nameContains=a&sort=id,asc', orderedJson, {'x-total-count': '5'});
await mockBackendResponse(page, '**/api/scenarios?**nameContains=a&sort=id,asc', orderedJson, { 'x-total-count': '5' });

await page.getByTestId('scenarioFilterByNameInput').fill('a');

0 comments on commit 6d6b582

Please sign in to comment.