From 9c3a69cb7f71dea59f0ce51f393445bb1be468cd Mon Sep 17 00:00:00 2001 From: Domas Nutautas Date: Thu, 22 Aug 2019 22:16:47 +0300 Subject: [PATCH] Add default handle(update:) implementation --- StoryFlow/Interfaces/UpdateHandling.swift | 4 ++++ StoryFlowTests/ExplicitFlowTests.swift | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/StoryFlow/Interfaces/UpdateHandling.swift b/StoryFlow/Interfaces/UpdateHandling.swift index d7ae82c..a48ef9c 100644 --- a/StoryFlow/Interfaces/UpdateHandling.swift +++ b/StoryFlow/Interfaces/UpdateHandling.swift @@ -4,3 +4,7 @@ public protocol UpdateHandling: _AnyUpdateHandling { associatedtype UpdateType func handle(update: UpdateType) } + +extension UpdateHandling where Self: UIViewController { + public func handle(update: UpdateType) {} +} diff --git a/StoryFlowTests/ExplicitFlowTests.swift b/StoryFlowTests/ExplicitFlowTests.swift index b7eebfa..7b505d2 100644 --- a/StoryFlowTests/ExplicitFlowTests.swift +++ b/StoryFlowTests/ExplicitFlowTests.swift @@ -90,6 +90,27 @@ class ExplicitFlowTests: XCTestCase { // MARK: Unwind + func testProduce_itUnwindsToUpdateHandlingVc() { + + // Arrange + class From: UIViewController, OutputProducing { typealias OutputType = Int } + class To: UIViewController, UpdateHandling { typealias UpdateType = Int } + + let to = To().visible() + let from = From() + from.flow = .unwind() + + to.show(from, sender: nil) + XCTAssert(currentVc.didAppear()) + + // Act + from.produce(2018) + XCTAssert(currentVc.didDismiss()) + + // Assert + XCTAssert(currentVc == to) + } + func testProduce_itUnwindsToUpdateHandlingVcAndPassesOutput() { // Arrange