Skip to content

Commit

Permalink
Merge pull request #87 from intuitem/Check-for-undefined-text
Browse files Browse the repository at this point in the history
Check for undefined text
  • Loading branch information
Mohamed-Hacene authored Feb 29, 2024
2 parents 9c0c6c8 + 18932e6 commit d184346
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions frontend/tests/functional/detailed/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down
1 change: 1 addition & 0 deletions frontend/tests/functional/detailed/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ baseTest.skip('login page as expected title', async ({ page }) => {
test('login / logout process is working properly', async ({ loginPage, analyticsPage, sideBar, page }) => {
await loginPage.hasUrl(1);
await expect.soft(page.getByRole('heading', { name: 'Login into your account' })).toBeVisible();
await loginPage.checkForUndefinedText();
await loginPage.login();
await analyticsPage.hasUrl();
sideBar.moreButton.click();
Expand Down
33 changes: 18 additions & 15 deletions frontend/tests/functional/nav.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ test('sidebar navigation tests', async ({ logedPage, analyticsPage, sideBar, pag
};

const locals = localItems(languageTag());

for await (const [key, value] of sideBar.items) {
for await (const item of value) {
if (item.href !== '/role-assignments') {
await sideBar.click(key, item.href);
await expect(page).toHaveURL(item.href);
if (item.name in temporaryPageTitle) {
await expect.soft(logedPage.pageTitle).toHaveText(temporaryPageTitle[item.name]);
} else {
await expect.soft(logedPage.pageTitle).toHaveText(locals[item.name]);
}
}
}
for await (const [key, value] of sideBar.items) {
for await (const item of value) {
if (item.href !== '/role-assignments') {
await sideBar.click(key, item.href);
await expect(page).toHaveURL(item.href);
if (item.name in temporaryPageTitle) {
await expect.soft(logedPage.pageTitle).toHaveText(temporaryPageTitle[item.name]);
} else {
await expect.soft(logedPage.pageTitle).toHaveText(locals[item.name]);
}
}
}
});
}
});

await test.step('user email is showing properly', async () => {
await expect(page.getByTestId('sidebar-user-account-display')).toHaveText(logedPage.email);
Expand All @@ -47,19 +46,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();

Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/functional/user-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test('user usual routine actions are working correctly', async ({
await pages.librariesPage.hasTitle();
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 pages.frameworksPage.hasUrl();
Expand Down
4 changes: 4 additions & 0 deletions frontend/tests/utils/base-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions frontend/tests/utils/page-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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');
}
}
13 changes: 10 additions & 3 deletions frontend/tests/utils/test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -64,21 +68,24 @@ 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'
},
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'
}
}
Expand Down

0 comments on commit d184346

Please sign in to comment.