Skip to content

Commit

Permalink
Resolving swiftlint and UI test issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
RealLast committed Jun 26, 2024
1 parent 433e71b commit 1d42652
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
5 changes: 0 additions & 5 deletions Tests/UITests/TestApp/ExampleStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import SwiftUI
actor ExampleStandard: Standard, EnvironmentAccessible {
@Published @MainActor var firstConsentData: PDFDocument = .init()
@Published @MainActor var secondConsentData: PDFDocument = .init()

}


extension ExampleStandard: OnboardingConstraint {
func store(consent: PDFDocument, identifier: String) async {
await MainActor.run {

if identifier == "FirstConsentDocument" {
self.firstConsentData = consent
} else if identifier == "SecondConsentDocument" {
Expand All @@ -34,7 +32,6 @@ extension ExampleStandard: OnboardingConstraint {
}

func loadConsentDocument(identifier: String) async throws -> PDFDocument? {

if identifier == "FirstConsentDocument" {
return await self.firstConsentData
} else if identifier == "SecondConsentDocument" {
Expand All @@ -46,6 +43,4 @@ extension ExampleStandard: OnboardingConstraint {
// is nil, and if so, displays an error.
return nil
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ struct OnboardingConsentMarkdownRenderingView1: View {


#if DEBUG
struct OnboardingConsentMarkdownRenderingView_Previews: PreviewProvider {
struct OnboardingConsentMarkdownRenderingView1_Previews: PreviewProvider {
static var standard: OnboardingDataSource = .init()


static var previews: some View {
OnboardingStack(startAtStep: OnboardingConsentMarkdownRenderingView1.self) {
for onboardingView in OnboardingFlow.previewSimulatorViews {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct OnboardingConsentMarkdownRenderingView2: View {


#if DEBUG
struct OnboardingSecondConsentMarkdownRenderingView_Previews: PreviewProvider {
struct OnboardingConsentMarkdownRenderingView2_Previews: PreviewProvider {
static var standard: OnboardingDataSource = .init()


Expand Down
81 changes: 43 additions & 38 deletions Tests/UITests/TestAppUITests/SpeziOnboardingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,28 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le
XCTAssert(app.buttons["Continue"].waitForExistence(timeout: 2))
app.buttons["Continue"].tap()

// Check if on consent (markdown) view
XCTAssert(app.staticTexts["Consent"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["This is the first markdown example"].waitForExistence(timeout: 2))
// Check first and second consent export
try testConsentViewOnboardingFlow(app: app, consentTitle: "First Consent", markdownText: "This is the first markdown example")
try testConsentViewOnboardingFlow(app: app, consentTitle: "Second Consent", markdownText: "This is the second markdown example")

XCTAssert(app.staticTexts["Leland"].waitForExistence(timeout: 2))
XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()

XCTAssert(app.staticTexts["Stanford"].waitForExistence(timeout: 2))
XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()

XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()

// Check if on final page
XCTAssert(app.staticTexts["Onboarding complete"].waitForExistence(timeout: 2))
}

func testConsentViewOnboardingFlow(app: XCUIApplication, consentTitle: String, markdownText: String) throws {
XCTAssert(app.staticTexts[consentTitle].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts[markdownText].waitForExistence(timeout: 2))

#if targetEnvironment(simulator) && (arch(i386) || arch(x86_64))
throw XCTSkip("PKCanvas view-related tests are currently skipped on Intel-based iOS simulators due to a metal bug on the simulator.")
Expand All @@ -67,25 +86,11 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le

hitConsentButton(app)

// Check if the consent export was successful
XCTAssert(app.staticTexts["Consent PDF rendering exists"].waitForExistence(timeout: 2))
// Check if the first consent export was successful
XCTAssert(app.staticTexts["\(consentTitle) PDF rendering exists"].waitForExistence(timeout: 2))

XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()

XCTAssert(app.staticTexts["Leland"].waitForExistence(timeout: 2))
XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()

XCTAssert(app.staticTexts["Stanford"].waitForExistence(timeout: 2))
XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()

XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()

// Check if on final page
XCTAssert(app.staticTexts["Onboarding complete"].waitForExistence(timeout: 2))
}

func testOnboardingWelcomeView() throws {
Expand Down Expand Up @@ -151,18 +156,18 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le
XCTAssert(app.buttons["Continue"].waitForExistence(timeout: 2))
app.buttons["Continue"].tap()

XCTAssert(app.staticTexts["Consent"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["First Consent"].waitForExistence(timeout: 2))
}

func testOnboardingConsentMarkdown() throws {
let app = XCUIApplication()
app.launch()

// Test that the consent view can render markdown
XCTAssert(app.buttons["Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["Consent View (Markdown)"].tap()
XCTAssert(app.buttons["First Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["First Consent View (Markdown)"].tap()

XCTAssert(app.staticTexts["Consent"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["First Consent"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["This is the first markdown example"].waitForExistence(timeout: 2))

XCTAssertFalse(app.staticTexts["Leland Stanford"].waitForExistence(timeout: 2))
Expand Down Expand Up @@ -199,28 +204,28 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le

hitConsentButton(app)

XCTAssert(app.staticTexts["Consent PDF rendering exists"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["First Consent PDF rendering exists"].waitForExistence(timeout: 2))
}

func testOnboardingConsentMarkdownRendering() throws {
let app = XCUIApplication()
app.launch()

// Test that the consent view is not exported
XCTAssert(app.buttons["Rendered Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["Rendered Consent View (Markdown)"].tap()
XCTAssert(app.buttons["First Rendered Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["First Rendered Consent View (Markdown)"].tap()

XCTAssert(app.staticTexts["Consent PDF rendering doesn't exist"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["First Consent PDF rendering doesn't exist"].waitForExistence(timeout: 2))

// Navigate back to start screen
XCTAssert(app.buttons["Back"].waitForExistence(timeout: 2))
app.buttons["Back"].tap()

// Go through markdown consent form and check rendering
XCTAssert(app.buttons["Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["Consent View (Markdown)"].tap()
XCTAssert(app.buttons["First Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["First Consent View (Markdown)"].tap()

XCTAssert(app.staticTexts["Consent"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["First Consent"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["This is the first markdown example"].waitForExistence(timeout: 2))

XCTAssertFalse(app.staticTexts["Leland Stanford"].waitForExistence(timeout: 2))
Expand Down Expand Up @@ -252,7 +257,7 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le

hitConsentButton(app)

XCTAssert(app.staticTexts["Consent PDF rendering exists"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["First Consent PDF rendering exists"].waitForExistence(timeout: 2))
}

#if !os(macOS) // Only test export on non macOS platforms
Expand Down Expand Up @@ -308,7 +313,7 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le
}

// Wait until share sheet closed and back on the consent form screen
XCTAssert(app.staticTexts["Consent"].waitForExistence(timeout: 10))
XCTAssert(app.staticTexts["First Consent"].waitForExistence(timeout: 10))

XCUIDevice.shared.press(.home)

Expand Down Expand Up @@ -402,11 +407,11 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le
let app = XCUIApplication()
app.launch()

XCTAssert(app.buttons["Rendered Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["Rendered Consent View (Markdown)"].tap()
XCTAssert(app.buttons["Second Rendered Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["Second Rendered Consent View (Markdown)"].tap()

// Check if on consent export page
XCTAssert(app.staticTexts["Consent PDF rendering doesn't exist"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Second Consent PDF rendering doesn't exist"].waitForExistence(timeout: 2))

XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()
Expand Down Expand Up @@ -450,11 +455,11 @@ final class OnboardingTests: XCTestCase { // swiftlint:disable:this type_body_le
app.buttons["Show Conditional View"].tap()
}

XCTAssert(app.buttons["Rendered Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["Rendered Consent View (Markdown)"].tap()
XCTAssert(app.buttons["Second Rendered Consent View (Markdown)"].waitForExistence(timeout: 2))
app.buttons["Second Rendered Consent View (Markdown)"].tap()

// Check if on consent export page
XCTAssert(app.staticTexts["Consent PDF rendering doesn't exist"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Second Consent PDF rendering doesn't exist"].waitForExistence(timeout: 2))

XCTAssert(app.buttons["Next"].waitForExistence(timeout: 2))
app.buttons["Next"].tap()
Expand Down

0 comments on commit 1d42652

Please sign in to comment.