Skip to content

Commit

Permalink
[frontend] add eslint config to e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lndrtrbn committed Feb 27, 2024
1 parent 26308ee commit fe7d889
Show file tree
Hide file tree
Showing 24 changed files with 207 additions and 189 deletions.
1 change: 0 additions & 1 deletion opencti-platform/opencti-front/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = {
'jest.file.transform.js',
'jest.relay.transform.js',
'extract-i18n-keyword.js',
'**/tests_e2e/**',
'playwright.config.ts',
],
plugins: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ArtifactPage} from "../model/Artifact.pageModel";
import { ArtifactImportPage} from "../model/ArtifactImport.pageModel";
import { expect, test } from "../fixtures/baseFixtures";
import ArtifactPage from '../model/Artifact.pageModel';
import ArtifactImportPage from '../model/ArtifactImport.pageModel';
import { expect, test } from '../fixtures/baseFixtures';


test('Artifact error message in the absence of a file.', async ({ page }) => {
const artifactPage = new ArtifactPage(page);
const artifactImport = new ArtifactImportPage(page);
await page.goto('/dashboard/observations/artifacts')
await artifactPage.addNewArtifactImport().click();
artifactImport.getFileInput();
await artifactImport.getCreateArtifactImportButton().click();
await expect (artifactImport.getErrorMessage()).toBeVisible();
})
test('Artifact error message in the absence of a file.', async ({ page }) => {
const artifactPage = new ArtifactPage(page);
const artifactImport = new ArtifactImportPage(page);
await page.goto('/dashboard/observations/artifacts');
await artifactPage.addNewArtifactImport().click();
artifactImport.getFileInput();
await artifactImport.getCreateArtifactImportButton().click();
await expect(artifactImport.getErrorMessage()).toBeVisible();
});
4 changes: 2 additions & 2 deletions opencti-platform/opencti-front/tests_e2e/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test as setup } from './fixtures/baseFixtures';
import { DashboardPage } from "./model/dashboard.pageModel";
import { LoginPage } from "./model/login.pageModel";
import DashboardPage from './model/dashboard.pageModel';
import LoginPage from './model/login.pageModel';

const authFile = 'tests_e2e/.setup/.auth/user.json';
const prepLogoutFile = 'tests_e2e/.setup/.auth/logout-user.json';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "../fixtures/baseFixtures";
import { FiltersUtils } from '../model/filters.pageModel';
import { expect, test } from '../fixtures/baseFixtures';
import FiltersUtils from '../model/filters.pageModel';

