Skip to content

Commit

Permalink
Clean up cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizhou Wang committed Dec 9, 2021
1 parent 4f11941 commit 20bcf99
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 33 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/session_view/cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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', () => {
Expand All @@ -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}`);
});
});
20 changes: 12 additions & 8 deletions x-pack/plugins/session_view/cypress/screens/common/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
export const getProcessTreeNodeAlertDetailViewRule = (alertUUID: string) =>
`[data-test-subj="sessionViewAlertDetailViewRule-${alertUUID}"]`;
2 changes: 1 addition & 1 deletion x-pack/plugins/session_view/cypress/urls/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export const SESSION_VIEW_URL = 'app/sessionView';
export const SESSION_VIEW_URL = 'app/sessionView/process_tree';
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const ProcessTree = ({
};

return (
<div ref={scrollerRef} css={styles.scroller}>
<div ref={scrollerRef} css={styles.scroller} data-test-subj="sessionViewProcessTree">
{sessionLeader && (
<ProcessTreeNode
isSessionLeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function ProcessTreeNode({
<EuiButton
css={styles.getButtonStyle(ButtonType.alerts)}
onClick={() => setAlertsExpanded(!alertsExpanded)}
data-test-subj="processTreeNodeAlertButton"
>
<FormattedMessage id="xpack.sessionView.alerts" defaultMessage="Alerts" />
<EuiIcon css={styles.buttonArrow} size="s" type={getExpandedIcon(alertsExpanded)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ export const SessionView = ({ sessionEntityId, height }: SessionViewDeps) => {
<EuiSearchBar query={searchQuery} onChange={onSearch} />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton onClick={toggleDetailPanel} iconType="list" fill>
<EuiButton
onClick={toggleDetailPanel}
iconType="list"
fill
data-test-subj="sessionViewDetailPanelToggle"
>
<FormattedMessage
id="xpack.sessionView.buttonOpenDetailPanel"
defaultMessage="Detail panel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const SessionViewDetailPanel = ({
color="plain"
css={isDetailMounted ? styles.detailPanelIn : styles.detailPanelOut}
onAnimationEnd={handleAnimationEnd}
data-test-subj="sessionViewDetailPanel"
>
{renderSelectedProcessCommandDetail()}
<div data-test-subj="sessionViewDetailPanelSessionDetail">
Expand Down

0 comments on commit 20bcf99

Please sign in to comment.