6
6
/// <reference types="cypress" />
7
7
8
8
import {
9
- TEST_NOTEBOOK ,
10
9
SAMPLE_URL ,
11
10
BASE_PATH ,
12
11
delayTime ,
@@ -16,81 +15,118 @@ import {
16
15
17
16
import { skipOn } from '@cypress/skip-test' ;
18
17
19
- let loadedOnce = 0 ;
18
+ const testNotebookName = ( ) => {
19
+ let code = ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) ;
20
+ return `Test Notebook ${ code } ` ;
21
+ } ;
20
22
21
23
const moveToNotebookHome = ( ) => {
22
24
cy . visit ( `${ BASE_PATH } /app/observability-notebooks#/` ) ;
23
25
} ;
24
26
25
- const moveToTestNotebook = ( ) => {
27
+ const moveToTestNotebook = ( notebookName ) => {
26
28
cy . visit ( `${ BASE_PATH } /app/observability-notebooks#/` , {
27
29
timeout : delayTime * 3 ,
28
30
} ) ;
29
31
30
32
// Force refresh the observablity index and reload page to load notebooks.
31
- if ( loadedOnce === 0 ) {
32
- cy . request ( {
33
+ cy . request ( {
34
+ method : 'POST' ,
35
+ failOnStatusCode : false ,
36
+ form : false ,
37
+ url : 'api/console/proxy' ,
38
+ headers : {
39
+ 'content-type' : 'application/json;charset=UTF-8' ,
40
+ 'osd-xsrf' : true ,
41
+ } ,
42
+ qs : {
43
+ path : `${ OBSERVABILITY_INDEX_NAME } /_refresh` ,
33
44
method : 'POST' ,
34
- failOnStatusCode : false ,
35
- form : false ,
36
- url : 'api/console/proxy' ,
37
- headers : {
38
- 'content-type' : 'application/json;charset=UTF-8' ,
39
- 'osd-xsrf' : true ,
40
- } ,
41
- qs : {
42
- path : `${ OBSERVABILITY_INDEX_NAME } /_refresh` ,
43
- method : 'POST' ,
44
- } ,
45
- } ) ;
46
- cy . reload ( ) ;
47
- loadedOnce = 1 ;
48
- }
45
+ } ,
46
+ } ) ;
47
+ cy . reload ( ) ;
49
48
50
49
cy . get ( '.euiTableCellContent' )
51
- . contains ( TEST_NOTEBOOK , {
50
+ . contains ( notebookName , {
52
51
timeout : delayTime * 3 ,
53
52
} )
54
53
. click ( ) ;
55
54
} ;
56
55
56
+ const makeTestNotebook = ( ) => {
57
+ let notebookName = testNotebookName ( ) ;
58
+
59
+ moveToNotebookHome ( ) ;
60
+ cy . get ( 'a[data-test-subj="createNotebookPrimaryBtn"]' ) . click ( ) ;
61
+ cy . get ( 'input[data-test-subj="custom-input-modal-input"]' ) . focus ( ) ;
62
+ cy . get ( 'input[data-test-subj="custom-input-modal-input"]' ) . type ( notebookName ) ;
63
+ cy . get ( 'button[data-test-subj="custom-input-modal-confirm-button"]' ) . click ( ) ;
64
+ cy . get ( 'h1[data-test-subj="notebookTitle"]' )
65
+ . contains ( notebookName )
66
+ . should ( 'exist' ) ;
67
+
68
+ return notebookName ;
69
+ } ;
70
+
71
+ const makeParagraph = ( ) => {
72
+ cy . get ( 'button[data-test-subj="emptyNotebookAddCodeBlockBtn"]' ) . click ( ) ;
73
+ cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . should ( 'exist' ) ;
74
+ } ;
75
+
76
+ const makePopulatedParagraph = ( ) => {
77
+ makeParagraph ( ) ;
78
+ cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . clear ( ) ;
79
+ cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . focus ( ) ;
80
+ cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . type ( MARKDOWN_TEXT ) ;
81
+ cy . get ( 'button[data-test-subj="runRefreshBtn-0"]' ) . click ( ) ;
82
+ } ;
83
+
84
+ const deleteNotebook = ( notebookName ) => {
85
+ moveToNotebookHome ( ) ;
86
+
87
+ cy . contains ( '.euiTableRow' , notebookName )
88
+ . find ( 'input[type="checkbox"]' )
89
+ . check ( ) ;
90
+
91
+ cy . get ( 'button[data-test-subj="notebookTableActionBtn"]' ) . click ( ) ;
92
+ cy . get ( 'button[data-test-subj="deleteNotebookBtn"]' ) . click ( ) ;
93
+
94
+ cy . get ( 'input[data-test-subj="delete-notebook-modal-input"]' ) . focus ( ) ;
95
+ cy . get ( 'input[data-test-subj="delete-notebook-modal-input"]' ) . type ( 'delete' ) ;
96
+ cy . get ( 'button[data-test-subj="delete-notebook-modal-delete-button"]' ) . should (
97
+ 'not.be.disabled'
98
+ ) ;
99
+ cy . get (
100
+ 'button[data-test-subj="delete-notebook-modal-delete-button"]'
101
+ ) . click ( ) ;
102
+ moveToNotebookHome ( ) ;
103
+
104
+ cy . contains ( '.euiTableRow' , notebookName ) . should ( 'not.exist' ) ;
105
+ } ;
106
+
57
107
describe ( 'Testing notebook actions' , ( ) => {
58
- before ( ( ) => {
59
- moveToNotebookHome ( ) ;
60
- cy . get ( 'a[data-test-subj="createNotebookPrimaryBtn"]' ) . click ( ) ;
61
- cy . get ( 'input[data-test-subj="custom-input-modal-input"]' ) . focus ( ) ;
62
- cy . get ( 'input[data-test-subj="custom-input-modal-input"]' ) . type (
63
- TEST_NOTEBOOK
64
- ) ;
65
- cy . get (
66
- 'button[data-test-subj="custom-input-modal-confirm-button"]'
67
- ) . click ( ) ;
68
- cy . get ( 'h1[data-test-subj="notebookTitle"]' )
69
- . contains ( TEST_NOTEBOOK )
70
- . should ( 'exist' ) ;
108
+ beforeEach ( ( ) => {
109
+ let notebookName = makeTestNotebook ( ) ;
110
+ moveToTestNotebook ( notebookName ) ;
111
+ cy . wrap ( { name : notebookName } ) . as ( 'notebook' ) ;
71
112
} ) ;
72
113
73
- beforeEach ( ( ) => {
74
- moveToTestNotebook ( ) ;
114
+ afterEach ( function ( ) {
115
+ // ^^^^^^^^ Cannot use arrow callback to access beforeEach wrapper state
116
+ deleteNotebook ( this . notebook . name ) ;
75
117
} ) ;
76
118
77
119
it ( 'Creates a code paragraph' , ( ) => {
78
- cy . get ( 'button[data-test-subj="emptyNotebookAddCodeBlockBtn"]' ) . click ( ) ;
79
- cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . should ( 'exist' ) ;
120
+ makeParagraph ( ) ;
121
+
80
122
cy . get ( 'button[data-test-subj="runRefreshBtn-0"]' ) . contains ( 'Run' ) . click ( ) ;
81
123
cy . get ( 'div[data-test-subj="paragraphInputErrorText"]' )
82
124
. contains ( 'Input is required.' )
83
125
. should ( 'exist' ) ;
84
126
} ) ;
85
127
86
128
it ( 'Renders markdown' , ( ) => {
87
- cy . get ( 'button[data-test-subj="paragraphToggleInputBtn"]' ) . click ( ) ;
88
- cy . get ( '.euiCodeBlock' ) . click ( ) ;
89
- cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . clear ( ) ;
90
- cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . focus ( ) ;
91
- cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . type ( MARKDOWN_TEXT ) ;
92
-
93
- cy . get ( 'button[data-test-subj="runRefreshBtn-0"]' ) . click ( ) ;
129
+ makePopulatedParagraph ( ) ;
94
130
cy . get ( 'textarea[data-test-subj="editorArea-0"]' ) . should ( 'not.exist' ) ;
95
131
cy . get ( `a[href="${ SAMPLE_URL } "]` ) . should ( 'exist' ) ;
96
132
cy . get ( 'code' ) . contains ( 'POST' ) . should ( 'exist' ) ;
@@ -100,17 +136,23 @@ describe('Testing notebook actions', () => {
100
136
101
137
describe ( 'Test reporting integration if plugin installed' , ( ) => {
102
138
beforeEach ( ( ) => {
103
- moveToNotebookHome ( ) ;
104
- cy . get ( '.euiTableCellContent' ) . contains ( TEST_NOTEBOOK ) . click ( ) ;
139
+ let notebookName = makeTestNotebook ( ) ;
105
140
cy . get ( 'h1[data-test-subj="notebookTitle"]' )
106
- . contains ( TEST_NOTEBOOK )
141
+ . contains ( notebookName )
107
142
. should ( 'exist' ) ;
108
143
cy . get ( 'body' ) . then ( ( $body ) => {
109
144
skipOn ( $body . find ( '#reportingActionsButton' ) . length <= 0 ) ;
110
145
} ) ;
146
+ cy . wrap ( { name : notebookName } ) . as ( 'notebook' ) ;
147
+ } ) ;
148
+
149
+ afterEach ( function ( ) {
150
+ // ^^^^^^^^ Cannot use arrow callback to access beforeEach wrapper state
151
+ deleteNotebook ( this . notebook . name ) ;
111
152
} ) ;
112
153
113
154
it ( 'Create in-context PDF report from notebook' , ( ) => {
155
+ makePopulatedParagraph ( ) ;
114
156
cy . get ( '#reportingActionsButton' ) . click ( ) ;
115
157
cy . get ( 'button.euiContextMenuItem:nth-child(1)' )
116
158
. contains ( 'Download PDF' )
@@ -119,6 +161,7 @@ describe('Test reporting integration if plugin installed', () => {
119
161
} ) ;
120
162
121
163
it ( 'Create in-context PNG report from notebook' , ( ) => {
164
+ makePopulatedParagraph ( ) ;
122
165
cy . get ( '#reportingActionsButton' ) . click ( ) ;
123
166
cy . get ( 'button.euiContextMenuItem:nth-child(2)' )
124
167
. contains ( 'Download PNG' )
@@ -127,6 +170,7 @@ describe('Test reporting integration if plugin installed', () => {
127
170
} ) ;
128
171
129
172
it ( 'Create on-demand report definition from context menu' , ( ) => {
173
+ makePopulatedParagraph ( ) ;
130
174
cy . get ( '#reportingActionsButton' ) . click ( ) ;
131
175
cy . get ( 'button.euiContextMenuItem:nth-child(3)' )
132
176
. contains ( 'Create report definition' )
@@ -140,6 +184,7 @@ describe('Test reporting integration if plugin installed', () => {
140
184
} ) ;
141
185
142
186
it ( 'View reports homepage from context menu' , ( ) => {
187
+ makePopulatedParagraph ( ) ;
143
188
cy . get ( '#reportingActionsButton' ) . click ( ) ;
144
189
cy . get ( 'button.euiContextMenuItem:nth-child(4)' )
145
190
. contains ( 'View reports' )
@@ -150,28 +195,3 @@ describe('Test reporting integration if plugin installed', () => {
150
195
) ;
151
196
} ) ;
152
197
} ) ;
153
-
154
- describe ( 'clean up all test data' , ( ) => {
155
- it ( 'Cleans up test notebooks' , ( ) => {
156
- moveToNotebookHome ( ) ;
157
- cy . get ( 'input[data-test-subj="checkboxSelectAll"]' ) . click ( ) ;
158
- cy . get ( 'button[data-test-subj="notebookTableActionBtn"]' ) . click ( ) ;
159
- cy . get ( 'button[data-test-subj="deleteNotebookBtn"]' ) . click ( ) ;
160
- cy . get (
161
- 'button[data-test-subj="delete-notebook-modal-delete-button"]'
162
- ) . should ( 'be.disabled' ) ;
163
-
164
- cy . get ( 'input[data-test-subj="delete-notebook-modal-input"]' ) . focus ( ) ;
165
- cy . get ( 'input[data-test-subj="delete-notebook-modal-input"]' ) . type (
166
- 'delete'
167
- ) ;
168
- cy . get (
169
- 'button[data-test-subj="delete-notebook-modal-delete-button"]'
170
- ) . should ( 'not.be.disabled' ) ;
171
- cy . get (
172
- 'button[data-test-subj="delete-notebook-modal-delete-button"]'
173
- ) . click ( ) ;
174
- moveToNotebookHome ( ) ;
175
- cy . get ( 'div[data-test-subj="notebookEmptyTableText"]' ) . should ( 'exist' ) ;
176
- } ) ;
177
- } ) ;
0 commit comments