From 20bcf9915f4bd3ad312e1b7e4997809606fb11d7 Mon Sep 17 00:00:00 2001 From: Zizhou Wang Date: Wed, 8 Dec 2021 19:49:03 -0500 Subject: [PATCH] Clean up cypress tests --- x-pack/plugins/session_view/cypress/README.md | 2 +- .../cypress/integration/session_view.spec.ts | 71 +++++++++++++------ .../cypress/screens/common/page.ts | 20 +++--- .../session_view/cypress/urls/navigation.ts | 2 +- .../public/components/ProcessTree/index.tsx | 2 +- .../components/ProcessTreeNode/index.tsx | 1 + .../public/components/SessionView/index.tsx | 7 +- .../SessionViewDetailPanel/index.tsx | 1 + 8 files changed, 73 insertions(+), 33 deletions(-) diff --git a/x-pack/plugins/session_view/cypress/README.md b/x-pack/plugins/session_view/cypress/README.md index 6967714e441741..7e97c80aa7a743 100644 --- a/x-pack/plugins/session_view/cypress/README.md +++ b/x-pack/plugins/session_view/cypress/README.md @@ -224,7 +224,7 @@ node ../../../scripts/es_archiver save ../../test/session_view_cypress/es_archiv Example: ```sh -node ../../../scripts/es_archiver save ../../test/session_view_cypress/es_archives ".kibana",".siem-signal*","cmd","cmd_entry_leader" --config ../../../test/functional/config.js --es-url http://elastic:changeme@localhost:9200 +node ../../../scripts/es_archiver save ../../test/session_view_cypress/es_archives ".siem-signal*","cmd","cmd_entry_leader" --config ../../../test/functional/config.js --es-url http://elastic:changeme@localhost:9200 ``` Note that the command will create the folder if it does not exist. diff --git a/x-pack/plugins/session_view/cypress/integration/session_view.spec.ts b/x-pack/plugins/session_view/cypress/integration/session_view.spec.ts index e08c0d78925d13..c199234656298d 100644 --- a/x-pack/plugins/session_view/cypress/integration/session_view.spec.ts +++ b/x-pack/plugins/session_view/cypress/integration/session_view.spec.ts @@ -9,7 +9,26 @@ import { loginAndWaitForPage } from '../tasks/login'; import { SESSION_VIEW_URL } from '../urls/navigation'; import { cleanKibana } from '../tasks/common'; import { esArchiverLoad } from '../tasks/es_archiver'; -import { DETAILS_PANEL, DETAILS_PANEL_TOGGLE, SEARCH_BAR } from '../screens/common/page'; +import { + PROCESS_TREE, + PROCESS_TREE_NODE, + PROCESS_TREE_NODE_ALERT, + DETAILS_PANEL, + DETAILS_PANEL_TOGGLE, + DETAILS_PANEL_ALERT, + DETAILS_PANEL_COMMAND, + DETAILS_PANEL_SESSION, + DETAILS_PANEL_SERVER, + SEARCH_BAR, + getProcessTreeNodeAlertDetailViewRule, +} from '../screens/common/page'; + +const LS_TEST_COMMAND = 'ls --color=auto'; +const ALERT_TEST_COMMAND = 'vi EventConverter/package.json'; +const ALERT_NODE_TEST_ID = getProcessTreeNodeAlertDetailViewRule( + '1900f4bb07c6fcc64eb754ed97a83a952aa7698eaffe14749709e83f7b6bdb0d' +); +const ALERT_RULE_ID = '15b43080-5204-11ec-a8f5-f507bc52c10c'; describe('Display session view test page', () => { beforeEach(() => { @@ -20,24 +39,38 @@ describe('Display session view test page', () => { it('General Layout for Session View', () => { loginAndWaitForPage(SESSION_VIEW_URL); - cy.contains('Process Tree').click().wait(1000); // Checking Search bar exist cy.get(SEARCH_BAR).should('be.visible'); - // Making sure commands from POST curl shows up - cy.contains('ls --color=auto').click(); + + // Check detail panel and its toggle work correctly + cy.get(DETAILS_PANEL).should('not.exist'); // Checking Details panel exist - cy.get(DETAILS_PANEL_TOGGLE).contains('Detail panel').click(); - // Checking Command, Session, Server Detail exist - cy.get(DETAILS_PANEL).contains('Command detail'); - cy.get(DETAILS_PANEL).contains('Session detail'); - cy.get(DETAILS_PANEL).contains('Server detail'); + cy.get(DETAILS_PANEL_TOGGLE).click(); + cy.get(DETAILS_PANEL).should('be.visible'); + + // Only Session, Server Detail exist when no commands selected when detail panel is open + cy.get(DETAILS_PANEL_ALERT).should('not.exist'); + cy.get(DETAILS_PANEL_COMMAND).should('not.exist'); + cy.get(DETAILS_PANEL_SESSION).should('be.visible'); + cy.get(DETAILS_PANEL_SERVER).should('exist'); + + const lsCommandNode = cy.get(`${PROCESS_TREE} ${PROCESS_TREE_NODE}`).eq(1); + lsCommandNode.contains(LS_TEST_COMMAND).should('be.visible'); + lsCommandNode.click(); + // Checking Command, Session, Server Detail exist for a command without alert + cy.get(DETAILS_PANEL_ALERT).should('not.exist'); + cy.get(DETAILS_PANEL_COMMAND).should('be.visible'); + cy.get(DETAILS_PANEL_SESSION).should('exist'); + cy.get(DETAILS_PANEL_SERVER).should('exist'); - cy.contains('vi EventConverter/package.json').click(); + const viCommand = cy.get(`${PROCESS_TREE} ${PROCESS_TREE_NODE}`).eq(3); + viCommand.contains(ALERT_TEST_COMMAND).should('be.visible'); + viCommand.click(); // Checking Command, Session, Server, Alert Detail exist - cy.get(DETAILS_PANEL).contains('Command detail'); - cy.get(DETAILS_PANEL).contains('Session detail'); - cy.get(DETAILS_PANEL).contains('Server detail'); - cy.get(DETAILS_PANEL).contains('Alert detail'); + cy.get(DETAILS_PANEL_ALERT).should('exist'); + cy.get(DETAILS_PANEL_COMMAND).should('be.visible'); + cy.get(DETAILS_PANEL_SESSION).should('exist'); + cy.get(DETAILS_PANEL_SERVER).should('exist'); }); // it('Search Functionality', () => { @@ -50,12 +83,8 @@ describe('Display session view test page', () => { it('Alerts Check', () => { loginAndWaitForPage(SESSION_VIEW_URL); - cy.contains('Process Tree').click().wait(1000); - cy.contains('Alerts').first().click(); - cy.contains('View rule').first().click(); - cy.location('pathname').should( - 'contain', - 'app/security/rules/id/15b43080-5204-11ec-a8f5-f507bc52c10c' - ); + cy.get(PROCESS_TREE_NODE_ALERT).first().click(); + cy.get(ALERT_NODE_TEST_ID).first().click(); + cy.location('pathname').should('contain', `app/security/rules/id/${ALERT_RULE_ID}`); }); }); diff --git a/x-pack/plugins/session_view/cypress/screens/common/page.ts b/x-pack/plugins/session_view/cypress/screens/common/page.ts index 99204aa352ac5c..3d26a0b8097a13 100644 --- a/x-pack/plugins/session_view/cypress/screens/common/page.ts +++ b/x-pack/plugins/session_view/cypress/screens/common/page.ts @@ -4,13 +4,17 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +export const PROCESS_TREE = '[data-test-subj="sessionViewProcessTree"]'; +export const PROCESS_TREE_NODE = '[data-test-subj="processTreeNode"]'; +export const PROCESS_TREE_NODE_ALERT = '[data-test-subj="processTreeNodeAlertButton"]'; +export const SEARCH_BAR = '[data-test-subj="sessionViewProcessEventsSearch"]'; -export const TEST = '[data-test-subj="sessionViewTestPage"]'; +export const DETAILS_PANEL = '[data-test-subj="sessionViewDetailPanel"]'; +export const DETAILS_PANEL_TOGGLE = '[data-test-subj="sessionViewDetailPanelToggle"]'; +export const DETAILS_PANEL_ALERT = '[data-test-subj="sessionViewDetailPanelAlertDetail"]'; +export const DETAILS_PANEL_COMMAND = '[data-test-subj="sessionViewDetailPanelCommandDetail"]'; +export const DETAILS_PANEL_SESSION = '[data-test-subj="sessionViewDetailPanelSessionDetail"]'; +export const DETAILS_PANEL_SERVER = '[data-test-subj="sessionViewDetailPanelServerDetail"]'; -export const DETAILS_PANEL = 'span.euiTitle.euiTitle--small'; - -export const DETAILS_PANEL_TOGGLE = 'span.euiButton__text'; - -//export const SEARCH_BAR = '[aria-label="This is a search bar. After typing your query, hit enter to filter the results lower in the page."]' - -export const SEARCH_BAR = 'input.euiFieldSearch.euiFieldSearch--fullWidth' \ No newline at end of file +export const getProcessTreeNodeAlertDetailViewRule = (alertUUID: string) => + `[data-test-subj="sessionViewAlertDetailViewRule-${alertUUID}"]`; diff --git a/x-pack/plugins/session_view/cypress/urls/navigation.ts b/x-pack/plugins/session_view/cypress/urls/navigation.ts index fc632b9646dfab..2dde79d4877850 100644 --- a/x-pack/plugins/session_view/cypress/urls/navigation.ts +++ b/x-pack/plugins/session_view/cypress/urls/navigation.ts @@ -5,4 +5,4 @@ * 2.0. */ -export const SESSION_VIEW_URL = 'app/sessionView'; +export const SESSION_VIEW_URL = 'app/sessionView/process_tree'; diff --git a/x-pack/plugins/session_view/public/components/ProcessTree/index.tsx b/x-pack/plugins/session_view/public/components/ProcessTree/index.tsx index 22a5a66245cbca..b6a95ca18e5dcc 100644 --- a/x-pack/plugins/session_view/public/components/ProcessTree/index.tsx +++ b/x-pack/plugins/session_view/public/components/ProcessTree/index.tsx @@ -141,7 +141,7 @@ export const ProcessTree = ({ }; return ( -
+
{sessionLeader && ( setAlertsExpanded(!alertsExpanded)} + data-test-subj="processTreeNodeAlertButton" > diff --git a/x-pack/plugins/session_view/public/components/SessionView/index.tsx b/x-pack/plugins/session_view/public/components/SessionView/index.tsx index a4bfccf1f31d53..aea67e214bec4b 100644 --- a/x-pack/plugins/session_view/public/components/SessionView/index.tsx +++ b/x-pack/plugins/session_view/public/components/SessionView/index.tsx @@ -134,7 +134,12 @@ export const SessionView = ({ sessionEntityId, height }: SessionViewDeps) => { - + {renderSelectedProcessCommandDetail()}