test('Add a new filter in the observables list and check the filter is still present when we come back to the page', async ({ page }) => {
await page.goto('/dashboard/observations/observables');
Expand All @@ -9,4 +9,4 @@ test('Add a new filter in the observables list and check the filter is still pre
await page.goto('/dashboard/');
await page.goto('/dashboard/observations/observables');
await expect(page.getByRole('button', { name: 'Entity type = Artifact' })).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from '../fixtures/baseFixtures';
import { LeftBarPage } from '../model/menu/leftBar.pageModel';

import LeftBarPage from '../model/menu/leftBar.pageModel';

test('Check navigation on all pages', async ({ page }) => {
await page.goto('/');
Expand Down Expand Up @@ -92,5 +91,4 @@ test('Check navigation on all pages', async ({ page }) => {
await expect(page.getByRole('paragraph')).toHaveText('Investigations');
await leftBarPage.clickOnMenu('Dashboards');
await expect(page.getByRole('paragraph')).toHaveText('Dashboards');

});
});
8 changes: 4 additions & 4 deletions opencti-platform/opencti-front/tests_e2e/logout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect, test } from "./fixtures/baseFixtures";
import { LoginPage } from "./model/login.pageModel";
import { TopMenuProfilePage } from "./model/menu/topMenuProfile.pageModel";
import { expect, test } from './fixtures/baseFixtures';
import LoginPage from './model/login.pageModel';
import TopMenuProfilePage from './model/menu/topMenuProfile.pageModel';

test.use({ storageState: 'tests_e2e/.setup/.auth/logout-user.json' });
test('test logout', async ({ page }) => {
const loginPage = new LoginPage(page);
const topMenu = new TopMenuProfilePage(page)
const topMenu = new TopMenuProfilePage(page);
await page.goto('/');
await topMenu.logout();
await expect(loginPage.getPage()).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Page } from "@playwright/test";
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';

export class ArtifactPage {
constructor(private page: Page) {
}
getPage() {
return this.page.getByTestId('Artifact-page');
}
addNewArtifactImport() {
return this.page.getByLabel('Add', { exact: true })
}
}
export default class ArtifactPage {
constructor(private page: Page) {}

getPage() {
return this.page.getByTestId('Artifact-page');
}

addNewArtifactImport() {
return this.page.getByLabel('Add', { exact: true });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';

export default class ArtifactImportPage {
constructor(private page: Page) {}

getFileInput() {
return this.page.getByLabel('file');
}

getCreateArtifactImportButton() {
return this.page.getByRole('button', { name: 'Create' });
}

getErrorMessage() {
return this.page.getByText('This field is required');
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Page } from "@playwright/test";
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';

export class DashboardPage {
constructor(private page: Page) {
}
getPage() {
return this.page.getByTestId('dashboard-page');
}
export default class DashboardPage {
constructor(private page: Page) {}

getPage() {
return this.page.getByTestId('dashboard-page');
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';

export class FiltersUtils {
constructor(private page: Page) {
}
export default class FiltersUtils {
constructor(private page: Page) {}

async addFilter(filterKey: string, filterLabel: string) {
await this.page.getByLabel('Add filter').click();
await this.page.getByRole('option', { name: filterKey }).click();
await this.page.getByLabel(filterKey).click();
await this.page.getByLabel(filterLabel).getByRole('checkbox').check();
await this.page.locator('.MuiPopover-root > .MuiBackdrop-root').click();
}

}
71 changes: 38 additions & 33 deletions opencti-platform/opencti-front/tests_e2e/model/login.pageModel.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import { Page } from "@playwright/test";

export class LoginPage {
constructor(private page: Page) {
}

getPage() {
return this.page.getByTestId('login-page');
}
getLoginInput() {
return this.page.getByLabel('Login')
}
async fillLoginInput(input: string) {
await this.getLoginInput().click();
return this.getLoginInput().fill(input);
}
async fillPasswordInput(input: string) {
await this.getPasswordInput().click();
return this.getPasswordInput().fill(input);
}
getPasswordInput() {
return this.page.getByLabel('Password')
}
getSignInButton() {
return this.page.getByRole('button', { name: 'Sign in' })
}

async login() {
await this.page.goto('/');
await this.fillLoginInput('[email protected]');
await this.fillPasswordInput('admin');
return this.getSignInButton().click();
}
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';

export default class LoginPage {
constructor(private page: Page) {}

getPage() {
return this.page.getByTestId('login-page');
}

getLoginInput() {
return this.page.getByLabel('Login');
}

async fillLoginInput(input: string) {
await this.getLoginInput().click();
return this.getLoginInput().fill(input);
}

async fillPasswordInput(input: string) {
await this.getPasswordInput().click();
return this.getPasswordInput().fill(input);
}

getPasswordInput() {
return this.page.getByLabel('Password');
}

getSignInButton() {
return this.page.getByRole('button', { name: 'Sign in' });
}

async login() {
await this.page.goto('/');
await this.fillLoginInput('[email protected]');
await this.fillPasswordInput('admin');
return this.getSignInButton().click();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Page } from "@playwright/test";
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';
import { expect } from '../../fixtures/baseFixtures';

export class LeftBarPage {
constructor(private page:Page) {
}
export default class LeftBarPage {
constructor(private page:Page) {}

async clickOnMenu(menuName: string, subMenuItem?: string) {
await this.page.getByRole('menuitem', { name: menuName }).click();
if(subMenuItem) {
if (subMenuItem) {
await this.page.getByRole('menuitem', { name: subMenuItem }).click();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Page } from "@playwright/test";
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';

export class TopMenuProfilePage {
constructor(private page:Page) {
}
export default class TopMenuProfilePage {
constructor(private page:Page) {}

getMenuProfile() {
getMenuProfile() {
return this.page.getByLabel('Profile');
}
getLogoutButton() {
return this.page.getByRole('menuitem', { name: 'Logout' });
}

async logout() {
await this.getMenuProfile().click();
return this.getLogoutButton().click();
}
}

getLogoutButton() {
return this.page.getByRole('menuitem', { name: 'Logout' });
}

async logout() {
await this.getMenuProfile().click();
return this.getLogoutButton().click();
}
}
59 changes: 33 additions & 26 deletions opencti-platform/opencti-front/tests_e2e/model/report.pageModel.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import { Page } from "@playwright/test";

export class ReportPage {
constructor(private page: Page) {
}
getPage() {
return this.page.getByTestId('report-page');
}
goToPage() {
return this.page.getByLabel('Analyses').click();
}
addNewReport() {
return this.page.getByLabel('Add', { exact: true }).click()
}
closeNewreport() {
return this.page.getByLabel('Close', { exact: true }).click()
}
getReportNameInput() {
return this.page.getByLabel('Name');
}
getCreateReportButton() {
return this.page.getByRole('button', { name: 'Create', exact: true })
}
getItemFromList(name: string) {
return this.page.getByRole('link', { name }).first()
}
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';

export default class ReportPage {
constructor(private page: Page) {}

getPage() {
return this.page.getByTestId('report-page');
}

goToPage() {
return this.page.getByLabel('Analyses').click();
}

addNewReport() {
return this.page.getByLabel('Add', { exact: true }).click();
}

closeNewreport() {
return this.page.getByLabel('Close', { exact: true }).click();
}

getReportNameInput() {
return this.page.getByLabel('Name');
}

getCreateReportButton() {
return this.page.getByRole('button', { name: 'Create', exact: true });
}

getItemFromList(name: string) {
return this.page.getByRole('link', { name }).first();
}
}
Loading

0 comments on commit fe7d889

Please sign in to comment.