Skip to content

Commit

Permalink
Bunch more adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Feb 14, 2024
1 parent 1e260aa commit 6b44124
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 57 deletions.
2 changes: 2 additions & 0 deletions Tests/UITests/TestApp/Examples/NameFieldsExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ struct NameFieldsExample: View {
}
}
.navigationTitle("Enter your details")
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.navigationBarBackButtonHidden(hideBackButton)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Expand Down
4 changes: 4 additions & 0 deletions Tests/UITests/TestApp/Examples/ValidationExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ struct ValidationExample: View {
VerifiableTextField("Password", text: $password, type: .secure)
.validate(input: password, rules: .minimalPassword)
}
#if !os(macOS)
.textInputAutocapitalization(.never)
#endif
.autocorrectionDisabled(true)

Section {
Expand All @@ -40,7 +42,9 @@ struct ValidationExample: View {
}
}
.navigationTitle("Signup")
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.navigationBarBackButtonHidden(backButtonHidden)
.receiveValidation(in: $validation)
.toolbar {
Expand Down
6 changes: 5 additions & 1 deletion Tests/UITests/TestApp/Examples/ViewStateExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ struct ViewStateExample: View {
.padding()
}
.navigationTitle("Reset Password")
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.viewStateAlert(state: $viewState)
.frame(maxWidth: .infinity, minHeight: proxy.size.height)
}
Expand All @@ -54,9 +56,11 @@ struct ViewStateExample: View {
.validate(input: emailAddress, rules: .minimalEmail)
.textFieldStyle(.roundedBorder)
.autocorrectionDisabled(true)
#if !os(macOS)
.textInputAutocapitalization(.never)
.textContentType(.username)
.keyboardType(.emailAddress)
#endif
.textContentType(.username)
.font(.title3)

Spacer()
Expand Down
19 changes: 19 additions & 0 deletions Tests/UITests/TestApp/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
},
"Action executed" : {

},
"Background text?" : {

},
"Canvas Size: none" : {

},
"Canvas Size: width %lf, height %lf" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Canvas Size: width %1$lf, height %2$lf"
}
}
}
},
"CanvasTest" : {

},
"Credentials" : {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ struct NameFieldsTestView: View {
nameFields
}
}
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}


