Skip to content

Commit

Permalink
[frontend] wip e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
lndrtrbn committed Apr 22, 2024
1 parent 8ea5575 commit deacb1c
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 158 deletions.
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = {
ignoreTemplateLiterals: true,
},
],
'@typescript-eslint/lines-between-class-members': 'off',
'@typescript-eslint/naming-convention': ['error', {
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,24 @@ class StixDomainObjectOverview extends Component {
/>
</>
)}
<Typography
variant="h3"
gutterBottom={true}
style={{
marginTop:
withPattern
|| (!withoutMarking && stixDomainObject.objectMarking)
? 20
: 0,
}}
>
{t('Author')}
</Typography>
<ItemAuthor
createdBy={R.propOr(null, 'createdBy', stixDomainObject)}
/>
<div>
<Typography
variant="h3"
gutterBottom={true}
style={{
marginTop:
withPattern
|| (!withoutMarking && stixDomainObject.objectMarking)
? 20
: 0,
}}
>
{t('Author')}
</Typography>
<ItemAuthor
createdBy={R.propOr(null, 'createdBy', stixDomainObject)}
/>
</div>
{(displayConfidence || displayReliability) && (
<Grid container={true} columnSpacing={1}>
{displayReliability && (
Expand Down Expand Up @@ -236,7 +238,7 @@ class StixDomainObjectOverview extends Component {
disabled={!stixDomainObject.workflowEnabled}
/>
{displayAssignees && (
<>
<div>
<Typography
variant="h3"
gutterBottom={true}
Expand All @@ -245,10 +247,10 @@ class StixDomainObjectOverview extends Component {
{t('Assignees')}
</Typography>
<ItemAssignees assignees={stixDomainObject.objectAssignee ?? []}/>
</>
</div>
)}
{displayParticipants && (
<>
<div>
<Typography
variant="h3"
gutterBottom={true}
Expand All @@ -257,7 +259,7 @@ class StixDomainObjectOverview extends Component {
{t('Participants')}
</Typography>
<ItemParticipants participants={stixDomainObject.objectParticipant ?? []}/>
</>
</div>
)}
<Typography
variant="h3"
Expand Down Expand Up @@ -285,14 +287,16 @@ class StixDomainObjectOverview extends Component {
{t('Platform creation date')}
</Typography>
{fldt(stixDomainObject.created_at)}
<Typography
variant="h3"
gutterBottom={true}
style={{ marginTop: 20 }}
>
{t('Creators')}
</Typography>
<ItemCreators creators={stixDomainObject.creators ?? []} />
<div>
<Typography
variant="h3"
gutterBottom={true}
style={{ marginTop: 20 }}
>
{t('Creators')}
</Typography>
<ItemCreators creators={stixDomainObject.creators ?? []} />
</div>
<div style={{ marginTop: 20 }}>
<Typography
variant="h3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Locator, Page } from '@playwright/test';

export default class ConfidenceFieldPageModel {
private alertLocator: Locator;
private readonly alertLocator: Locator;

constructor(private label: string, private page: Page) {
constructor(
private readonly page: Page,
private readonly label: string
) {
this.alertLocator = this.page.getByRole('alert', { name: label });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Locator, Page } from '@playwright/test';

export default class DateFieldPageModel {
private readonly inputLocator: Locator;

constructor(
private readonly page: Page,
label: string,
) {
this.inputLocator = this.page.getByLabel(label);
}

getInput() {
return this.inputLocator;
}

value() {
return this.inputLocator.inputValue();
}

async clear() {
await this.inputLocator.click();
await this.page.keyboard.press('Control+A');
return this.page.keyboard.press('Backspace');
}

async fill(input: string) {
await this.inputLocator.click();
return this.page.keyboard.type(input);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { Locator, Page } from '@playwright/test';

interface SelectFieldPageModelOptions {
page: Page
multiple?: boolean
}

export default class SelectFieldPageModel {
private page: Page;

private multiple: boolean;

private inputLocator: Locator;

private parentLocator: Locator;

constructor(private label: string, { page, multiple = true }: SelectFieldPageModelOptions) {
this.page = page;
this.multiple = multiple;
private readonly inputLocator: Locator;
private readonly parentLocator: Locator;

constructor(
private readonly page: Page,
private readonly label: string,
private readonly multiple = true,
) {
this.inputLocator = this.page.getByRole('combobox', { name: label });
this.parentLocator = this.inputLocator.locator('..');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Locator, Page } from '@playwright/test';

type TextFieldPageModelType = 'text' | 'text-area' | 'rich-content';

export default class TextFieldPageModel {
private readonly inputLocator: Locator;

constructor(
private readonly page: Page,
label: string,
type: TextFieldPageModelType = 'text',
) {
if (type === 'text-area') {
const parent = this.page.getByText(label).locator('..');
this.inputLocator = parent.getByTestId('text-area');
} else if (type === 'rich-content') {
const parent = this.page.getByText(label).locator('..');
this.inputLocator = parent.getByLabel('Editor editing area: main');
} else {
this.inputLocator = this.page.getByLabel(label);
}
}

get() {
return this.inputLocator;
}

value() {
return this.inputLocator.inputValue();
}

async clear() {
await this.inputLocator.clear();
}

async fill(input: string, clear = true) {
await this.inputLocator.click();
if (clear) await this.clear();
return this.inputLocator.fill(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ export default class ReportPage {
return this.page.getByTestId('report-page');
}

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

addNewReport() {
return this.page.getByLabel('Add', { exact: true }).click();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ export default class ReportDetailsPage {
return this.page.getByLabel('Edit');
}

goToContentTab() {
return this.page.getByRole('tab', { name: 'Content' }).click();
}

getObservablesTab() {
return this.page.getByRole('tab', { name: 'Observables' });
}

getTextForHeading(heading: string, text: string) {
return this.page
.getByRole('heading', { name: heading })
.locator('..')
.getByText(text);
}
}
Original file line number Diff line number Diff line change
@@ -1,95 +1,41 @@
import { Page } from '@playwright/test';
import SelectFieldPageModel from './field/SelectField.pageModel';
import ConfidenceFieldPageModel from './field/ConfidenceField.pageModel';
import DateFieldPageModel from './field/DateField.pageModel';
import TextFieldPageModel from './field/TextField.pageModel';

export default class ReportFormPage {
reportTypesSelect = new SelectFieldPageModel('Report types', {
page: this.page,
});
nameField = new TextFieldPageModel(this.page, 'Name');
contentField = new TextFieldPageModel(this.page, 'Content', 'rich-content');
descriptionField = new TextFieldPageModel(this.page, 'Description', 'text-area');

reliabilitySelect = new SelectFieldPageModel('Reliability', {
page: this.page,
multiple: false,
});
confidenceLevelField = new ConfidenceFieldPageModel(this.page, 'Confidence level');

assigneesSelect = new SelectFieldPageModel('Assignee(s)', {
page: this.page,
multiple: true,
});
publicationDateField = new DateFieldPageModel(this.page, 'Publication date');

participantsSelect = new SelectFieldPageModel('Participant(s)', {
page: this.page,
multiple: true,
});

authorSelect = new SelectFieldPageModel('Author', {
page: this.page,
multiple: false,
});

labelsSelect = new SelectFieldPageModel('Labels', {
page: this.page,
multiple: true,
});

markingsSelect = new SelectFieldPageModel('Markings', {
page: this.page,
multiple: true,
});

externalReferencesSelect = new SelectFieldPageModel('External references', {
page: this.page,
multiple: true,
});

confidenceLevelField = new ConfidenceFieldPageModel('Confidence level', this.page);
labelsSelect = new SelectFieldPageModel(this.page, 'Labels');
markingsSelect = new SelectFieldPageModel(this.page, 'Markings');
authorSelect = new SelectFieldPageModel(this.page, 'Author', false);
assigneesSelect = new SelectFieldPageModel(this.page, 'Assignee(s)');
reportTypesSelect = new SelectFieldPageModel(this.page, 'Report types');
participantsSelect = new SelectFieldPageModel(this.page, 'Participant(s)');
reliabilitySelect = new SelectFieldPageModel(this.page, 'Reliability', false);

constructor(private page: Page) {}

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

getPublicationDateInput() {
return this.page.getByLabel('Publication date');
}

getDescriptionInput() {
return this.page.getByTestId('text-area');
}

getContentInput() {
return this.page.getByLabel('Editor editing area: main');
getTitle() {
return this.page.getByRole('heading', { name: 'Create a report' });
}

async fillNameInput(input: string) {
await this.getNameInput().click();
return this.getNameInput().fill(input);
}

async clearPublicationDateInput() {
await this.getPublicationDateInput().click();
await this.page.keyboard.press('Control+A');
return this.page.keyboard.press('Backspace');
}

async fillPublicationDateInput(input: string) {
await this.getPublicationDateInput().click();
return this.page.keyboard.type(input);
}

async fillDescriptionInput(input: string) {
await this.getDescriptionInput().click();
return this.getDescriptionInput().fill(input);
}

async fillContentInput(input: string) {
await this.getContentInput().click();
await this.getContentInput().clear();
return this.getContentInput().fill(input);
getCreateButton() {
return this.page.getByRole('button', { name: 'Create', exact: true });
}

getCloseButton() {
return this.page.getByRole('button', { name: 'Close' });
}

getCancelButton() {
return this.page.getByRole('button', { name: 'Cancel' });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test report e2e</title>
</head>
<body>
<h1>Test Report e2e</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test report e2e
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test report e2e

0 comments on commit deacb1c

Please sign in to comment.