Skip to content

Commit

Permalink
Docs and snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Sep 12, 2024
1 parent de70433 commit 87ec7a3
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 10 deletions.
1 change: 0 additions & 1 deletion Sources/SpeziPersonalInfo/Fields/NameFieldRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public struct NameFieldRow<Description: View, Label: View>: View {
/// - Parameters:
/// - name: The name to display and edit.
/// - component: The `KeyPath` to the property of the provided `PersonNameComponents` to display and edit.
/// - prompt: An optional `Text` prompt. Refer to the documentation of `TextField` for more information.
/// - description: The description label displayed before the text field.
/// - label: A view that describes the purpose of the text field.
public init(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SpeziViews/Views/Text/MarkdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public struct MarkdownView: View {

/// Creates a ``MarkdownView`` that displays the content of a markdown file
/// - Parameters:
/// - asyncMarkdown: A `Data` instance containing the markdown file in an utf8 representation.
/// - markdown: A `Data` instance containing the markdown file in an utf8 representation.
/// - state: A `Binding` to observe the ``ViewState`` of the ``MarkdownView``.
public init(
markdown: Data,
Expand Down
9 changes: 3 additions & 6 deletions Sources/SpeziViews/Views/Tiles/SimpleTile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import SwiftUI

// TODO: snapshot testing!


/// A tile-like view with header, footer and an optional action.
///
Expand Down Expand Up @@ -73,7 +71,7 @@ public struct SimpleTile<Header: View, Body: View, Footer: View>: View {
/// - header: The header view of the tile. Refer to ``TileHeader`` for a great default layout for tile headers.
/// - body: The body of the tile.
/// - footer: A footer that can be used to place buttons or other actions.
public init( // swiftlint:disable:this function_default_parameter_at_end
public init(
alignment: HorizontalAlignment = .leading,
@ViewBuilder header: () -> Header,
@ViewBuilder body: () -> Body = { EmptyView() },
Expand All @@ -90,22 +88,21 @@ public struct SimpleTile<Header: View, Body: View, Footer: View>: View {
/// - alignment: The alignment of the tile.
/// - header: The header view of the tile. Refer to ``TileHeader`` for a great default layout for tile headers.
/// - body: The body of the tile.
public init( // swiftlint:disable:this function_default_parameter_at_end
public init(
alignment: HorizontalAlignment = .leading,
@ViewBuilder header: () -> Header,
@ViewBuilder body: () -> Body
) where Footer == EmptyView {
self.init(alignment: alignment, header: header, body: body) {
EmptyView()
}

}

/// Create a new tile view.
/// - Parameters:
/// - alignment: The alignment of the tile.
/// - header: The header view of the tile. Refer to ``TileHeader`` for a great default layout for tile headers.
public init( // swiftlint:disable:this function_default_parameter_at_end
public init(
alignment: HorizontalAlignment = .leading,
@ViewBuilder header: () -> Header
) where Body == EmptyView, Footer == EmptyView {
Expand Down
2 changes: 0 additions & 2 deletions Sources/SpeziViews/Views/Tiles/TileHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import SwiftUI

// TODO: snapshot testing!


/// A header layout for tiles.
///
Expand Down
71 changes: 71 additions & 0 deletions Tests/SpeziViewsTests/SnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,75 @@ final class SnapshotTests: XCTestCase {

XCTAssertNil(nonExistingImage.image)

Check failure on line 71 in Tests/SpeziViewsTests/SnapshotTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package watchOS / Test using xcodebuild or run fastlane

testImageReference, XCTAssertNil failed: "Image(provider: SwiftUI.ImageProviderBox<SwiftUI.Image.NamedImageProvider>)"
}

@MainActor
func testTileHeaderLayout() {
struct TestView: View {
private let alignment: HorizontalAlignment

var body: some View {
TileHeader(alignment: alignment) {
Image(systemName: "book.pages.fill")
.foregroundStyle(.teal)
.font(.custom("Task Icon", size: 30, relativeTo: .headline))
.dynamicTypeSize(...DynamicTypeSize.accessibility2)
.accessibilityHidden(true)
} title: {
Text("Clean Code")
} subheadline: {
Text("by Robert C. Martin")
}
}

init(alignment: HorizontalAlignment) {
self.alignment = alignment
}
}

let leadingTileHeader = TestView(alignment: .leading)
let centerTileHeader = TestView(alignment: .center)
let trailingTileHeader = TestView(alignment: .trailing)

#if os(iOS)
assertSnapshot(of: leadingTileHeader, as: .image(layout: .device(config: .iPhone13Pro)), named: "leading")
assertSnapshot(of: centerTileHeader, as: .image(layout: .device(config: .iPhone13Pro)), named: "center")
assertSnapshot(of: trailingTileHeader, as: .image(layout: .device(config: .iPhone13Pro)), named: "trailing")
#endif
}

@MainActor
func testSimpleTile() {
struct TileView: View {
private let alignment: HorizontalAlignment

var body: some View {
SimpleTile(alignment: alignment) {
Text("Clean Code")
} body: {
Text("A book by Robert C. Martin")
} footer: {
Button {
} label: {
Text("Buy")
.frame(maxWidth: .infinity, minHeight: 30)
}
.buttonStyle(.borderedProminent)
}
}

init(alignment: HorizontalAlignment) {
self.alignment = alignment
}
}

let tileLeading = TileView(alignment: .leading)
let tileCenter = TileView(alignment: .center)
let tileTraining = TileView(alignment: .trailing)

#if os(iOS)
assertSnapshot(of: tileLeading, as: .image(layout: .device(config: .iPhone13Pro)), named: "leading")
assertSnapshot(of: tileCenter, as: .image(layout: .device(config: .iPhone13Pro)), named: "center")
assertSnapshot(of: tileTraining, as: .image(layout: .device(config: .iPhone13Pro)), named: "trailing")
#endif
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 87ec7a3

Please sign in to comment.