Skip to content

Commit 542c248

Browse files
author
Mikhail Markin
committed
tests added childViewControllerIsNotLeakingWhenParentFlowAllowsStepWhenDismissed
1 parent 8bc0da5 commit 542c248

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

RxFlowTests/FlowCoordinatorTests.swift

+57
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,36 @@ final class TestLeakingFlow: Flow {
230230
}
231231
}
232232

233+
final class TestChildLeakingFlow: Flow {
234+
final class ChildViewController: UIViewController {
235+
var onDeinit: (() -> Void)? = nil
236+
237+
deinit {
238+
onDeinit?()
239+
}
240+
}
241+
242+
var root: Presentable = UIViewController()
243+
weak var childViewController: ChildViewController? = nil
244+
245+
func navigate(to step: Step) -> FlowContributors {
246+
guard let step = step as? TestSteps else { return .none }
247+
248+
switch step {
249+
case .one:
250+
let viewController = ChildViewController()
251+
childViewController = viewController
252+
let flowContributor = FlowContributor.contribute(
253+
withNextPresentable: viewController,
254+
withNextStepper: DefaultStepper()
255+
)
256+
return .one(flowContributor: flowContributor)
257+
default:
258+
return .none
259+
}
260+
}
261+
}
262+
233263
final class FlowCoordinatorTests: XCTestCase {
234264

235265
func testCoordinateWithOneStepper() {
@@ -368,6 +398,33 @@ final class FlowCoordinatorTests: XCTestCase {
368398

369399
XCTAssertNil(leakingFlowReference)
370400
}
401+
402+
func testChildViewControllerIsNotLeakingWhenParentFlowAllowsStepWhenDismissed() throws {
403+
let exp = expectation(description: "Flow when ready")
404+
let flowCoordinator = FlowCoordinator()
405+
let parentFlow = TestChildLeakingFlow()
406+
407+
flowCoordinator.coordinate(flow: parentFlow,
408+
with: OneStepper(withSingleStep: TestSteps.one),
409+
allowStepWhenDismissed: true)
410+
411+
Flows.use(parentFlow, when: .created) { (_) in
412+
exp.fulfill()
413+
}
414+
415+
waitForExpectations(timeout: 1)
416+
417+
XCTAssertNotNil(parentFlow.childViewController)
418+
419+
let deallocExp = expectation(description: "Child view controller deallocated")
420+
parentFlow.childViewController?.onDeinit = { deallocExp.fulfill() }
421+
422+
try XCTUnwrap(parentFlow.childViewController).didMove(toParent: nil)
423+
424+
waitForExpectations(timeout: 1)
425+
426+
XCTAssertNil(parentFlow.childViewController)
427+
}
371428

372429
func testNavigate_executes_on_mainThread() {
373430
class ThreadRecorderFlow: Flow {

0 commit comments

Comments
 (0)