3
3
function saveMeasurement ( ) {
4
4
cy . get ( '#saveButton' ) . click ( { force : true } )
5
5
cy . log ( 'Waiting for measurement to post to API...' )
6
- cy . wait ( '@post-measurement' , { timeout : 30000 } ) . should ( 'have.property' , 'status ', 201 )
6
+ cy . wait ( '@post-measurement' , { timeout : 30000 } ) . its ( 'response.statusCode' ) . should ( 'eq ', 201 )
7
7
cy . log ( 'Waiting for measurement with id to be stored...' )
8
8
cy . wait ( 500 )
9
9
}
@@ -67,6 +67,10 @@ function ratingValueToImage(value, valence) {
67
67
return ratingImages [ valence ] [ value - 1 ]
68
68
}
69
69
70
+ function getTopMeasurementTitle ( ) {
71
+ return cy . get ( '#historyItemTitle-0' , { timeout : 40000 } )
72
+ }
73
+
70
74
/**
71
75
* @param {number } [dosageValue]
72
76
* @param variableName
@@ -93,16 +97,21 @@ function recordTreatmentMeasurementAndCheckHistoryPage(dosageValue, variableName
93
97
saveMeasurement ( )
94
98
cy . visitIonicAndSetApiUrl ( '/#/app/history-all-category/' + variableCategory )
95
99
let treatmentStringNoQuotes = `${ dosageValue } mg Aaa Test Treatment`
96
- cy . get ( '#historyItemTitle-0' , { timeout : 40000 } )
97
- . should ( 'contain' , treatmentStringNoQuotes )
100
+ getTopMeasurementTitle ( ) . invoke ( 'text' ) . then ( ( text ) => {
101
+ //debugger
102
+ if ( text . trim ( ) !== treatmentStringNoQuotes ) {
103
+ cy . log ( "ERROR: top value should be " + treatmentStringNoQuotes + " but is " + text . trim ( ) )
104
+ }
105
+ } )
106
+ getTopMeasurementTitle ( ) . should ( 'contain' , treatmentStringNoQuotes )
98
107
}
99
108
100
109
/**
101
110
* @param {string } itemTitle
102
111
*/
103
112
function editHistoryPageMeasurement ( itemTitle ) {
104
113
cy . log ( `Editing history measurement with title containing: ${ itemTitle } ` )
105
- cy . get ( '#historyItemTitle-0' , { timeout : 30000 } ) . contains ( itemTitle )
114
+ getTopMeasurementTitle ( ) . contains ( itemTitle )
106
115
cy . get ( '#action-sheet-button-0' , { timeout : 30000 } ) . click ( { force : true } )
107
116
cy . clickActionSheetButtonContaining ( 'Edit' )
108
117
cy . wait ( 2000 )
@@ -125,7 +134,7 @@ function deleteMeasurements(variableName) {
125
134
cy . wrap ( $el ) . click ( { force : true , timeout : 10000 } )
126
135
cy . clickActionSheetButtonContaining ( 'Delete' )
127
136
cy . wait ( '@measurements-delete' , { timeout : 30000 } )
128
- . should ( 'have.property' , 'status ', 204 )
137
+ . its ( 'response.statusCode' ) . should ( 'eq ', 204 )
129
138
deleted = true
130
139
} )
131
140
}
@@ -139,7 +148,7 @@ function deleteMeasurements(variableName) {
139
148
cy . wrap ( $el ) . click ( )
140
149
cy . clickActionSheetButtonContaining ( 'Delete' )
141
150
cy . wait ( '@measurements-delete' , { timeout : 30000 } )
142
- . should ( 'have.property' , 'status ', 204 )
151
+ . its ( 'response.statusCode' ) . should ( 'eq ', 204 )
143
152
deleted = true
144
153
} else {
145
154
// It's a header
@@ -164,8 +173,8 @@ describe('Measurements', function () {
164
173
it ( 'Goes to edit measurement from history page' , function ( ) {
165
174
cy . loginWithAccessTokenIfNecessary ( '/#/app/history-all-category/Anything' )
166
175
cy . wait ( '@measurements' , { timeout : 30000 } )
167
- . should ( 'have.property' , 'status ', 200 )
168
- cy . get ( '#historyItemTitle-0' , { timeout : 30000 } ) . click ( { force : true } )
176
+ . its ( 'response.statusCode' ) . should ( 'eq ', 200 )
177
+ getTopMeasurementTitle ( ) . click ( { force : true } )
169
178
cy . clickActionSheetButtonContaining ( 'Edit' )
170
179
cy . wait ( 2000 )
171
180
cy . url ( ) . should ( 'include' , 'measurement-add' )
@@ -178,7 +187,7 @@ describe('Measurements', function () {
178
187
checkChartsPage ( variableName )
179
188
goToHistoryForVariable ( variableName , true )
180
189
cy . wait ( '@measurements' , { timeout : 30000 } )
181
- . should ( 'have.property' , 'status ', 200 )
190
+ . its ( 'response.statusCode' ) . should ( 'eq ', 200 )
182
191
deleteMeasurements ( variableName )
183
192
cy . loginWithAccessTokenIfNecessary ( '/#/app/measurement-add-search' )
184
193
cy . searchAndClickTopResult ( variableName , true )
@@ -212,7 +221,7 @@ describe('Measurements', function () {
212
221
} )
213
222
} )
214
223
// Skipping because it fails randomly and can't reproduce failure locally
215
- it ( 'Record, edit, and delete a treatment measurement' , function ( ) {
224
+ it . only ( 'Record, edit, and delete a treatment measurement' , function ( ) {
216
225
let dosageValue = Math . floor ( Math . random ( ) * 100 ) + 10
217
226
let variableName = 'Aaa Test Treatment'
218
227
let variableCategoryName = 'Treatments'
@@ -228,7 +237,7 @@ describe('Measurements', function () {
228
237
cy . url ( ) . should ( 'include' , '/#/app/history-all-category/' + variableCategoryName )
229
238
cy . log ( 'Check that deleted measurement is gone (must use does not equal instead of does not contain because a ' +
230
239
'measurement of 0mg will be true if the value is 50mg)' )
231
- cy . get ( '#historyItemTitle-0' , { timeout : 40000 } )
240
+ getTopMeasurementTitle ( )
232
241
. should ( 'not.contain' , `${ newDosageValue } mg ` + variableName )
233
242
} )
234
243
// Seeing if skip fixes timeout problem
0 commit comments