Skip to content

Commit 1ef603b

Browse files
Merge develop into feature/validateVariables
2 parents bc1dc9d + c396084 commit 1ef603b

37 files changed

+199
-144
lines changed

.github/workflows/autoupdate.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: autoupdate
22
on:
3-
push:
4-
branches:
5-
- feature/*
3+
push: {}
64
jobs:
75
autoupdate:
86
name: autoupdate

cypress/cypress-functions.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,15 @@ function copyCypressEnvConfigIfNecessary() {
131131
}
132132
console.info("Cypress Configuration: " + cypressJsonString)
133133
}
134-
function setGithubStatusAndUploadTestResults(failedTests: any[] | null, context: string, cb: (err: any) => void) {
135-
// @ts-ignore
134+
function setGithubStatusAndUploadTestResults(failedTests: any[], context: string, cb: (err: any) => void) {
135+
const test = failedTests[0];
136136
const failedTestTitle = failedTests[0].title[1]
137-
// @ts-ignore
138-
const errorMessage = failedTests[0].error
139-
qmGit.setGithubStatus("failure", context, failedTestTitle + ": " +
140-
errorMessage, getReportUrl(), function() {
137+
const errorMessage = test.displayError
138+
if(!failedTests[0].displayError || failedTests[0].displayError === "undefined"){
139+
qmLog.le("No displayError on failedTests[0]: ", failedTests[0])
140+
}
141+
qmGit.setGithubStatus("failure", context, failedTestTitle + " err: " +
142+
failedTests[0].error, getReportUrl(), function() {
141143
uploadMochawesome().then(function(urls) {
142144
console.error(errorMessage)
143145
cb(errorMessage)
@@ -348,6 +350,12 @@ export function runCypressTestsInParallel(cb?: (err: any) => void) {
348350
})
349351
}
350352

353+
function moveToFront(specFileNames: string[], first: string) {
354+
specFileNames.sort(function (x, y) {
355+
return x == first ? -1 : y == first ? 1 : 0;
356+
});
357+
}
358+
351359
export function runCypressTests(cb?: (err: any) => void) {
352360
qmLog.logStartOfProcess("runCypressTests")
353361
deleteSuccessFile()
@@ -364,6 +372,8 @@ export function runCypressTests(cb?: (err: any) => void) {
364372
if (!specFileNames) {
365373
throw new Error("No specFileNames in " + specsPath)
366374
}
375+
moveToFront(specFileNames, "ionic_measurements_spec.js") // Fails a lot
376+
moveToFront(specFileNames, "ionic_variables_spec.js") // Fails a lot
367377
for (let i = 0, p = Promise.resolve(); i < specFileNames.length; i++) {
368378
const specName = specFileNames[i]
369379
if (releaseStage === "ionic" && specName.indexOf("ionic_") === -1) {

cypress/examples/aliasing.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ context('Aliasing', () => {
2828
it('.as() - alias a route for later use', () => {
2929
// Alias the route to wait for its response
3030
cy.server()
31-
cy.route('GET', 'comments/*').as('getComment')
31+
cy.intercept('GET', 'comments/*').as('getComment')
3232

3333
// we have code that gets a comment when
3434
// the button is clicked in scripts.js

cypress/examples/files.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ context('Files', () => {
2727
// when application makes an Ajax request matching "GET comments/*"
2828
// Cypress will intercept it and reply with object
2929
// from the "comment" alias
30-
cy.route('GET', 'comments/*', '@comment').as('getComment')
30+
cy.intercept('GET', 'comments/*', '@comment').as('getComment')
3131

3232
// we have code that gets a comment when
3333
// the button is clicked in scripts.js
@@ -38,7 +38,7 @@ context('Files', () => {
3838
.and('include', 'Using fixtures to represent data')
3939

4040
// you can also just write the fixture in the route
41-
cy.route('GET', 'comments/*', 'fixture:example.json').as('getComment')
41+
cy.intercept('GET', 'comments/*', 'fixture:example.json').as('getComment')
4242

4343
// we have code that gets a comment when
4444
// the button is clicked in scripts.js
@@ -50,7 +50,7 @@ context('Files', () => {
5050

5151
// or write fx to represent fixture
5252
// by default it assumes it's .json
53-
cy.route('GET', 'comments/*', 'fx:example').as('getComment')
53+
cy.intercept('GET', 'comments/*', 'fx:example').as('getComment')
5454

5555
// we have code that gets a comment when
5656
// the button is clicked in scripts.js

cypress/examples/network_requests.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ context('Network Requests', () => {
155155
})
156156
})
157157

158-
it('cy.route() - route responses to matching requests', () => {
158+
it('cy.intercept() - route responses to matching requests', () => {
159159
// https://on.cypress.io/route
160160

161161
let message = 'whoa, this comment does not exist'
162162

163163
cy.server()
164164

165165
// Listen to GET to comments/1
166-
cy.route('GET', 'comments/*').as('getComment')
166+
cy.intercept('GET', 'comments/*').as('getComment')
167167

168168
// we have code that gets a comment when
169169
// the button is clicked in scripts.js
@@ -173,19 +173,19 @@ context('Network Requests', () => {
173173
cy.wait('@getComment').its('status').should('eq', 200)
174174

175175
// Listen to POST to comments
176-
cy.route('POST', '/comments').as('postComment')
176+
cy.intercept('POST', '/comments').as('postComment')
177177

178178
// we have code that posts a comment when
179179
// the button is clicked in scripts.js
180180
cy.get('.network-post').click()
181181
cy.wait('@postComment').should((xhr) => {
182182
expect(xhr.requestBody).to.include('email')
183183
expect(xhr.requestHeaders).to.have.property('Content-Type')
184-
expect(xhr.responseBody).to.have.property('name', 'Using POST in cy.route()')
184+
expect(xhr.responseBody).to.have.property('name', 'Using POST in cy.intercept()')
185185
})
186186

187187
// Stub a response to PUT comments/ ****
188-
cy.route({
188+
cy.intercept({
189189
method: 'PUT',
190190
url: 'comments/*',
191191
status: 404,

cypress/examples/waiting.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ context('Waiting', () => {
2121
cy.server()
2222

2323
// Listen to GET to comments/1
24-
cy.route('GET', 'comments/*').as('getComment')
24+
cy.intercept('GET', 'comments/*').as('getComment')
2525

2626
// we have code that gets a comment when
2727
// the button is clicked in scripts.js

cypress/integration/ionic_measurements_spec.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function saveMeasurement() {
44
cy.get('#saveButton').click({force: true})
55
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)
77
cy.log('Waiting for measurement with id to be stored...')
88
cy.wait(500)
99
}
@@ -67,6 +67,10 @@ function ratingValueToImage(value, valence) {
6767
return ratingImages[valence][value - 1]
6868
}
6969

70+
function getTopMeasurementTitle() {
71+
return cy.get('#historyItemTitle-0', {timeout: 40000})
72+
}
73+
7074
/**
7175
* @param {number} [dosageValue]
7276
* @param variableName
@@ -93,16 +97,21 @@ function recordTreatmentMeasurementAndCheckHistoryPage(dosageValue, variableName
9397
saveMeasurement()
9498
cy.visitIonicAndSetApiUrl('/#/app/history-all-category/' + variableCategory)
9599
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)
98107
}
99108

100109
/**
101110
* @param {string} itemTitle
102111
*/
103112
function editHistoryPageMeasurement(itemTitle) {
104113
cy.log(`Editing history measurement with title containing: ${itemTitle}`)
105-
cy.get('#historyItemTitle-0', {timeout: 30000}).contains(itemTitle)
114+
getTopMeasurementTitle().contains(itemTitle)
106115
cy.get('#action-sheet-button-0', {timeout: 30000}).click({force: true})
107116
cy.clickActionSheetButtonContaining('Edit')
108117
cy.wait(2000)
@@ -125,7 +134,7 @@ function deleteMeasurements(variableName) {
125134
cy.wrap($el).click({force: true, timeout: 10000})
126135
cy.clickActionSheetButtonContaining('Delete')
127136
cy.wait('@measurements-delete', {timeout: 30000})
128-
.should('have.property', 'status', 204)
137+
.its('response.statusCode').should('eq', 204)
129138
deleted = true
130139
})
131140
}
@@ -139,7 +148,7 @@ function deleteMeasurements(variableName) {
139148
cy.wrap($el).click()
140149
cy.clickActionSheetButtonContaining('Delete')
141150
cy.wait('@measurements-delete', {timeout: 30000})
142-
.should('have.property', 'status', 204)
151+
.its('response.statusCode').should('eq', 204)
143152
deleted = true
144153
} else {
145154
// It's a header
@@ -164,8 +173,8 @@ describe('Measurements', function () {
164173
it('Goes to edit measurement from history page', function () {
165174
cy.loginWithAccessTokenIfNecessary('/#/app/history-all-category/Anything')
166175
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})
169178
cy.clickActionSheetButtonContaining('Edit')
170179
cy.wait(2000)
171180
cy.url().should('include', 'measurement-add')
@@ -178,7 +187,7 @@ describe('Measurements', function () {
178187
checkChartsPage(variableName)
179188
goToHistoryForVariable(variableName, true)
180189
cy.wait('@measurements', {timeout: 30000})
181-
.should('have.property', 'status', 200)
190+
.its('response.statusCode').should('eq', 200)
182191
deleteMeasurements(variableName)
183192
cy.loginWithAccessTokenIfNecessary('/#/app/measurement-add-search')
184193
cy.searchAndClickTopResult(variableName, true)
@@ -212,7 +221,7 @@ describe('Measurements', function () {
212221
})
213222
})
214223
// 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 () {
216225
let dosageValue = Math.floor(Math.random() * 100) + 10
217226
let variableName = 'Aaa Test Treatment'
218227
let variableCategoryName = 'Treatments'
@@ -228,7 +237,7 @@ describe('Measurements', function () {
228237
cy.url().should('include', '/#/app/history-all-category/' + variableCategoryName)
229238
cy.log('Check that deleted measurement is gone (must use does not equal instead of does not contain because a ' +
230239
'measurement of 0mg will be true if the value is 50mg)')
231-
cy.get('#historyItemTitle-0', {timeout: 40000})
240+
getTopMeasurementTitle()
232241
.should('not.contain', `${newDosageValue} mg ` + variableName)
233242
})
234243
// Seeing if skip fixes timeout problem

cypress/integration/ionic_reminders_spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ describe('Reminders', function () {
152152
cy.wait(1000) // Have to wait for save to complete
153153
goToCategoryInbox(variableCategoryName)
154154
}
155+
it('Selects a reminder time', function () {
156+
cy.loginWithAccessTokenIfNecessary('/#/app/reminder-add/', false)
157+
setReminderTime(8, 15, 'AM')
158+
})
155159
it('Creates a goals reminder and skip it', function () {
156160
let variableName = 'Aaa Test Reminder Goal Skip'
157161
let variableCategoryName = 'Goals'
@@ -218,7 +222,7 @@ describe('Reminders', function () {
218222
cy.get('#negativeRatingOptions4').click({ force: true, timeout: 30000 })
219223
cy.get('#menu-item-chart-search > a').click({ force: true, timeout: 20000 })
220224
cy.log("waiting for notifications to post after leaving inbox state before checking history...")
221-
cy.wait('@post-notifications', {timeout: 30000}).should('have.property', 'status', 201)
225+
cy.wait('@post-notifications', {timeout: 30000}).its('response.statusCode').should('eq', 201)
222226
cy.searchAndClickTopResult(variableName, true)
223227
cy.contains(`${variableName} Over Time`, {timeout: 30000})
224228
cy.get('#menu-more-button').click({ force: true })
@@ -236,10 +240,6 @@ describe('Reminders', function () {
236240
cy.wait(1000)
237241
deleteReminders(variableCategoryName)
238242
})
239-
it('Selects a reminder time', function () {
240-
cy.loginWithAccessTokenIfNecessary('/#/app/reminder-add/', false)
241-
setReminderTime(8, 15, 'AM')
242-
})
243243
it('Sets frequency to 30 minutes', function () {
244244
cy.loginWithAccessTokenIfNecessary('/#/app/reminder-add/', false)
245245
setFrequency('30 minutes')

cypress/integration/ionic_variables_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Variables', function(){
4545
cy.get('.primary-outcome-variable-history > img:nth-of-type(3)').click({force: true})
4646
cy.get('#saveButton').click({force: true})
4747
cy.wait('@post-measurement', {timeout: 30000})
48-
.should('have.property', 'status', 201)
48+
.its('response.statusCode').should('eq', 201)
4949
cy.loginWithAccessTokenIfNecessary('/#/app/reminders-inbox', true)
5050
searchForMoodFromMagnifyingGlassIcon(variableName)
5151
cy.clickActionSheetButtonContaining('Charts')

cypress/support/commands.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,10 @@ Cypress.Commands.add('visitWithApiUrlParam', (url, options = {}) => {
103103
cy.visit(url, options)
104104
})
105105
// noinspection JSUnusedLocalSymbols
106-
Cypress.Commands.add('visitApi', (url, options = {}, urlParams = {}) => {
107-
cy.log(`=== visitWithApiUrlParam at ${url} ===`)
108-
if(!API_HOST || API_HOST === 'undefined'){
109-
throw 'Please set API_HOST env!'
110-
}
111-
if(!options.qs){
112-
options.qs = {}
113-
}
106+
Cypress.Commands.add('visitApi', (url, options = {}) => {
107+
cy.log(`=== visitApi at ${url} ===`)
108+
if(!API_HOST || API_HOST === 'undefined'){ throw 'Please set API_HOST env!' }
109+
if(!options.qs){ options.qs = {} }
114110
options.qs.XDEBUG_SESSION_START = 'PHPSTORM'
115111
cy.visit("https://" + API_HOST + url, options)
116112
})
@@ -201,7 +197,7 @@ Cypress.Commands.add('enterNewUserCredentials', (clickAccept) => {
201197
cy.get('input[name="user_pass"]').click({force: true}).type('qwerty', {force: true})
202198
cy.get('input[name="user_pass_confirmation"]').click({force: true}).type('qwerty', {force: true})
203199
cy.get('input[type="submit"]').click({force: true})
204-
if(clickAccept && oauthAppBaseUrl.indexOf("quantimo.do") === -1){
200+
if(clickAccept && baseUrl.indexOf("quantimo.do") === -1){
205201
cy.log("OAUTH_APP_HOST is external so we have to click approve on oauth page")
206202
cy.get('#button-approve').click({force: true})
207203
}

0 commit comments

Comments
 (0)