From a691aba8eac715e995af5d97327e370e6bc2505b Mon Sep 17 00:00:00 2001 From: Paul Schmiedmayer Date: Mon, 1 Apr 2024 23:49:32 -0700 Subject: [PATCH] Update Setup --- .../contents.xcworkspacedata | 4 - ...lan.license => ENGAGEHF.xctestplan.license | 0 ...cheduler.swift => ENGAGEHFScheduler.swift} | 0 ...ontext.swift => ENGAGEHFTaskContext.swift} | 0 ....license => ENGAGEHF.entitlements.license} | 0 ...GAGE-HFTests.swift => ENGAGEHFTests.swift} | 0 ENGAGEHFUITests/ENGAGEHFUITests.swift | 21 ++ ENGAGEHFUITests/OnboardingTests.swift | 224 ------------------ 8 files changed, 21 insertions(+), 228 deletions(-) delete mode 100644 ENGAGE-HF.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename ENGAGE-HF.xctestplan.license => ENGAGEHF.xctestplan.license (100%) rename ENGAGEHF/Schedule/{ENGAGE-HFScheduler.swift => ENGAGEHFScheduler.swift} (100%) rename ENGAGEHF/Schedule/{ENGAGE-HFTaskContext.swift => ENGAGEHFTaskContext.swift} (100%) rename ENGAGEHF/Supporting Files/{ENGAGE-HF.entitlements.license => ENGAGEHF.entitlements.license} (100%) rename ENGAGEHFTests/{ENGAGE-HFTests.swift => ENGAGEHFTests.swift} (100%) create mode 100644 ENGAGEHFUITests/ENGAGEHFUITests.swift delete mode 100644 ENGAGEHFUITests/OnboardingTests.swift diff --git a/ENGAGE-HF.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ENGAGE-HF.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 94b2795e..00000000 --- a/ENGAGE-HF.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/ENGAGE-HF.xctestplan.license b/ENGAGEHF.xctestplan.license similarity index 100% rename from ENGAGE-HF.xctestplan.license rename to ENGAGEHF.xctestplan.license diff --git a/ENGAGEHF/Schedule/ENGAGE-HFScheduler.swift b/ENGAGEHF/Schedule/ENGAGEHFScheduler.swift similarity index 100% rename from ENGAGEHF/Schedule/ENGAGE-HFScheduler.swift rename to ENGAGEHF/Schedule/ENGAGEHFScheduler.swift diff --git a/ENGAGEHF/Schedule/ENGAGE-HFTaskContext.swift b/ENGAGEHF/Schedule/ENGAGEHFTaskContext.swift similarity index 100% rename from ENGAGEHF/Schedule/ENGAGE-HFTaskContext.swift rename to ENGAGEHF/Schedule/ENGAGEHFTaskContext.swift diff --git a/ENGAGEHF/Supporting Files/ENGAGE-HF.entitlements.license b/ENGAGEHF/Supporting Files/ENGAGEHF.entitlements.license similarity index 100% rename from ENGAGEHF/Supporting Files/ENGAGE-HF.entitlements.license rename to ENGAGEHF/Supporting Files/ENGAGEHF.entitlements.license diff --git a/ENGAGEHFTests/ENGAGE-HFTests.swift b/ENGAGEHFTests/ENGAGEHFTests.swift similarity index 100% rename from ENGAGEHFTests/ENGAGE-HFTests.swift rename to ENGAGEHFTests/ENGAGEHFTests.swift diff --git a/ENGAGEHFUITests/ENGAGEHFUITests.swift b/ENGAGEHFUITests/ENGAGEHFUITests.swift new file mode 100644 index 00000000..8005c68a --- /dev/null +++ b/ENGAGEHFUITests/ENGAGEHFUITests.swift @@ -0,0 +1,21 @@ +// +// This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project +// +// SPDX-FileCopyrightText: 2023 Stanford University +// +// SPDX-License-Identifier: MIT +// + +import XCTest + + +final class ENGAGEHFUITests: XCTestCase { + override func setUpWithError() throws { + continueAfterFailure = false + } + + func testExample() throws { + let app = XCUIApplication() + app.launch() + } +} diff --git a/ENGAGEHFUITests/OnboardingTests.swift b/ENGAGEHFUITests/OnboardingTests.swift deleted file mode 100644 index 43e52d94..00000000 --- a/ENGAGEHFUITests/OnboardingTests.swift +++ /dev/null @@ -1,224 +0,0 @@ -// -// This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project -// -// SPDX-FileCopyrightText: 2023 Stanford University -// -// SPDX-License-Identifier: MIT -// - -import XCTest -import XCTestExtensions -import XCTHealthKit - - -class OnboardingTests: XCTestCase { - override func setUpWithError() throws { - try super.setUpWithError() - - continueAfterFailure = false - - let app = XCUIApplication() - app.launchArguments = ["--showOnboarding"] - app.deleteAndLaunch(withSpringboardAppName: "ENGAGEHF") - } - - - func testOnboardingFlow() throws { - let app = XCUIApplication() - let email = "leland@onboarding.stanford.edu" - - try app.navigateOnboardingFlow(email: email) - - app.assertOnboardingComplete() - try app.assertAccountInformation(email: email) - } - - func testOnboardingFlowRepeated() throws { - let app = XCUIApplication() - app.launchArguments = ["--showOnboarding", "--disableFirebase"] - app.terminate() - app.launch() - - try app.navigateOnboardingFlow() - app.assertOnboardingComplete() - - app.terminate() - - // Second onboarding round shouldn't display HealthKit and Notification authorizations anymore - app.activate() - - try app.navigateOnboardingFlow(repeated: true) - // Do not show HealthKit and Notification authorization view again - app.assertOnboardingComplete() - } -} - - -extension XCUIApplication { - func conductOnboardingIfNeeded(email: String = "leland@stanford.edu") throws { - let app = XCUIApplication() - - if app.staticTexts["Spezi\nENGAGEHF"].waitForExistence(timeout: 5) { - try app.navigateOnboardingFlow(email: email) - } - } - - fileprivate func navigateOnboardingFlow( - email: String = "leland@stanford.edu", - repeated skippedIfRepeated: Bool = false - ) throws { - try navigateOnboardingFlowWelcome() - try navigateOnboardingFlowInterestingModules() - if staticTexts["Your Account"].waitForExistence(timeout: 5) { - try navigateOnboardingAccount(email: email) - } - if staticTexts["Consent"].waitForExistence(timeout: 5) { - try navigateOnboardingFlowConsent() - } - if !skippedIfRepeated { - try navigateOnboardingFlowHealthKitAccess() - try navigateOnboardingFlowNotification() - } - } - - private func navigateOnboardingFlowWelcome() throws { - XCTAssertTrue(staticTexts["Spezi\nENGAGEHF"].waitForExistence(timeout: 5)) - - XCTAssertTrue(buttons["Learn More"].waitForExistence(timeout: 2)) - buttons["Learn More"].tap() - } - - private func navigateOnboardingFlowInterestingModules() throws { - XCTAssertTrue(staticTexts["Interesting Modules"].waitForExistence(timeout: 5)) - - for _ in 1..<4 { - XCTAssertTrue(buttons["Next"].waitForExistence(timeout: 2)) - buttons["Next"].tap() - } - - XCTAssertTrue(buttons["Next"].waitForExistence(timeout: 2)) - buttons["Next"].tap() - } - - private func navigateOnboardingAccount(email: String) throws { - if buttons["Logout"].waitForExistence(timeout: 2.0) { - buttons["Logout"].tap() - } - - XCTAssertTrue(buttons["Signup"].waitForExistence(timeout: 2)) - buttons["Signup"].tap() - - XCTAssertTrue(staticTexts["Create a new Account"].waitForExistence(timeout: 2)) - - try collectionViews.textFields["E-Mail Address"].enter(value: email) - try collectionViews.secureTextFields["Password"].enter(value: "StanfordRocks") - try textFields["enter first name"].enter(value: "Leland") - try textFields["enter last name"].enter(value: "Stanford") - - XCTAssertTrue(collectionViews.buttons["Signup"].waitForExistence(timeout: 2)) - collectionViews.buttons["Signup"].tap() - - sleep(3) - - if staticTexts["HealthKit Access"].waitForExistence(timeout: 5) && navigationBars.buttons["Back"].waitForExistence(timeout: 5) { - navigationBars.buttons["Back"].tap() - - XCTAssertTrue(staticTexts["Leland Stanford"].waitForExistence(timeout: 2)) - XCTAssertTrue(staticTexts[email].waitForExistence(timeout: 2)) - - XCTAssertTrue(buttons["Next"].waitForExistence(timeout: 2)) - buttons["Next"].tap() - } - } - - private func navigateOnboardingFlowConsent() throws { - XCTAssertTrue(staticTexts["Consent"].waitForExistence(timeout: 5)) - - XCTAssertTrue(staticTexts["First Name"].waitForExistence(timeout: 2)) - try textFields["Enter your first name ..."].enter(value: "Leland") - - XCTAssertTrue(staticTexts["Last Name"].waitForExistence(timeout: 2)) - try textFields["Enter your last name ..."].enter(value: "Stanford") - - XCTAssertTrue(scrollViews["Signature Field"].waitForExistence(timeout: 2)) - scrollViews["Signature Field"].swipeRight() - - XCTAssertTrue(buttons["I Consent"].waitForExistence(timeout: 2)) - buttons["I Consent"].tap() - } - - private func navigateOnboardingFlowHealthKitAccess() throws { - XCTAssertTrue(staticTexts["HealthKit Access"].waitForExistence(timeout: 5)) - - XCTAssertTrue(buttons["Grant Access"].waitForExistence(timeout: 2)) - buttons["Grant Access"].tap() - - try handleHealthKitAuthorization() - } - - private func navigateOnboardingFlowNotification() throws { - XCTAssertTrue(staticTexts["Notifications"].waitForExistence(timeout: 5)) - - XCTAssertTrue(buttons["Allow Notifications"].waitForExistence(timeout: 2)) - buttons["Allow Notifications"].tap() - - let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") - let alertAllowButton = springboard.buttons["Allow"] - if alertAllowButton.waitForExistence(timeout: 5) { - alertAllowButton.tap() - } - } - - fileprivate func assertOnboardingComplete() { - let tabBar = tabBars["Tab Bar"] - XCTAssertTrue(tabBar.buttons["Schedule"].waitForExistence(timeout: 2)) - XCTAssertTrue(tabBar.buttons["Contacts"].waitForExistence(timeout: 2)) - } - - fileprivate func assertAccountInformation(email: String) throws { - XCTAssertTrue(navigationBars.buttons["Your Account"].waitForExistence(timeout: 2)) - navigationBars.buttons["Your Account"].tap() - - XCTAssertTrue(staticTexts["Account Overview"].waitForExistence(timeout: 5.0)) - XCTAssertTrue(staticTexts["Leland Stanford"].exists) - XCTAssertTrue(staticTexts[email].exists) - XCTAssertTrue(staticTexts["Gender Identity, Choose not to answer"].exists) - - - XCTAssertTrue(navigationBars.buttons["Close"].waitForExistence(timeout: 0.5)) - navigationBars.buttons["Close"].tap() - - XCTAssertTrue(navigationBars.buttons["Your Account"].waitForExistence(timeout: 2)) - navigationBars.buttons["Your Account"].tap() - - XCTAssertTrue(navigationBars.buttons["Edit"].waitForExistence(timeout: 2)) - navigationBars.buttons["Edit"].tap() - - usleep(500_00) - XCTAssertFalse(navigationBars.buttons["Close"].exists) - - XCTAssertTrue(buttons["Delete Account"].waitForExistence(timeout: 2)) - buttons["Delete Account"].tap() - - let alert = "Are you sure you want to delete your account?" - XCTAssertTrue(alerts[alert].waitForExistence(timeout: 6.0)) - alerts[alert].buttons["Delete"].tap() - - XCTAssertTrue(alerts["Authentication Required"].waitForExistence(timeout: 2.0)) - XCTAssertTrue(alerts["Authentication Required"].secureTextFields["Password"].waitForExistence(timeout: 0.5)) - typeText("StanfordRocks") // the password field has focus already - XCTAssertTrue(alerts["Authentication Required"].buttons["Login"].waitForExistence(timeout: 0.5)) - alerts["Authentication Required"].buttons["Login"].tap() - - sleep(2) - - // Login - try textFields["E-Mail Address"].enter(value: email) - try secureTextFields["Password"].enter(value: "StanfordRocks") - - XCTAssertTrue(buttons["Login"].waitForExistence(timeout: 0.5)) - buttons["Login"].tap() - - XCTAssertTrue(alerts["Invalid Credentials"].waitForExistence(timeout: 2.0)) - } -}