Skip to content

Commit

Permalink
Update UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Oct 26, 2023
1 parent 4282410 commit 9264294
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 35 deletions.
30 changes: 15 additions & 15 deletions NAMS/Patients/Model/PatientListModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,6 @@ class PatientListModel {
}
}

func setupTestEnvironment(withPatient patientId: String, viewState: Binding<ViewState>, account: Account) async {
await setupTestAccount(account: account, viewState: viewState)

do {
try await patientsCollection.document(patientId).setData(
from: Patient(name: .init(givenName: "Leland", familyName: "Stanford")),
merge: true
)
} catch {
Self.logger.error("Failed to set test patient information: \(error)")
viewState.wrappedValue = .error(FirestoreError(error))
}
}

func loadActivePatient(for id: String, viewState: Binding<ViewState>) {
if activePatient?.id == id {
return // already set up
Expand Down Expand Up @@ -213,6 +199,20 @@ class PatientListModel {
}
}

func setupTestEnvironment(withPatient patientId: String, viewState: Binding<ViewState>, account: Account) async {
await setupTestAccount(account: account, viewState: viewState)

do {
try await patientsCollection.document(patientId).setData(
from: Patient(name: .init(givenName: "Example", familyName: "Patient")),
merge: true
)
} catch {
Self.logger.error("Failed to set test patient information: \(error)")
viewState.wrappedValue = .error(FirestoreError(error))
}
}

private func setupTestAccount(account: Account, viewState: Binding<ViewState>) async {
let email = "[email protected]"
let password = "123456789"
Expand All @@ -233,7 +233,7 @@ class PatientListModel {
do {
let details = SignupDetails.Builder()
.set(\.userId, value: email)
.set(\.name, value: PersonNameComponents(givenName: "Example", familyName: "Patient"))
.set(\.name, value: PersonNameComponents(givenName: "Leland", familyName: "Stanford"))
.set(\.password, value: password)
.build()
try await service.signUp(signupDetails: details)
Expand Down
10 changes: 3 additions & 7 deletions NAMS/Tiles/QuestionnaireTile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ struct QuestionnaireTile: View {
VStack(alignment: .leading, spacing: 4) {
Text(patientQuestionnaire.title)
.font(.headline)
.accessibilityLabel(
completed
? "Completed Task: \(patientQuestionnaire.title)"
: "Task: \(patientQuestionnaire.title)"
)

HStack {
if completed {
Expand All @@ -81,8 +76,9 @@ struct QuestionnaireTile: View {
.foregroundColor(.secondary)
}
}
.font(.subheadline)
.foregroundColor(.secondary)
.font(.subheadline)
.foregroundColor(.secondary)
.accessibilityElement(children: .combine)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion NAMSUITests/ContactsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ContactsTests: XCTestCase {

func testContacts() throws {
let app = XCUIApplication()

XCTAssertTrue(app.tabBars["Tab Bar"].buttons["Contacts"].waitForExistence(timeout: 2))
app.tabBars["Tab Bar"].buttons["Contacts"].tap()

Expand Down
2 changes: 1 addition & 1 deletion NAMSUITests/OnboardingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OnboardingTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()

// TODO try disablePasswordAutofill()
try disablePasswordAutofill()

sleep(1)

Expand Down
4 changes: 2 additions & 2 deletions NAMSUITests/PatientInformationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ final class PatientInformationTests: XCTestCase {
app.buttons["Example Patient, Selected"].tap()

XCTAssertTrue(app.staticTexts["No Patient selected"].waitForExistence(timeout: 2.0))
XCTAssertTrue(app.buttons["Select Patient"].waitForExistence(timeout: 2.0))
app.buttons["Select Patient"].tap()
XCTAssertTrue(app.navigationBars.buttons["Select Patient"].waitForExistence(timeout: 2.0))
app.navigationBars.buttons["Select Patient"].tap()

XCTAssertTrue(app.navigationBars["Patients"].waitForExistence(timeout: 6.0))

Expand Down
40 changes: 31 additions & 9 deletions NAMSUITests/ScheduleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,36 @@ class ScheduleTests: XCTestCase {
XCTAssertTrue(app.tabBars["Tab Bar"].buttons["Schedule"].waitForExistence(timeout: 2))
app.tabBars["Tab Bar"].buttons["Schedule"].tap()

XCTAssertTrue(app.staticTexts["Start Questionnaire"].waitForExistence(timeout: 2))
app.staticTexts["Start Questionnaire"].tap()

XCTAssertTrue(app.staticTexts["M-CHAT R/F"].waitForExistence(timeout: 2))

// TODO: navigate the questionnaire with all yes
// TODO: assert completion!

// TODO switch patients and check if mark goes away?
XCTAssertTrue(app.staticTexts["SCREENING"].waitForExistence(timeout: 2.0))
XCTAssertTrue(app.staticTexts["M-CHAT R/F"].waitForExistence(timeout: 0.5))
XCTAssertTrue(app.staticTexts["Questionnaire, 5-10 min"].waitForExistence(timeout: 0.5))

XCTAssertTrue(app.buttons["Start Questionnaire"].waitForExistence(timeout: 0.5))
app.buttons["Start Questionnaire"].tap()

XCTAssertTrue(app.navigationBars.buttons["Cancel"].waitForExistence(timeout: 4))
XCTAssertTrue(app.staticTexts["M-CHAT R/F"].waitForExistence(timeout: 0.5))

while true {
if app.staticTexts["Yes"].exists {
app.staticTexts["Yes"].tap()

if app.buttons["Next"].exists {
app.buttons["Next"].tap()
usleep(500_000)
} else if app.buttons["Done"].exists {
app.buttons["Done"].tap()
usleep(500_000)
break
} else {
XCTFail("Couldn't navigate questionnaire!")
}
} else {
XCTFail("Couldn't navigate questionnaire!")
}
}


XCTAssertTrue(app.staticTexts["Completed"].waitForExistence(timeout: 2.0))
}
}

0 comments on commit 9264294

Please sign in to comment.