Skip to content

Commit

Permalink
test(citrus-simulator-ui): fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerfluri committed Sep 4, 2024
1 parent 6d6b582 commit c74272a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 22 deletions.
4 changes: 2 additions & 2 deletions simulator-ui/tests/entities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ const entityPageContentMap: EntityPageContentObject[] = [

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

await page.goto(contentObject.entityUrl);

await expect(page.locator('th :text("ID")').nth(0)).toHaveCount(1);
await checkEntityPageContentValueAndVisibility(page, contentObject);
//'second test'
// 'second test'
await checkIfRefreshButtonWorks(page, contentObject);
});
});
Expand Down
5 changes: 2 additions & 3 deletions simulator-ui/tests/error-banner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ test.beforeEach(async ({ page }) => {
});

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();
};
await mockErrorResponseOfAllApiUrls(page);
await goToAllPagesAndCheckURLPlusContent(page, thingsToCheckOnAllPages);
});

const thingsToCheckOnAllPages = async (pageToPass: Page): Promise<void> => await expect(pageToPass.getByTestId('error')).toBeVisible();
27 changes: 21 additions & 6 deletions simulator-ui/tests/helpers/helper-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ export const elementLinkPairNoDropdown: navbarElementLinkPair[] = [
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: '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: 'navigationEntitiesScenarioParameterLink',
link: /.*\/scenario-parameter*/,
apiLink: '**/api/scenario-parameters*',
},
{ testName: 'navigationEntitiesTestResultLink', link: /.*\/test-result*/, apiLink: '**/api/test-results*' },
{ testName: 'navigationEntitiesParameterLink', link: /.*\/test-parameter*/, apiLink: '**/api/test-parameters*' },
];
Expand Down Expand Up @@ -38,7 +46,11 @@ export const mockBackendResponse = async (
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 });
if (headers) {
await route.fulfill({ json: responseJson, headers });
} else {
await route.fulfill({ json: responseJson });
}
});
};

Expand All @@ -60,20 +72,23 @@ export const mockErrorResponseOfAllApiUrls = async (page: Page): Promise<any> =>
}
};

export const goToAllPagesAndCheckURLPlusContent = async (page: Page, checkPageContentFunction?: (page: Page) => void): Promise<any> => {
export const goToAllPagesAndCheckURLPlusContent = async (
page: Page,
checkPageContentFunction?: (page: Page) => Promise<void>,
): Promise<any> => {
for (const element of elementLinkPairNoDropdown) {
await page.getByTestId(element.testName).click();
await expect(page).toHaveURL(element.link);
if (checkPageContentFunction) {
checkPageContentFunction(page);
await checkPageContentFunction(page);
}
}
for (const element of elementLinkPairEntityDroptdown) {
await page.getByTestId('navigationEntitiesLink').click();
await page.getByTestId(element.testName).click();
await expect(page).toHaveURL(element.link);
if (checkPageContentFunction) {
checkPageContentFunction(page);
await checkPageContentFunction(page);
}
}
};
2 changes: 1 addition & 1 deletion simulator-ui/tests/helpers/helper-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface EntityPageContentObject {
testName: string;
apiUrl: string;
entityUrl: string;
contentJson: {}[];
contentJson: object[];
locators: string[];
testIdsAndExpectedValues: TestIdValuePair[];
testIdToBeVisible: string[];
Expand Down
8 changes: 5 additions & 3 deletions simulator-ui/tests/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test('should have updated total, successful, failed tabs after refresh button cl
await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);

nbOfFailedTests -= 10;
nbOfSuccessfulTests += 10; //the total stays the same
nbOfSuccessfulTests += 10; // the total stays the same
await mockBackendResponse(page, '**/api/test-results/count-by-status', {
successful: nbOfSuccessfulTests,
failed: nbOfFailedTests,
Expand All @@ -102,7 +102,7 @@ test('(test if frontend trusts backend blindly) should have updated total, succe
await page.getByTestId('refreshListButton').click();

await checkIfSummaryTabsAreDisplayingRightNumbers(page, nbOfTotalTests, nbOfSuccessfulTests, nbOfFailedTests);
expect(nbOfTotalTests == newCorrectTotal).toBeFalsy();
expect(nbOfTotalTests === newCorrectTotal).toBeFalsy();
});

test('should have same total, successful, failed tabs after cancel deletion via close-Button and cancel-Button', async ({ page }) => {
Expand All @@ -111,7 +111,9 @@ 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();
Expand Down
7 changes: 4 additions & 3 deletions simulator-ui/tests/no-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ test.beforeEach(async ({ page }) => {
});

test('should show no-data-banner if there is an empty backend response on all pages', async ({ page }) => {
const checkIfNotFoundBannerVisible = async (page: Page) => {
await expect(page.getByTestId('noDataFound')).toBeVisible();
};
await goToAllPagesAndCheckURLPlusContent(page, checkIfNotFoundBannerVisible);
});

const checkIfNotFoundBannerVisible = async (page: Page): Promise<void> => {
await expect(page.getByTestId('noDataFound')).toBeVisible();
};
20 changes: 16 additions & 4 deletions simulator-ui/tests/scenario.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ 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');

Expand Down Expand Up @@ -222,9 +232,11 @@ const applyFilterAAndCheckCorrectness = async (page: Page): Promise<any> => {
await page.getByTestId('scenarioFilterByNameInput').fill('a');

for (const element of scenarioJson) {
element.name.includes('a') || element.name.includes('A')
? await expect(page.getByText(element.name)).toBeVisible()
: await expect(page.getByText(element.name)).toBeHidden();
if (element.name.includes('a') || element.name.includes('A')) {
await expect(page.getByText(element.name)).toBeVisible();
} else {
await expect(page.getByText(element.name)).toBeHidden();
}
}
await expect(page.getByText('Showing 1 - 5 of 5 Items')).toBeVisible();
};

0 comments on commit c74272a

Please sign in to comment.