Skip to content

Commit 5ad03ff

Browse files
author
Alexey Naumov
committed
Migrate to ViewInspector 0.8.1
1 parent 33a7cef commit 5ad03ff

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

CountriesSwiftUI.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@
10131013
repositoryURL = "https://github.com/nalexn/ViewInspector";
10141014
requirement = {
10151015
kind = exactVersion;
1016-
version = 0.7.4;
1016+
version = 0.8.1;
10171017
};
10181018
};
10191019
F6E7ACE023F5D1EC00AB48AB /* XCRemoteSwiftPackageReference "EnvironmentOverrides" */ = {

CountriesSwiftUI/UI/RootViewModifier.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ struct RootViewAppearance: ViewModifier {
1515

1616
@Environment(\.injected) private var injected: DIContainer
1717
@State private var isActive: Bool = false
18-
let inspection = PassthroughSubject<((AnyView) -> Void), Never>()
18+
internal let inspection = Inspection<Self>()
1919

2020
func body(content: Content) -> some View {
2121
content
2222
.blur(radius: isActive ? 0 : 10)
2323
.onReceive(stateUpdate) { self.isActive = $0 }
24-
.onReceive(inspection) { callback in
25-
callback(AnyView(self.body(content: content)))
26-
}
24+
.onReceive(inspection.notice) { self.inspection.visit(self, $0) }
2725
}
2826

2927
private var stateUpdate: AnyPublisher<Bool, Never> {

CountriesSwiftUI/Utilities/Helpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension Result {
3939

4040
// MARK: - View Inspection helper
4141

42-
internal final class Inspection<V> where V: View {
42+
internal final class Inspection<V> {
4343
let notice = PassthroughSubject<UInt, Never>()
4444
var callbacks = [UInt: (V) -> Void]()
4545

UnitTests/UI/RootViewAppearanceTests.swift

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,18 @@ import SwiftUI
1111
import ViewInspector
1212
@testable import CountriesSwiftUI
1313

14-
private typealias ModifierContent = _ViewModifier_Content<RootViewAppearance>
15-
16-
extension ModifierContent: Inspectable { }
14+
extension RootViewAppearance: Inspectable { }
1715

1816
final class RootViewAppearanceTests: XCTestCase {
1917

2018
func test_blur_whenInactive() {
2119
let sut = RootViewAppearance()
22-
let exp = XCTestExpectation(description: #function)
2320
let container = DIContainer(appState: .init(AppState()),
2421
interactors: .mocked())
2522
XCTAssertFalse(container.appState.value.system.isActive)
26-
DispatchQueue.main.async {
27-
sut.inspection.send { body in
28-
body.inspect { content in
29-
XCTAssertEqual(try content.anyView()
30-
.view(ModifierContent.self).blur().radius, 10)
31-
}
32-
ViewHosting.expel()
33-
exp.fulfill()
34-
}
23+
let exp = sut.inspection.inspect { modifier in
24+
let content = try modifier.viewModifierContent()
25+
XCTAssertEqual(try content.blur().radius, 10)
3526
}
3627
let view = EmptyView().modifier(sut)
3728
.environment(\.injected, container)
@@ -41,20 +32,13 @@ final class RootViewAppearanceTests: XCTestCase {
4132

4233
func test_blur_whenActive() {
4334
let sut = RootViewAppearance()
44-
let exp = XCTestExpectation(description: #function)
4535
let container = DIContainer(appState: .init(AppState()),
4636
interactors: .mocked())
4737
container.appState[\.system.isActive] = true
4838
XCTAssertTrue(container.appState.value.system.isActive)
49-
DispatchQueue.main.async {
50-
sut.inspection.send { body in
51-
body.inspect { content in
52-
XCTAssertEqual(try content.anyView()
53-
.view(ModifierContent.self).blur().radius, 0)
54-
}
55-
ViewHosting.expel()
56-
exp.fulfill()
57-
}
39+
let exp = sut.inspection.inspect { modifier in
40+
let content = try modifier.viewModifierContent()
41+
XCTAssertEqual(try content.blur().radius, 0)
5842
}
5943
let view = EmptyView().modifier(sut)
6044
.environment(\.injected, container)

0 commit comments

Comments
 (0)