Skip to content

Commit

Permalink
#255: Slight refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Naumov committed Aug 26, 2023
1 parent 0f872b5 commit 0def023
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Sources/ViewInspector/SwiftUI/ViewThatFits.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import SwiftUI

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
internal extension ViewType {
public extension ViewType {
struct ViewThatFits {}
}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
extension ViewType.ViewThatFits: SingleViewContent {

static func child(_ content: Content) throws -> Content {
public static func child(_ content: Content) throws -> Content {
let view: Any = try {
guard let rootContent = try? Inspector.attribute(path: "_tree|content", value: content.view) else {
// A ViewThatFits View renders only one of its child Views based on the available horizontal space.
Expand Down
30 changes: 22 additions & 8 deletions Tests/ViewInspectorTests/SwiftUI/ViewThatFitsTests.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
import XCTest
import SwiftUI

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
final class ViewThatFitsTests: XCTestCase {

func testAllEnclosedChildTextViews() throws {
guard #available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
else { throw XCTSkip() }

This comment has been minimized.

Copy link
@bachand

bachand Aug 28, 2023

Contributor

TIL about XCTSkip()!

let sut = TestViewThatFits()
let longText = try sut.inspect().find(text: "Very long text that will only get picked if there is available space.")
let shortText = try sut.inspect().find(text: "Short text")
let shortString = TestViewThatFits.shortString
let longString = TestViewThatFits.longString
let longText = try sut.inspect().find(text: longString)
let shortText = try sut.inspect().find(text: shortString)

XCTAssertEqual(try longText.string(), "Very long text that will only get picked if there is available space.")
XCTAssertEqual(try shortText.string(), "Short text")
XCTAssertEqual(try longText.string(), longString)
XCTAssertEqual(try shortText.string(), shortString)
}
}

// MARK: - TestViewThatFits

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
struct TestViewThatFits: View {
private struct TestViewThatFits: View {

static var longString: String {
"Very long text that will only get picked if there is available space."
}

static var shortString: String {
"Short text"
}

var body: some View {
ViewThatFits {
Text("Very long text that will only get picked if there is available space.")
Text("Short text")
Text(Self.longString)
Text(Self.shortString)
}
}
}

0 comments on commit 0def023

Please sign in to comment.