From c74272ac2a47594a3726ab3c34bba62e8372a2f3 Mon Sep 17 00:00:00 2001 From: muellerfluri Date: Wed, 4 Sep 2024 11:14:03 +0200 Subject: [PATCH] test(citrus-simulator-ui): fix lint errors --- simulator-ui/tests/entities.spec.ts | 4 +-- simulator-ui/tests/error-banner.spec.ts | 5 ++-- .../tests/helpers/helper-functions.ts | 27 ++++++++++++++----- .../tests/helpers/helper-interfaces.ts | 2 +- simulator-ui/tests/home.spec.ts | 8 +++--- simulator-ui/tests/no-data.spec.ts | 7 ++--- simulator-ui/tests/scenario.spec.ts | 20 +++++++++++--- 7 files changed, 51 insertions(+), 22 deletions(-) diff --git a/simulator-ui/tests/entities.spec.ts b/simulator-ui/tests/entities.spec.ts index 0200f8fb..0f4ef96d 100644 --- a/simulator-ui/tests/entities.spec.ts +++ b/simulator-ui/tests/entities.spec.ts @@ -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); }); }); diff --git a/simulator-ui/tests/error-banner.spec.ts b/simulator-ui/tests/error-banner.spec.ts index 9dd1e05d..681438a4 100644 --- a/simulator-ui/tests/error-banner.spec.ts +++ b/simulator-ui/tests/error-banner.spec.ts @@ -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 => { - await expect(pageToPass.getByTestId('error')).toBeVisible(); - }; await mockErrorResponseOfAllApiUrls(page); await goToAllPagesAndCheckURLPlusContent(page, thingsToCheckOnAllPages); }); + +const thingsToCheckOnAllPages = async (pageToPass: Page): Promise => await expect(pageToPass.getByTestId('error')).toBeVisible(); diff --git a/simulator-ui/tests/helpers/helper-functions.ts b/simulator-ui/tests/helpers/helper-functions.ts index 17fc8ce4..51510540 100644 --- a/simulator-ui/tests/helpers/helper-functions.ts +++ b/simulator-ui/tests/helpers/helper-functions.ts @@ -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*' }, ]; @@ -38,7 +46,11 @@ export const mockBackendResponse = async ( headers?: { [key: string]: string }, ): Promise => { 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 }); + } }); }; @@ -60,12 +72,15 @@ export const mockErrorResponseOfAllApiUrls = async (page: Page): Promise => } }; -export const goToAllPagesAndCheckURLPlusContent = async (page: Page, checkPageContentFunction?: (page: Page) => void): Promise => { +export const goToAllPagesAndCheckURLPlusContent = async ( + page: Page, + checkPageContentFunction?: (page: Page) => Promise, +): Promise => { 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) { @@ -73,7 +88,7 @@ export const goToAllPagesAndCheckURLPlusContent = async (page: Page, checkPageCo await page.getByTestId(element.testName).click(); await expect(page).toHaveURL(element.link); if (checkPageContentFunction) { - checkPageContentFunction(page); + await checkPageContentFunction(page); } } }; diff --git a/simulator-ui/tests/helpers/helper-interfaces.ts b/simulator-ui/tests/helpers/helper-interfaces.ts index 942e9c83..e3d6ab8a 100644 --- a/simulator-ui/tests/helpers/helper-interfaces.ts +++ b/simulator-ui/tests/helpers/helper-interfaces.ts @@ -2,7 +2,7 @@ export interface EntityPageContentObject { testName: string; apiUrl: string; entityUrl: string; - contentJson: {}[]; + contentJson: object[]; locators: string[]; testIdsAndExpectedValues: TestIdValuePair[]; testIdToBeVisible: string[]; diff --git a/simulator-ui/tests/home.spec.ts b/simulator-ui/tests/home.spec.ts index 8bd5b02c..c744d69e 100644 --- a/simulator-ui/tests/home.spec.ts +++ b/simulator-ui/tests/home.spec.ts @@ -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, @@ -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 }) => { @@ -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(); diff --git a/simulator-ui/tests/no-data.spec.ts b/simulator-ui/tests/no-data.spec.ts index bd0d53ac..70e84583 100644 --- a/simulator-ui/tests/no-data.spec.ts +++ b/simulator-ui/tests/no-data.spec.ts @@ -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 => { + await expect(page.getByTestId('noDataFound')).toBeVisible(); +}; diff --git a/simulator-ui/tests/scenario.spec.ts b/simulator-ui/tests/scenario.spec.ts index d5e11414..0a0326d4 100644 --- a/simulator-ui/tests/scenario.spec.ts +++ b/simulator-ui/tests/scenario.spec.ts @@ -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'); @@ -222,9 +232,11 @@ const applyFilterAAndCheckCorrectness = async (page: Page): Promise => { 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(); };