From 4babe6da693769afe29d74544d6e81fe873fc28a Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 28 Feb 2024 14:00:21 +0100 Subject: [PATCH 1/3] check for undefined text in pages --- frontend/tests/functional/detailed/common.test.ts | 1 + frontend/tests/functional/detailed/login.test.ts | 1 + frontend/tests/functional/nav.test.ts | 7 ++++++- frontend/tests/utils/base-page.ts | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/tests/functional/detailed/common.test.ts b/frontend/tests/functional/detailed/common.test.ts index 5c700ccbe..da8a5d565 100644 --- a/frontend/tests/functional/detailed/common.test.ts +++ b/frontend/tests/functional/detailed/common.test.ts @@ -68,6 +68,7 @@ for (const key of testPages) { page }) => { await pages[key].itemDetail.verifyItem(items[key].build); + await pages[key].checkForUndefinedText(); page.url().includes('evidences') ? await pages[key].page.waitForTimeout(1000) : null; // prevent crashing }); diff --git a/frontend/tests/functional/detailed/login.test.ts b/frontend/tests/functional/detailed/login.test.ts index 21b5936f6..bf20e3d42 100644 --- a/frontend/tests/functional/detailed/login.test.ts +++ b/frontend/tests/functional/detailed/login.test.ts @@ -16,6 +16,7 @@ test('login / logout process is working properly', async ({ }) => { await loginPage.hasUrl(1); await expect.soft(page.getByRole('heading', { name: 'Login into your account' })).toBeVisible(); + await loginPage.checkForUndefinedText(); await loginPage.login(); await overviewPage.hasUrl(); sideBar.moreButton.click(); diff --git a/frontend/tests/functional/nav.test.ts b/frontend/tests/functional/nav.test.ts index 40915cbc7..c6c00501e 100644 --- a/frontend/tests/functional/nav.test.ts +++ b/frontend/tests/functional/nav.test.ts @@ -29,6 +29,7 @@ test('sidebar navigation tests', async ({ logedPage, analyticsPage, sideBar, pag if (item.href !== '/role-assignments') { await sideBar.click(key, item.href); await expect(page).toHaveURL(item.href); + await logedPage.checkForUndefinedText(); if (item.name in temporaryPageTitle) { await expect.soft(logedPage.pageTitle).toHaveText([temporaryPageTitle[item.name]]); } else { @@ -47,19 +48,23 @@ test('sidebar navigation tests', async ({ logedPage, analyticsPage, sideBar, pag await test.step('more panel links are working properly', async () => { await sideBar.moreButton.click(); await expect(sideBar.morePanel).not.toHaveAttribute('inert'); + await logedPage.checkForUndefinedText(); await expect(sideBar.profileButton).toBeVisible(); await sideBar.profileButton.click(); await expect(sideBar.morePanel).toHaveAttribute('inert'); await expect(page).toHaveURL('/my-profile'); await expect.soft(logedPage.pageTitle).toHaveText('My profile'); - + await logedPage.checkForUndefinedText(); + await sideBar.moreButton.click(); await expect(sideBar.morePanel).not.toHaveAttribute('inert'); + await logedPage.checkForUndefinedText(); await expect(sideBar.aboutButton).toBeVisible(); await sideBar.aboutButton.click(); await expect(sideBar.morePanel).toHaveAttribute('inert'); await expect(logedPage.modalTitle).toBeVisible(); await expect.soft(logedPage.modalTitle).toHaveText('About CISO Assistant'); + await logedPage.checkForUndefinedText(); await page.mouse.click(20, 20); // click outside the modal to close it await expect(logedPage.modalTitle).not.toBeVisible(); diff --git a/frontend/tests/utils/base-page.ts b/frontend/tests/utils/base-page.ts index 42fd6c347..b68376058 100644 --- a/frontend/tests/utils/base-page.ts +++ b/frontend/tests/utils/base-page.ts @@ -24,6 +24,10 @@ export abstract class BasePage { //TODO function to assert breadcrumb path is accurate + async checkForUndefinedText() { + await expect.soft(this.page.getByText('undefined'), "An undefined text is visible on the page").toHaveCount(0); + } + async isToastVisible(value: string, flags?: string | undefined, options?: {} | undefined) { const toast = this.page.getByTestId('toast').filter({ hasText: new RegExp(value, flags) }); await expect(toast).toBeVisible(options); From d4a5f83dd3fc1415b74bf0da87a0a8f4b20bc1d8 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 28 Feb 2024 14:08:17 +0100 Subject: [PATCH 2/3] fix library import due to name conflicts --- frontend/tests/functional/user-route.test.ts | 4 ++-- frontend/tests/utils/page-content.ts | 12 ++++++------ frontend/tests/utils/test-data.ts | 13 ++++++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/frontend/tests/functional/user-route.test.ts b/frontend/tests/functional/user-route.test.ts index f9ba5a7db..96227bab7 100644 --- a/frontend/tests/functional/user-route.test.ts +++ b/frontend/tests/functional/user-route.test.ts @@ -72,11 +72,11 @@ test('user usual routine actions are working correctly', async ({ await expect(page).toHaveURL(pages.librariesPage.url); await pages.librariesPage.hasTitle(); - await pages.librariesPage.importLibrary(vars.framework.name, vars.framework.urn); + await pages.librariesPage.importLibrary(vars.framework.ref, vars.framework.urn); await sideBar.click('Compliance', pages.frameworksPage.url); await expect(page).toHaveURL(pages.frameworksPage.url); - await expect(page.getByRole('row', { name: vars.framework.name })).toBeVisible(); + await expect(page.getByRole('row', { name: vars.framework.ref })).toBeVisible(); }); await test.step('user can create a security function', async () => { diff --git a/frontend/tests/utils/page-content.ts b/frontend/tests/utils/page-content.ts index eeefe2634..153cd0588 100644 --- a/frontend/tests/utils/page-content.ts +++ b/frontend/tests/utils/page-content.ts @@ -45,7 +45,7 @@ export class PageContent extends BasePage { await this.page.goto('/libraries'); await this.page.waitForURL('/libraries'); - await this.importLibrary(dependency.name, dependency.urn); + await this.importLibrary(dependency.ref || dependency.name, dependency.urn); await this.goto(); } @@ -69,22 +69,22 @@ export class PageContent extends BasePage { } } - async importLibrary(name: string, urn: string, language: string = 'English') { + async importLibrary(ref: string, urn: string, language: string = 'English') { if (await this.tab('Imported libraries').isVisible()) { - if (await this.getRow(name).isHidden()) { + if (await this.getRow(ref).isHidden()) { await this.tab('Libraries store').click(); expect(this.tab('Libraries store').getAttribute('aria-selected')).toBeTruthy(); } else { return; } } - await this.importItemButton(name, language).click(); + await this.importItemButton(ref, language).click(); await this.isToastVisible('Successfully imported library ' + urn + '.+', undefined, { timeout: 15000 }); await this.tab('Imported libraries').click(); expect(this.tab('Imported libraries').getAttribute('aria-selected')).toBeTruthy(); - expect(this.getRow(name)).toBeVisible(); + expect(this.getRow(ref)).toBeVisible(); } async viewItemDetail(value?: string) { @@ -134,6 +134,6 @@ export class PageContent extends BasePage { importItemButton(value: string, language?: string) { return language ? this.getRow(value, language).getByTestId('tablerow-import-button') - : this.getRow(value).getByTestId('tablerow-import-button').first(); + : this.getRow(value).getByTestId('tablerow-import-button'); } } diff --git a/frontend/tests/utils/test-data.ts b/frontend/tests/utils/test-data.ts index 3c8f3eee2..2d6087943 100644 --- a/frontend/tests/utils/test-data.ts +++ b/frontend/tests/utils/test-data.ts @@ -26,7 +26,8 @@ export default { validator: 'Validator' }, framework: { - name: 'NIST CSF', + name: 'NIST CSF v1.1', + ref: 'NIST-CSF-1.1', urn: 'urn:intuitem:risk:library:nist-csf-1.1' }, matrix: { @@ -39,6 +40,7 @@ export default { category: 'policy', library: { name: 'Documents and policies', + ref: 'doc-pol', urn: 'urn:intuitem:risk:library:doc-pol' }, urn: 'urn:intuitem:risk:function:POL.PHYSICAL' @@ -48,6 +50,7 @@ export default { category: 'process', library: { name: 'Documents and policies', + ref: 'doc-pol', urn: 'urn:intuitem:risk:library:doc-pol' }, urn: 'urn:intuitem:risk:function:DOC.CONTROLS' @@ -56,6 +59,7 @@ export default { name: 'Exfiltration Over Other Network Medium', library: { name: 'Mitre ATT&CK v14 - Threats and mitigations', + ref: 'mitre-attack', urn: 'urn:intuitem:risk:library:mitre-attack-v14' }, urn: 'urn:intuitem:risk:threat:mitre-attack:T1011' @@ -64,6 +68,7 @@ export default { name: 'Exfiltration Over Physical Medium', library: { name: 'Mitre ATT&CK v14 - Threats and mitigations', + ref: 'mitre-attack', urn: 'urn:intuitem:risk:library:mitre-attack-v14' }, urn: 'urn:intuitem:risk:threat:mitre-attack:T1052' @@ -71,14 +76,16 @@ export default { requirement_assessment: { name: 'RC.RP - Recovery Planning', library: { - name: 'NIST CSF', + name: 'NIST CSF v1.1', + ref: 'NIST-CSF-1.1', urn: 'urn:intuitem:risk:library:nist-csf-1.1' } }, requirement_assessment2: { name: 'ID.GV - Governance', library: { - name: 'NIST CSF', + name: 'NIST CSF v1.1', + ref: 'NIST-CSF-1.1', urn: 'urn:intuitem:risk:library:nist-csf-1.1' } } From e18b7e3e91d337b422b0a507c2b4c9328b4f864a Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 28 Feb 2024 15:23:51 +0100 Subject: [PATCH 3/3] fix user route tests --- frontend/tests/functional/user-route.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/functional/user-route.test.ts b/frontend/tests/functional/user-route.test.ts index 96227bab7..e854eb00f 100644 --- a/frontend/tests/functional/user-route.test.ts +++ b/frontend/tests/functional/user-route.test.ts @@ -76,7 +76,7 @@ test('user usual routine actions are working correctly', async ({ await sideBar.click('Compliance', pages.frameworksPage.url); await expect(page).toHaveURL(pages.frameworksPage.url); - await expect(page.getByRole('row', { name: vars.framework.ref })).toBeVisible(); + await expect(page.getByRole('row', { name: vars.framework.name })).toBeVisible(); }); await test.step('user can create a security function', async () => {