File tree Expand file tree Collapse file tree 2 files changed +24
-11
lines changed Expand file tree Collapse file tree 2 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ describe('Settings > My Settings', () => {
10
10
expect ( value [ 0 ] . value ) . to . be . oneOf ( [ '' , 'Overview / Dashboard' ] ) ;
11
11
} ) ;
12
12
cy . changeSelect ( 'display\\.startpage' , 'Overview / Utilization' ) ;
13
- cy . intercept ( 'PATCH' , '/api/users/1 ' ) . as ( 'settingsUpdate' ) ;
13
+ cy . intercept ( 'PATCH' , '/api/users/* ' ) . as ( 'settingsUpdate' ) ;
14
14
cy . contains ( 'button' , 'Save' ) . click ( ) ;
15
15
cy . wait ( '@settingsUpdate' ) . its ( 'response.statusCode' ) . should ( 'eq' , 200 ) ;
16
16
@@ -25,7 +25,7 @@ describe('Settings > My Settings', () => {
25
25
expect ( value [ 0 ] . value ) . to . equal ( 'Overview / Utilization' ) ;
26
26
} ) ;
27
27
cy . changeSelect ( 'display\\.startpage' , 'Overview / Dashboard' ) ;
28
- cy . intercept ( 'PATCH' , '/api/users/1 ' ) . as ( 'settingsUpdate' ) ;
28
+ cy . intercept ( 'PATCH' , '/api/users/* ' ) . as ( 'settingsUpdate' ) ;
29
29
cy . contains ( 'button' , 'Save' ) . click ( ) ;
30
30
cy . wait ( '@settingsUpdate' ) . its ( 'response.statusCode' ) . should ( 'eq' , 200 ) ;
31
31
Original file line number Diff line number Diff line change 3
3
// selectId: String of the ID of the select element to interact with.
4
4
// optionToSelect: String of the option to select from the dropdown.
5
5
Cypress . Commands . add ( 'changeSelect' , ( selectId , optionToSelect ) => {
6
- cy . get ( `#${ selectId } ` ) . click ( ) ;
7
- cy . get ( '.bx--list-box__menu-item__option' ) . then ( ( options ) => {
8
- const optionArray = Cypress . $ . makeArray ( options ) ;
9
- const match = optionArray . find ( ( el ) => el . innerText . trim ( ) === optionToSelect ) ;
10
- if ( match ) {
11
- cy . wrap ( match ) . click ( ) ;
12
- } else {
13
- throw new Error ( 'No match' ) ;
14
- }
6
+ // First, get the select element and store its text
7
+ let selectElementText = '' ;
8
+ cy . get ( `#${ selectId } ` ) . then ( ( selectElement ) => {
9
+ // Get the currently displayed text in the select element
10
+ selectElementText = selectElement . text ( ) . trim ( ) ;
11
+ // Click to open the dropdown
12
+ cy . wrap ( selectElement ) . click ( ) ;
13
+ } ) . then ( ( ) => {
14
+ // Now find the options and try to select the requested one
15
+ cy . get ( '.bx--list-box__menu-item__option' ) . then ( ( options ) => {
16
+ const optionArray = Cypress . $ . makeArray ( options ) ;
17
+ const match = optionArray . find ( ( el ) => el . innerText . trim ( ) === optionToSelect ) ;
18
+
19
+ if ( match ) {
20
+ cy . wrap ( match ) . click ( ) ;
21
+ } else {
22
+ // Include both the requested option and the select element's text in the error
23
+ cy . logAndThrowError (
24
+ `Could not find "${ optionToSelect } " in select element with text "${ selectElementText } "`
25
+ ) ;
26
+ }
27
+ } ) ;
15
28
} ) ;
16
29
} ) ;
You can’t perform that action at this time.
0 commit comments