Expand Down
11 changes: 8 additions & 3 deletions Tests/UITests/TestApp/SpeziViewsTargetsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ struct SpeziViewsTargetsTests: View {
Button("SpeziValidation") {
presentingSpeziValidation = true
}
#if canImport(PencilKit) && !os(macOS)
NavigationLink("CanvasTest") {
CanvasTestView()
}
#endif

Section {
NavigationLink("ViewState") {
Expand All @@ -48,13 +53,13 @@ struct SpeziViewsTargetsTests: View {
.navigationTitle("Targets")
}
.sheet(isPresented: $presentingSpeziViews) {
TestAppTestsView<SpeziViewsTests>()
TestAppTestsView<SpeziViewsTests>(showCloseButton: true)
}
.sheet(isPresented: $presentingSpeziPersonalInfo) {
TestAppTestsView<SpeziPersonalInfoTests>()
TestAppTestsView<SpeziPersonalInfoTests>(showCloseButton: true)
}
.sheet(isPresented: $presentingSpeziValidation) {
TestAppTestsView<SpeziValidationTests>()
TestAppTestsView<SpeziValidationTests>(showCloseButton: true)
}
}
}
Expand Down
39 changes: 26 additions & 13 deletions Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// SPDX-License-Identifier: MIT
//

#if canImport(PencilKit) && !os(macOS)
import PencilKit
import SpeziViews
import SwiftUI
Expand All @@ -16,28 +17,38 @@ struct CanvasTestView: View {
@State var didDrawAnything = false
@State var showToolPicker = false
@State var drawing = PKDrawing()

@State var receivedSize: CGSize?

var body: some View {
VStack {
Text("Did Draw Anything: \(didDrawAnything.description)")
Button("Show Tool Picker") {
showToolPicker.toggle()
ZStack {
VStack {
Text("Did Draw Anything: \(didDrawAnything.description)")
if let receivedSize {
Text("Canvas Size: width \(receivedSize.width), height \(receivedSize.height)")
} else {
Text("Canvas Size: none")
}
Button("Show Tool Picker") {
showToolPicker.toggle()
}
CanvasView(
drawing: $drawing,
isDrawing: $isDrawing,
tool: .init(.pencil, color: .red, width: 10),
drawingPolicy: .anyInput,
showToolPicker: $showToolPicker
)
}
CanvasView(
drawing: $drawing,
isDrawing: $isDrawing,
tool: .init(.pencil, color: .red, width: 10),
drawingPolicy: .anyInput,
showToolPicker: $showToolPicker
)
}
.onChange(of: isDrawing) {
if isDrawing {
didDrawAnything = true
}
}
.navigationBarTitleDisplayMode(.inline)
.onPreferenceChange(CanvasView.CanvasSizePreferenceKey.self) { size in
self.receivedSize = size
}
}
}

Expand All @@ -49,3 +60,5 @@ struct CanvasTestView_Previews: PreviewProvider {
}
}
#endif
#endif

Check failure on line 64 in Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
2 changes: 2 additions & 0 deletions Tests/UITests/TestApp/ViewsTests/GeometryReaderTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ struct GeometryReaderTestView: View {
.frame(width: 300)
.border(.blue)
}
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
}

Expand Down
16 changes: 14 additions & 2 deletions Tests/UITests/TestApp/ViewsTests/SpeziViewsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import XCTestApp


enum SpeziViewsTests: String, TestAppTests {
#if canImport(PencilKit) && !os(macOS)
case canvas = "Canvas"
#endif
case geometryReader = "Geometry Reader"
#if !os(macOS)
case label = "Label"
#endif
case lazyText = "Lazy Text"
case markdownView = "Markdown View"
case viewState = "View State"
Expand All @@ -26,16 +30,19 @@ enum SpeziViewsTests: String, TestAppTests {
case listRow = "List Row"


#if canImport(PencilKit) && !os(macOS)
@ViewBuilder
private var canvas: some View {
CanvasTestView()
}

#endif

@ViewBuilder
private var geometryReader: some View {
GeometryReaderTestView()
}

#if !os(macOS)
@ViewBuilder
private var label: some View {
Label(
Expand All @@ -54,7 +61,8 @@ enum SpeziViewsTests: String, TestAppTests {
)
.border(.red)
}

#endif

@ViewBuilder
private var markdownView: some View {
MarkdownViewTestView()
Expand Down Expand Up @@ -118,12 +126,16 @@ enum SpeziViewsTests: String, TestAppTests {

func view(withNavigationPath path: Binding<NavigationPath>) -> some View { // swiftlint:disable:this cyclomatic_complexity
switch self {
#if canImport(PencilKit) && !os(macOS)
case .canvas:
canvas
#endif
case .geometryReader:
geometryReader
#if !os(macOS)
case .label:
label
#endif
case .lazyText:
lazyText
case .markdownView:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,15 @@ final class PersonalInfoViewsTests: XCTestCase {
func testNameFields() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["Name Fields"].waitForExistence(timeout: 2))
app.collectionViews.buttons["Name Fields"].tap()
XCTAssert(app.buttons["Name Fields"].waitForExistence(timeout: 2))
app.buttons["Name Fields"].tap()

XCTAssert(app.staticTexts["First Name"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Last Name"].waitForExistence(timeout: 2))

#if os(visionOS)
app.textFields["enter your first name"].tap()
sleep(1)
app.typeText("Leland")

app.textFields["enter your last name"].tap()
sleep(1)
app.typeText("Stanford")

#else
print(app.textFields.debugDescription) // TODO: name fields don't look good on macOS

Check failure on line 34 in Tests/UITests/TestAppUITests/SpeziPersonalInfo/PersonalInfoViewsTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Todo Violation: TODOs should be resolved (name fields don't look good on...) (todo)
try app.textFields["enter your first name"].enter(value: "Leland")
try app.textFields["enter your last name"].enter(value: "Stanford")
#endif

XCTAssert(app.textFields["Leland"].waitForExistence(timeout: 2))
XCTAssert(app.textFields["Stanford"].waitForExistence(timeout: 2))
Expand All @@ -52,8 +42,8 @@ final class PersonalInfoViewsTests: XCTestCase {
func testUserProfile() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["User Profile"].waitForExistence(timeout: 2))
app.collectionViews.buttons["User Profile"].tap()
XCTAssert(app.buttons["User Profile"].waitForExistence(timeout: 2))
app.buttons["User Profile"].tap()

XCTAssertTrue(app.staticTexts["PS"].waitForExistence(timeout: 2))
XCTAssertTrue(app.staticTexts["LS"].exists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,25 @@ final class ValidationTests: XCTestCase {
XCTAssertFalse(app.staticTexts[passwordMessage].exists)
XCTAssertTrue(app.staticTexts[emptyMessage].exists)

print(app.switches["Switch Focus"].debugDescription)
#if os(macOS)
XCTAssertTrue(app.checkBoxes["Switch Focus"].exists)
app.checkBoxes["Switch Focus"].tap()
#else
XCTAssertTrue(app.switches["Switch Focus"].exists)
try XCTUnwrap(app.switches.allElementsBoundByIndex.last).tap() // toggles automatic focus switch off
#endif

app.buttons["Validate"].tap()

app.typeText("!")
app.dismissKeyboard()

XCTAssertTrue(app.textFields["Hello World!"].waitForExistence(timeout: 0.5))
#if os(macOS)
app.checkBoxes["Switch Focus"].tap()
#else
try XCTUnwrap(app.switches.allElementsBoundByIndex.last).tap() // toggles automatic focus switch on
#endif

app.buttons["Validate"].tap()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ final class EnvironmentTests: XCTestCase {
func testDefaultErrorDescription() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["Default Error Description"].waitForExistence(timeout: 2))
app.collectionViews.buttons["Default Error Description"].tap()
XCTAssert(app.buttons["Default Error Description"].waitForExistence(timeout: 2))
app.buttons["Default Error Description"].tap()

XCTAssert(app.staticTexts["View State: processing"].waitForExistence(timeout: 2))

sleep(12)

print(app.alerts.debugDescription)
XCTAssert(app.alerts.staticTexts["This is a default error description!"].exists)
XCTAssert(app.alerts.staticTexts["Failure Reason\n\nHelp Anchor\n\nRecovery Suggestion"].exists)
app.alerts.buttons["OK"].tap()
Expand Down
16 changes: 8 additions & 8 deletions Tests/UITests/TestAppUITests/SpeziViews/ModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ final class ModelTests: XCTestCase {
func testViewState() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["View State"].waitForExistence(timeout: 2))
app.collectionViews.buttons["View State"].tap()
XCTAssert(app.buttons["View State"].waitForExistence(timeout: 2))
app.buttons["View State"].tap()

XCTAssert(app.staticTexts["View State: processing"].waitForExistence(timeout: 2))

Expand All @@ -42,8 +42,8 @@ final class ModelTests: XCTestCase {
func testOperationState() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["Operation State"].waitForExistence(timeout: 2))
app.collectionViews.buttons["Operation State"].tap()
XCTAssert(app.buttons["Operation State"].waitForExistence(timeout: 2))
app.buttons["Operation State"].tap()

XCTAssert(app.staticTexts["Operation State: someOperationStep"].waitForExistence(timeout: 2))

Expand All @@ -61,8 +61,8 @@ final class ModelTests: XCTestCase {
func testViewStateMapper() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["View State Mapper"].waitForExistence(timeout: 2))
app.collectionViews.buttons["View State Mapper"].tap()
XCTAssert(app.buttons["View State Mapper"].waitForExistence(timeout: 2))
app.buttons["View State Mapper"].tap()

XCTAssert(app.staticTexts["View State: processing"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Operation State: someOperationStep"].waitForExistence(timeout: 2))
Expand All @@ -84,8 +84,8 @@ final class ModelTests: XCTestCase {
func testDefaultErrorDescription() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["Default Error Only"].waitForExistence(timeout: 2))
app.collectionViews.buttons["Default Error Only"].tap()
XCTAssert(app.buttons["Default Error Only"].waitForExistence(timeout: 2))
app.buttons["Default Error Only"].tap()

XCTAssert(app.staticTexts["View State: processing"].waitForExistence(timeout: 2))

Expand Down
Loading

0 comments on commit 6b44124

Please sign in to comment.