1+ // ***********************************************
2+ // This commands.js file
3+ // create various custom commands and overwrite
4+ // existing commands.
5+ //
6+ // For more comprehensive examples of custom
7+ // commands please read more here:
8+ // https://on.cypress.io/custom-commands
9+ // ***********************************************
10+
11+ import * as c from './const'
12+
13+ Cypress . Commands . add ( 'openNetflowTrafficPage' , ( ) => {
14+ //clear local storage to ensure to be in default view = table
15+ cy . clearLocalStorage ( ) ;
16+ cy . visit ( c . url ) ;
17+ } ) ;
18+
19+ Cypress . Commands . add ( 'checkColumns' , ( groups = 5 , cols = 9 ) => {
20+ if ( groups === 0 ) {
21+ //Should not have nested columns
22+ cy . get ( 'thead>tr' ) . should ( 'have.length' , 1 ) ;
23+
24+ //Should have correct number of columns
25+ cy . get ( 'thead>tr' ) . children ( ) . should ( 'have.length' , cols ) ;
26+ } else {
27+ //Should have nested columns
28+ cy . get ( 'thead>tr' ) . should ( 'have.length' , 2 ) ;
29+
30+ //Should have correct number of groups
31+ cy . get ( 'thead>tr' ) . eq ( 0 ) . children ( ) . should ( 'have.length' , groups ) ;
32+ //Should have correct number of columns
33+ cy . get ( 'thead>tr' ) . eq ( 1 ) . children ( ) . should ( 'have.length' , cols ) ;
34+ }
35+ } ) ;
36+
37+ Cypress . Commands . add ( 'openColumnsModal' , ( ) => {
38+ cy . get ( '#manage-columns-button' ) . click ( ) ;
39+ cy . get ( '#columns-modal' ) . should ( 'exist' ) ;
40+ } ) ;
41+
42+ Cypress . Commands . add ( 'selectColumns' , ( names ) => {
43+ for ( let i = 0 ; i < names . length ; i ++ ) {
44+ cy . get ( '.modal-body' ) . contains ( names [ i ] ) . click ( ) ;
45+ }
46+ } ) ;
47+
48+ Cypress . Commands . add ( 'sortColumn' , ( name ) => {
49+ cy . get ( 'thead' ) . contains ( name ) . click ( ) ;
50+ cy . get ( '[aria-sort="ascending"]' ) . should ( 'have.length' , 1 ) ;
51+ cy . get ( '[aria-sort="descending"]' ) . should ( 'have.length' , 0 ) ;
52+ cy . get ( 'thead' ) . contains ( name ) . click ( ) ;
53+ cy . get ( '[aria-sort="ascending"]' ) . should ( 'have.length' , 0 ) ;
54+ cy . get ( '[aria-sort="descending"]' ) . should ( 'have.length' , 1 ) ;
55+ } ) ;
56+
57+ Cypress . Commands . add ( 'dropdownSelect' , ( id , name ) => {
58+ cy . get ( `#${ id } ` ) . click ( ) ;
59+ cy . get ( '.pf-c-dropdown__menu' ) . should ( 'exist' ) ;
60+ cy . get ( '.pf-c-dropdown__menu' ) . find ( `#${ name } ` ) . click ( ) ;
61+ } ) ;
62+
63+ Cypress . Commands . add ( 'checkContent' , ( topology ) => {
64+ if ( topology ) {
65+ cy . get ( '[data-layer-id="default"]' ) . children ( ) . its ( 'length' ) . should ( 'be.gte' , 5 ) ;
66+ } else {
67+ cy . get ( '#table-container' ) . find ( 'tr' ) . its ( 'length' ) . should ( 'be.gte' , 5 ) ;
68+ }
69+ } ) ;
70+
71+ Cypress . Commands . add ( 'addCommonFilter' , ( filter , value , topology ) => {
72+ cy . get ( '#column-filter-toggle' ) . click ( ) ;
73+ cy . get ( '.pf-c-accordion__expanded-content-body' ) . find ( `#${ filter } ` ) . click ( ) ;
74+ cy . get ( '.pf-c-accordion__expanded-content-body' ) . should ( 'not.exist' ) ;
75+ cy . get ( '#column-filter-dropdown' ) . parent ( ) . children ( ) . eq ( 1 ) . type ( `${ value } {enter}` ) ;
76+ cy . checkContent ( topology ) ;
77+ } ) ;
78+
79+ Cypress . Commands . add ( 'changeQueryOption' , ( name , topology ) => {
80+ cy . get ( '[aria-label="Options menu"]' ) . click ( ) ;
81+ cy . get ( '#query-options-dropdown' ) . contains ( name ) . click ( ) ;
82+ cy . get ( '[aria-label="Options menu"]' ) . click ( ) ;
83+ cy . checkContent ( topology ) ;
84+ } ) ;
85+
86+ Cypress . Commands . add ( 'changeTimeRange' , ( name , topology ) => {
87+ cy . get ( '#time-range-dropdown-dropdown' ) . click ( ) ;
88+ cy . get ( '.pf-c-dropdown__menu' ) . contains ( name ) . click ( ) ;
89+ cy . checkContent ( topology ) ;
90+ } ) ;
91+
92+ Cypress . Commands . add ( 'changeMetricFunction' , ( name ) => {
93+ cy . get ( '#metricFunction-dropdown' ) . click ( ) ;
94+ cy . get ( '.pf-c-dropdown__menu' ) . contains ( name ) . click ( ) ;
95+ cy . get ( '[data-layer-id="default"]' ) . children ( ) . its ( 'length' ) . should ( 'be.gte' , 5 ) ;
96+ } ) ;
97+
98+ Cypress . Commands . add ( 'changeMetricType' , ( name ) => {
99+ cy . get ( '#metricType-dropdown' ) . click ( ) ;
100+ cy . get ( '.pf-c-dropdown__menu' ) . contains ( name ) . click ( ) ;
101+ cy . get ( '[data-layer-id="default"]' ) . children ( ) . its ( 'length' ) . should ( 'be.gte' , 5 ) ;
102+ } ) ;
0 commit comments