Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frontend/e2e] Navigation on groupings and malware analyses (#7378) #7860

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opencti-platform/opencti-front/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default defineConfig({
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'on-first-retry',
video: 'retain-on-failure',
ignoreHTTPSErrors: true,
},
expect: { timeout: 60000 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const MalwareAnalyses: FunctionComponent = () => {
<ExportContextProvider>
<Breadcrumbs variant="list" elements={[{ label: t_i18n('Analyses') }, { label: t_i18n('Malware analyses'), current: true }]} />
{queryRef && (
<div data-testid='malware-analyses-page'>
<DataTable
dataColumns={dataColumns}
resolvePath={(data: MalwareAnalysesLines_data$data) => data.malwareAnalyses?.edges?.map((n) => n?.node)}
Expand All @@ -177,11 +178,12 @@ const MalwareAnalyses: FunctionComponent = () => {
lineFragment={malwareAnalysisFragment}
exportContext={{ entity_type: 'Malware-Analysis' }}
createButton={isFABReplaced && (
<Security needs={[KNOWLEDGE_KNUPDATE]}>
<MalwareAnalysisCreation paginationOptions={queryPaginationOptions} />
</Security>
<Security needs={[KNOWLEDGE_KNUPDATE]}>
<MalwareAnalysisCreation paginationOptions={queryPaginationOptions} />
</Security>
)}
/>
</div>
)}
{!isFABReplaced && (
<Security needs={[KNOWLEDGE_KNUPDATE]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const GroupingComponent = ({ grouping }) => {
const { canEdit } = useGetCurrentUserAccessRight(grouping.currentUserAccessRight);

return (
<div data-testid="grouping-details-page">
<div data-testid='grouping-details-page'>
<Grid
container={true}
spacing={3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class GroupingKnowledgeComponent extends Component {
<div
className={classes.container}
id={location.pathname.includes('matrix') ? 'parent' : 'container'}
data-testid='groupings-knowledge'
>
{mode !== 'graph' && (
<ContainerHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ MalwareAnalysisDetailsProps
malwareAnalysisFragment,
);
return (
<div style={{ height: '100%' }}>
<div style={{ height: '100%' }}
data-testid='malware-analyses-details-page'
>
<Typography variant="h4" gutterBottom={true}>
{t_i18n('Details')}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class StixCoreObjectHistory extends Component {
container={true}
spacing={3}
classes={{ container: classes.gridContainer }}
data-testid='sco-history-content'
>
<Grid
item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ test('Add and remove observable from Observables tab of a Report as Admin user',
await reportPage.getCreateReportButton().click();
await reportPage.getItemFromList('Test add observable e2e').click();
await expect(reportDetailsPage.getPage()).toBeVisible();
await reportDetailsPage.goToObservablesTab();
await reportDetailsPage.tabs.goToObservablesTab();
await expect(containerObservablesPage.getPage()).toBeVisible();
await containerObservablesPage.getAddObservableListButton().click();
await containerAddObservablesPage.createNewIPV4Observable('8.8.8.8');
Expand All @@ -140,7 +140,7 @@ test('Add and remove observable from Observables tab of a Report as Admin user',

await leftBarPage.clickOnMenu('Analyses', 'Reports');
await reportPage.getItemFromList('Test add observable e2e').click();
await reportDetailsPage.goToObservablesTab();
await reportDetailsPage.tabs.goToObservablesTab();
await expect(containerObservablesPage.getPage()).toBeVisible();
await containerObservablesPage.getAddObservableListButton().click();
await expect(containerAddObservablesPage.getObservable('IPv4 address 8.8.8.8')).toBeVisible();
Expand Down Expand Up @@ -173,7 +173,7 @@ test.describe('Add and remove observable from Observables tab of a Report as noB
await reportPage.getCreateReportButton().click();
await reportPage.getItemFromList('Test add observable e2e 2').click();
await expect(reportDetailsPage.getPage()).toBeVisible();
await reportDetailsPage.goToObservablesTab();
await reportDetailsPage.tabs.goToObservablesTab();
await expect(containerObservablesPage.getPage()).toBeVisible();
await containerObservablesPage.getAddObservableListButton().click();
await containerAddObservablesPage.createNewIPV4Observable('9.9.9.9');
Expand All @@ -191,7 +191,7 @@ test.describe('Add and remove observable from Observables tab of a Report as noB

await leftBarPage.clickOnMenu('Analyses', 'Reports');
await reportPage.getItemFromList('Test add observable e2e 2').click();
await reportDetailsPage.goToObservablesTab();
await reportDetailsPage.tabs.goToObservablesTab();
await expect(containerObservablesPage.getPage()).toBeVisible();
await containerObservablesPage.getAddObservableListButton().click();
await expect(containerAddObservablesPage.getObservable('IPv4 address 9.9.9.9')).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('Create a new grouping', async ({ page }) => {
const stixDomainObjectContentTab = new StixDomainObjectContentTabPage(page);

// go to groupings
await page.goto('/dashboard/analyses/groupings');
await groupingsPage.goto();
await expect(groupingsPage.getPage()).toBeVisible();
// add a new grouping
await groupingsPage.addNew();
Expand All @@ -20,7 +20,7 @@ test('Create a new grouping', async ({ page }) => {
await groupingForm.submit();
// open it
await groupingsPage.getItemFromList('Test grouping e2e').click();
await expect(groupingDetails.getGroupingDetailsPage()).toBeVisible();
await expect(groupingDetails.getPage()).toBeVisible();
await expect(groupingDetails.getTitle('Test grouping e2e')).toBeVisible();
// add content
await groupingDetails.goToTab('Content');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Page } from '@playwright/test';
import LeftBarPage from './menu/leftBar.pageModel';

export default class MalwareAnalysesPage {
pageUrl = '/dashboard/analyses/malware_analyses';

constructor(private page: Page) {
}

/**
* Reload the page (like F5), mostly used once on test start.
* When possible please use navigateFromMenu instead it's faster.
*/
async goto() {
await this.page.goto(this.pageUrl);
}

async navigateFromMenu() {
const leftBarPage = new LeftBarPage(this.page);
await leftBarPage.open();
await leftBarPage.clickOnMenu('Analyses', 'Malware analyses');
}
getPage() {
return this.page.getByTestId('malware-analyses-page');
}

getItemFromList(name: string) {
return this.page.getByLabel(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Page } from '@playwright/test';
import SDOTabs from './SDOTabs.pageModel';

export default class MalwareAnalysesDetailsPage {
tabs = new SDOTabs(this.page);
constructor(private page: Page) {}

getPage() {
return this.page.getByTestId('malware-analyses-details-page');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Page } from '@playwright/test';

/**
* Common page for all components that have Overview/Knowledge/...etc tabs (in knowledge)
*/
export default class SDOTabs {
constructor(private page: Page) {}

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

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

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

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

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

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

goToHistoryTab() {
return this.page.getByRole('tab', { name: 'History' }).click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Page } from '@playwright/test';

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

getPage() {
return this.page.getByTestId('sco-history-content');
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { Page } from '@playwright/test';
import LeftBarPage from './menu/leftBar.pageModel';

export default class GroupingsPage {
pageUrl = '/dashboard/analyses/groupings';
constructor(private page: Page) {}

/**
* Reload the page (like F5), mostly used once on test start.
* When possible please use navigateFromMenu instead it's faster.
*/
async goto() {
await this.page.goto(this.pageUrl);
}

async navigateFromMenu() {
const leftBarPage = new LeftBarPage(this.page);
await leftBarPage.open();
await leftBarPage.clickOnMenu('Analyses', 'Groupings');
}

getPage() {
return this.page.getByTestId('groupings-page');
}
Expand All @@ -20,7 +36,7 @@ export default class GroupingsPage {
}

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

getItemFromList(name: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Page } from '@playwright/test';
import SDOTabs from './SDOTabs.pageModel';

export default class GroupingDetailsPage {
tabs = new SDOTabs(this.page);
constructor(private page: Page) {}

getGroupingDetailsPage() {
getPage() {
return this.page.getByTestId('grouping-details-page');
}

Expand Down
11 changes: 11 additions & 0 deletions opencti-platform/opencti-front/tests_e2e/model/report.pageModel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { Page } from '@playwright/test';
import LeftBarPage from './menu/leftBar.pageModel';

export default class ReportPage {
pageUrl = '/dashboard/analyses/reports';
constructor(private page: Page) {}

/**
* Reload the page (like F5), mostly used once on test start.
* When possible please use navigateFromMenu instead it's faster.
*/
async goto() {
await this.page.goto(this.pageUrl);
}

async navigateFromMenu() {
const leftBarPage = new LeftBarPage(this.page);
await leftBarPage.open();
await leftBarPage.clickOnMenu('Analyses', 'Reports');
}

getPage() {
return this.page.getByTestId('report-page');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Page } from '@playwright/test';
import AutocompleteFieldPageModel from './field/AutocompleteField.pageModel';
import SDOTabs from './SDOTabs.pageModel';

export default class ReportDetailsPage {
labelsSelect = new AutocompleteFieldPageModel(this.page, 'Labels', true);
tabs = new SDOTabs(this.page);

constructor(private page: Page) {}

Expand All @@ -18,34 +20,10 @@ export default class ReportDetailsPage {
return this.page.getByLabel('Update', { exact: true });
}

async goToOverviewTab() {
await this.page.getByRole('tab', { name: 'Overview' }).click();
}

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

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

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

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

getContentFile(fileName: string) {
return this.page.getByLabel(fileName);
}

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

getTextForHeading(heading: string, text: string) {
return this.page
.getByRole('heading', { name: heading })
Expand Down
Loading