-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution][Attacks/Alerts] Add a scheduled attack icon (#17461) #271871
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
60503ef
3d0a64a
4855746
d68bb55
49a98ad
24fb94a
d897289
1d856e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,18 +53,21 @@ export class DetectionsAttackDiscoveryPage { | |
| public attacksPageAssigneeFilter: Locator; | ||
| public attacksPageConnectorFilter: Locator; | ||
| public attacksKpisSection: Locator; | ||
| public kpisSectionToggleButton: Locator; | ||
| public attacksSummaryView: Locator; | ||
| public attacksListPanel: Locator; | ||
| public attacksVolumePanel: Locator; | ||
| public attacksListTable: Locator; | ||
| public attacksTableSection: Locator; | ||
| public scheduleButton: Locator; | ||
| public settingsFlyout: Locator; | ||
| public scheduleDetailsFlyout: Locator; | ||
| public schedulesTable: Locator; | ||
| public attackDetailsFlyoutBody: Locator; | ||
| public assigneesFilterButton: Locator; | ||
| public connectorFilterButton: Locator; | ||
| public tableExpandAttackDetailsButtons: Locator; | ||
| public tableScheduleButtons: Locator; | ||
| public settingsButton: Locator; | ||
| public generateButton: Locator; | ||
| public runButton: Locator; | ||
|
|
@@ -84,20 +87,27 @@ export class DetectionsAttackDiscoveryPage { | |
| ATTACKS_PAGE_CONNECTOR_FILTER_TEST_ID | ||
| ); | ||
| this.attacksKpisSection = this.page.testSubj.locator(ATTACKS_KPIS_SECTION_TEST_ID); | ||
| this.kpisSectionToggleButton = this.attacksKpisSection.locator( | ||
| '[data-test-subj="query-toggle-header"]' | ||
|
e40pud marked this conversation as resolved.
Outdated
|
||
| ); | ||
| this.attacksSummaryView = this.page.testSubj.locator(ATTACKS_SUMMARY_VIEW_TEST_ID); | ||
| this.attacksListPanel = this.page.testSubj.locator(ATTACKS_LIST_PANEL_TEST_ID); | ||
| this.attacksVolumePanel = this.page.testSubj.locator(ATTACKS_VOLUME_PANEL_TEST_ID); | ||
| this.attacksListTable = this.page.testSubj.locator(ATTACKS_LIST_TABLE_TEST_ID); | ||
| this.attacksTableSection = this.page.testSubj.locator(ATTACKS_PAGE_TABLE_SECTION_TEST_ID); | ||
| this.scheduleButton = this.page.testSubj.locator(SCHEDULE_BUTTON_TEST_ID); | ||
| this.settingsFlyout = this.page.testSubj.locator(SETTINGS_FLYOUT_TEST_ID); | ||
| this.scheduleDetailsFlyout = this.page.testSubj.locator('scheduleDetailsFlyout'); | ||
| this.schedulesTable = this.page.testSubj.locator(SCHEDULES_TABLE_TEST_ID); | ||
| this.attackDetailsFlyoutBody = this.page.testSubj.locator(ATTACK_DETAILS_FLYOUT_BODY_TEST_ID); | ||
| this.assigneesFilterButton = this.page.testSubj.locator(FILTER_BY_ASSIGNEES_BUTTON_TEST_ID); | ||
| this.connectorFilterButton = this.page.testSubj.locator(CONNECTOR_FILTER_BUTTON_TEST_ID); | ||
| this.tableExpandAttackDetailsButtons = this.attacksTableSection.locator( | ||
| `[data-test-subj="${EXPAND_ATTACK_BUTTON_TEST_ID}"]` | ||
| ); | ||
| this.tableScheduleButtons = this.attacksTableSection.locator( | ||
| `[data-test-subj="scheduleButton"]` | ||
| ); | ||
| this.settingsButton = this.page.testSubj.locator('settings'); | ||
| this.generateButton = this.page.testSubj.locator('generate'); | ||
| this.runButton = this.page.testSubj.locator('run'); | ||
|
|
@@ -161,6 +171,13 @@ export class DetectionsAttackDiscoveryPage { | |
| await this.detectionsNavItem.click(); | ||
| } | ||
|
|
||
| async collapseKpisSection() { | ||
| if (await this.attacksSummaryView.isVisible()) { | ||
| await this.kpisSectionToggleButton.click(); | ||
| await this.attacksSummaryView.waitFor({ state: 'hidden' }); | ||
| } | ||
| } | ||
|
|
||
| async openScheduleFlyout() { | ||
| await this.scheduleButton.click(); | ||
| await this.settingsFlyout.waitFor({ state: 'visible' }); | ||
|
|
@@ -177,4 +194,15 @@ export class DetectionsAttackDiscoveryPage { | |
| await firstExpandAttackButton.click(); | ||
| await this.attackDetailsFlyoutBody.waitFor({ state: 'visible' }); | ||
| } | ||
|
|
||
| async openFirstScheduleDetailsFromTable() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is semantically equivalent to .first(), which playwright/no-nth-methods targets. Since the test always seeds exactly one attack and tableScheduleButtons is already scoped to attacksTableSection, the locator should resolve to a single element — which means await this.tableScheduleButtons.click() would work directly and Playwright's strict mode would enforce uniqueness. The .all() destructure adds complexity without benefit here. The same issue exists in the pre-existing openFirstAttackDetailsFromTable() method — but since you're adding a new method, it's worth getting right rather than copying the pattern.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that |
||
| const [firstScheduleButton] = await this.tableScheduleButtons.all(); | ||
|
|
||
| if (!firstScheduleButton) { | ||
| throw new Error('No schedule button found'); | ||
| } | ||
|
|
||
| await firstScheduleButton.click(); | ||
| await this.scheduleDetailsFlyout.waitFor({ state: 'visible' }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { render, fireEvent } from '@testing-library/react'; | ||
|
|
||
| import { ScheduleDetailsButton } from './schedule_details_button'; | ||
|
|
||
| describe('ScheduleDetailsButton', () => { | ||
| it('renders the button and tooltip', () => { | ||
| const onClickMock = jest.fn(); | ||
| const { getByTestId, getByLabelText } = render(<ScheduleDetailsButton onClick={onClickMock} />); | ||
|
|
||
| const button = getByTestId('scheduleButton'); | ||
| expect(button).toBeInTheDocument(); | ||
| expect(getByLabelText('Open schedule details')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls onClick when the button is clicked', () => { | ||
| const onClickMock = jest.fn(); | ||
| const { getByTestId } = render(<ScheduleDetailsButton onClick={onClickMock} />); | ||
|
|
||
| const button = getByTestId('scheduleButton'); | ||
| fireEvent.click(button); | ||
|
|
||
| expect(onClickMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React, { useCallback } from 'react'; | ||
| import { EuiButtonIcon, EuiFlexItem, EuiToolTip } from '@elastic/eui'; | ||
|
|
||
| import * as i18n from './translations'; | ||
|
|
||
| export interface ScheduleDetailsButtonProps { | ||
| onClick: () => void; | ||
| } | ||
|
|
||
| export const ScheduleDetailsButton = React.memo<ScheduleDetailsButtonProps>(({ onClick }) => { | ||
| const handleClick = useCallback( | ||
| (event: React.MouseEvent<HTMLButtonElement>) => { | ||
| event.stopPropagation(); | ||
| onClick(); | ||
| }, | ||
| [onClick] | ||
| ); | ||
|
|
||
| return ( | ||
| <EuiFlexItem grow={false}> | ||
| <EuiToolTip | ||
| content={i18n.SCHEDULED_ATTACK_DISCOVERY} | ||
| data-test-subj="scheduledTooltip" | ||
| position="top" | ||
| > | ||
| <EuiButtonIcon | ||
| aria-label={i18n.OPEN_SCHEDULE_DETAILS} | ||
| data-test-subj="scheduleButton" | ||
| iconType="calendar" | ||
| onClick={handleClick} | ||
| size="xs" | ||
| /> | ||
| </EuiToolTip> | ||
| </EuiFlexItem> | ||
| ); | ||
| }); | ||
| ScheduleDetailsButton.displayName = 'ScheduleDetailsButton'; |
Uh oh!
There was an error while loading. Please reload this page.