-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci skip] Add tests around the rest of the workflow example - TT
- Loading branch information
1 parent
535fa62
commit fbd4586
Showing
10 changed files
with
209 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
WorkflowExampleTests/EnterAddressViewControllerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// EnterAddressViewControllerTests.swift | ||
// WorkflowExampleTests | ||
// | ||
// Created by Tyler Thompson on 10/5/19. | ||
// Copyright © 2019 Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
@testable import WorkflowExample | ||
|
||
class EnterAddressViewControllerTests: ViewControllerTest<EnterAddressViewController> { | ||
func testViewShouldAlwaysLoad() { | ||
let order = Order(location: nil) | ||
XCTAssert(testViewController.shouldLoad(with: order)) | ||
} | ||
|
||
func testSavingAddressProceedsInWorkflow() { | ||
var proceedInWorkflowCalled = false | ||
let order = Order(location: nil) | ||
testViewController.order = order | ||
|
||
testViewController.callback = { data in | ||
proceedInWorkflowCalled = true | ||
XCTAssertEqual((data as? Order)?.orderType, .delivery(Address())) | ||
} | ||
|
||
testViewController.saveAddress() | ||
|
||
XCTAssert(proceedInWorkflowCalled) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// MockPresenter.swift | ||
// WorkflowExampleTests | ||
// | ||
// Created by Tyler Thompson on 10/5/19. | ||
// Copyright © 2019 Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
@testable import DynamicWorkflow | ||
|
||
class MockPresenter: Presenter { | ||
var abandonCalled = 0 | ||
var lastWorkflow:Workflow? | ||
var lastAnimated:Bool? | ||
func abandon(_ workflow: Workflow, animated: Bool, onFinish: (() -> Void)?) { | ||
abandonCalled += 1 | ||
lastWorkflow = workflow | ||
lastAnimated = animated | ||
onFinish?() | ||
} | ||
required init() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// WorkflowListener.swift | ||
// WorkflowExampleTests | ||
// | ||
// Created by Tyler Thompson on 10/5/19. | ||
// Copyright © 2019 Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
@testable import DynamicWorkflow | ||
|
||
class WorkflowListener { | ||
var workflow:Workflow? | ||
var launchStyle:PresentationType? | ||
var args:Any? | ||
var launchedFrom:AnyFlowRepresentable? | ||
var onFinish:((Any?) -> Void)? | ||
init() { | ||
NotificationCenter.default.addObserver(self, selector: #selector(workflowLaunched(notification:)), name: .workflowLaunched, object: nil) | ||
} | ||
|
||
@objc func workflowLaunched(notification: Notification) { | ||
let dict = notification.object as? [String:Any?] | ||
workflow = dict?["workflow"] as? Workflow | ||
launchStyle = dict?["style"] as? PresentationType | ||
onFinish = dict?["onFinish"] as? ((Any?) -> Void) | ||
launchedFrom = dict?["launchFrom"] as? AnyFlowRepresentable | ||
args = dict?["args"] as Any? | ||
} | ||
} | ||
|
||
func XCTAssertWorkflowLaunched(listener: WorkflowListener, expectedFlowRepresentables:[AnyFlowRepresentable.Type]) { | ||
XCTAssertNotNil(listener.workflow, "No workflow found") | ||
guard let workflow = listener.workflow, expectedFlowRepresentables.count == workflow.count else { | ||
XCTFail("workflow does not contain correct representables: \(String(describing: listener.workflow?.compactMap { String(describing: $0.value) }) )") | ||
return | ||
} | ||
XCTAssertEqual(workflow.compactMap { String(describing: $0.value) }, | ||
expectedFlowRepresentables.map { String(describing: $0) }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// ReviewOrderViewControllerTests.swift | ||
// WorkflowExampleTests | ||
// | ||
// Created by Tyler Thompson on 10/5/19. | ||
// Copyright © 2019 Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
@testable import WorkflowExample | ||
|
||
class ReviewOrderViewControllerTests: ViewControllerTest<ReviewOrderViewController> { | ||
|
||
var locationNameLabel:UILabel! | ||
var menuLabel:UILabel! | ||
var orderTypeLabel:UILabel! | ||
var foodChoiceLabel:UILabel! | ||
|
||
override func afterLoadFromStoryboard() { | ||
locationNameLabel = testViewController.locationNameLabel | ||
menuLabel = testViewController.menuLabel | ||
orderTypeLabel = testViewController.orderTypeLabel | ||
foodChoiceLabel = testViewController.foodChoiceLabel | ||
} | ||
|
||
func testShouldLoad() { | ||
let order = Order(location: Location(name: "", address: Address(), orderTypes: [], menuTypes: [])) | ||
XCTAssert(testViewController.shouldLoad(with: order)) | ||
} | ||
|
||
func testShowOrderInformation() { | ||
let locationName = UUID().uuidString | ||
var order = Order(location: Location(name: locationName, address: Address(), orderTypes: [.delivery(Address())], menuTypes: [.catering])) | ||
order.menuType = .catering | ||
order.shoppingCart.append(Food(name: "Combo #1")) | ||
order.shoppingCart.append(Food(name: "Combo #2")) | ||
loadFromStoryboard { | ||
XCTAssert($0.shouldLoad(with: order)) | ||
} | ||
|
||
XCTAssertEqual(locationNameLabel.text, locationName) | ||
XCTAssertEqual(menuLabel.text, "Catering Menu") | ||
XCTAssertEqual(orderTypeLabel.text, "Delivery") | ||
XCTAssertEqual(foodChoiceLabel.text, "Combo #1, Combo #2") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// SetupViewControllerTests.swift | ||
// WorkflowExampleTests | ||
// | ||
// Created by Tyler Thompson on 10/5/19. | ||
// Copyright © 2019 Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
@testable import WorkflowExample | ||
|
||
class SetupViewControllerTests: ViewControllerTest<SetupViewController> { | ||
func testLaunchingMultiLocationWorkflow() { | ||
let listener = WorkflowListener() | ||
|
||
testViewController.launchMultiLocationWorkflow() | ||
|
||
XCTAssertWorkflowLaunched(listener: listener, expectedFlowRepresentables: [ | ||
LocationsViewController.self, | ||
PickupOrDeliveryViewController.self, | ||
MenuSelectionViewController.self, | ||
FoodSelectionViewController.self, | ||
ReviewOrderViewController.self, | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters