From 0def023b706034d9e570557437225d2c737d8939 Mon Sep 17 00:00:00 2001 From: Alexey Naumov Date: Sat, 26 Aug 2023 21:00:34 +0600 Subject: [PATCH] #255: Slight refactoring --- .../ViewInspector/SwiftUI/ViewThatFits.swift | 4 +-- .../SwiftUI/ViewThatFitsTests.swift | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Sources/ViewInspector/SwiftUI/ViewThatFits.swift b/Sources/ViewInspector/SwiftUI/ViewThatFits.swift index 0b3e6a91..37b308eb 100644 --- a/Sources/ViewInspector/SwiftUI/ViewThatFits.swift +++ b/Sources/ViewInspector/SwiftUI/ViewThatFits.swift @@ -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. diff --git a/Tests/ViewInspectorTests/SwiftUI/ViewThatFitsTests.swift b/Tests/ViewInspectorTests/SwiftUI/ViewThatFitsTests.swift index cbb75e8e..d649ef9b 100644 --- a/Tests/ViewInspectorTests/SwiftUI/ViewThatFitsTests.swift +++ b/Tests/ViewInspectorTests/SwiftUI/ViewThatFitsTests.swift @@ -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() } 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) } } }