Skip to content

Commit

Permalink
[ci skip] Any good example project should include ideas on how to tes…
Browse files Browse the repository at this point in the history
…t it, so let's add tests! - TT
  • Loading branch information
Tyler-Keith-Thompson committed Sep 25, 2019
1 parent a6f922f commit c489e7d
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 28 deletions.
6 changes: 6 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ target 'WorkflowExample' do
use_frameworks!

pod 'DynamicWorkflow', :path => '.'

target 'WorkflowExampleTests' do
pod 'DynamicWorkflow', :path => '.'
pod 'UIUTest'
end

end
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ SPEC CHECKSUMS:
DynamicWorkflow: a45e06c1d0448d295ed3572ccc591a347fe40237
UIUTest: 842c642e5bec098b1e2c890cbe25aacab80f2481

PODFILE CHECKSUM: 18326f83e0ef521b2ecc44966469cd4f4412e5b1
PODFILE CHECKSUM: 5f55f064de83e2e4f31f04427448900a8e9571f2

COCOAPODS: 1.7.5
178 changes: 171 additions & 7 deletions Workflow.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Workflow.xcodeproj/xcshareddata/xcschemes/WorkflowExample.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,28 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
systemAttachmentLifetime = "keepNever"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "# Type a script or drag a script file from your workspace to insert its path.&#10;pod install&#10;">
</ActionContent>
</ExecutionAction>
</PreActions>
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AD5BB00A231B82C9001DAF7C"
BuildableName = "WorkflowExample.app"
BlueprintName = "WorkflowExample"
ReferencedContainer = "container:Workflow.xcodeproj">
</BuildableReference>
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -38,6 +59,16 @@
ReferencedContainer = "container:Workflow.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ADEE774E233BAA6C007E9FD2"
BuildableName = "WorkflowExampleTests.xctest"
BlueprintName = "WorkflowExampleTests"
ReferencedContainer = "container:Workflow.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
16 changes: 0 additions & 16 deletions WorkflowExample/Extensions/OptionSetExtensions.swift

This file was deleted.

6 changes: 5 additions & 1 deletion WorkflowExample/Ordering/LocationsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class LocationsViewController: UIWorkflowItem<[Location]>, StoryboardLoadable {
extension LocationsViewController: FlowRepresentable {
func shouldLoad(with locations: [Location]) -> Bool {
self.locations = locations
return true
if let location = locations.first,
locations.count == 1 {
proceedInWorkflow(Order(location: location))
}
return locations.count > 1
}
}

Expand Down
4 changes: 4 additions & 0 deletions WorkflowExample/Ordering/ReviewOrderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class ReviewOrderViewController: UIWorkflowItem<Order>, StoryboardLoadable {
this.text = order?.shoppingCart.compactMap { $0.name }.joined(separator: ", ")
}
}

// @IBAction func editLocation() {
//
// }
}

extension ReviewOrderViewController: FlowRepresentable {
Expand Down
6 changes: 5 additions & 1 deletion WorkflowExample/Protocols/StoryboardLoadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import DynamicWorkflow
protocol StoryboardLoadable {}

extension StoryboardLoadable {
static var storyboardId:String {
return String(describing: Self.self)
}

static func instance() -> AnyFlowRepresentable {
return Storyboard.main.instantiateViewController(withIdentifier: String(describing: Self.self)) as! AnyFlowRepresentable
return Storyboard.main.instantiateViewController(withIdentifier: storyboardId) as! AnyFlowRepresentable
}
}
4 changes: 2 additions & 2 deletions WorkflowExample/SetupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class SetupViewController: UIViewController {
address: Address(line1: "123 Fake St", line2: "", city: "Fakerton", state: "FK", zip: "00001"),
orderTypes: [OrderType.pickup], menuTypes: [MenuType.catering, MenuType.regular]),
Location(name: "Pickup And Delivery w/ just regular menu",
address: Address(line1: "234 Fake St", line2: "", city: "Fakerton", state: "FK", zip: "00002"),
address: Address(line1: "567 Fake St", line2: "", city: "Fakerton", state: "FK", zip: "00003"),
orderTypes: [OrderType.pickup, OrderType.delivery(Address(line1: "", line2: "", city: "", state: "", zip: ""))],
menuTypes: [.regular]),
Location(name: "Pickup And Delivery w/ all menu types",
address: Address(line1: "234 Fake St", line2: "", city: "Fakerton", state: "FK", zip: "00002"),
address: Address(line1: "890 Fake St", line2: "", city: "Fakerton", state: "FK", zip: "00004"),
orderTypes: [OrderType.pickup, OrderType.delivery(Address(line1: "", line2: "", city: "", state: "", zip: ""))],
menuTypes: [.catering, .regular]),
]
Expand Down
22 changes: 22 additions & 0 deletions WorkflowExampleTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
108 changes: 108 additions & 0 deletions WorkflowExampleTests/LocationsViewControllerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// LocationsViewControllerTests.swift
// WorkflowExampleTests
//
// Created by Tyler Thompson on 9/25/19.
// Copyright © 2019 Tyler Thompson. All rights reserved.
//

import Foundation
import XCTest
import UIUTest

@testable import WorkflowExample

class LocationsViewControllerTests:XCTestCase {
typealias ControllerType = LocationsViewController
var testViewController:ControllerType!
var tableView:UITableView!
override func setUp() {
loadFromStoryboard()
}

private func loadFromStoryboard(configure: ((ControllerType) -> Void)? = nil) {
testViewController = UIViewController.loadFromStoryboard(identifier: ControllerType.storyboardId, configure:configure)
tableView = testViewController.tableView
}

func testShouldLoadOnlyIfThereAreMultipleLocations() {
XCTAssertFalse(testViewController.shouldLoad(with: []), "LocationsViewController should not load if there are less than 2 locations")
XCTAssertTrue(testViewController.shouldLoad(with: [
Location(name: "", address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: []),
Location(name: "", address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: [])
]), "LocationsViewController should load if there are multiple locations")
}

func testLocationsShouldPassAlongOrderWithDefaultLocation_IfThereIsOnlyOne() {
let rand = UUID().uuidString
var callbackCalled = false
loadFromStoryboard { viewController in
viewController.callback = { data in
callbackCalled = true
XCTAssert(data is Order, "View should pass on data as an order object")
XCTAssertEqual((data as? Order)?.location?.name, rand, "The location in the order should be the same one selected")
}
_ = viewController.shouldLoad(with: [
Location(name: rand, address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: [])
])
}

XCTAssert(callbackCalled)
}

func testViewShouldTakeInLocationsData() {
let rand1 = UUID().uuidString
let rand2 = UUID().uuidString
let loc1 = Location(name: rand1, address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: [])
let loc2 = Location(name: rand2, address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: [])
_ = testViewController.shouldLoad(with: [loc1, loc2])

XCTAssertEqual(testViewController.locations.first?.name, rand1)
XCTAssertEqual(testViewController.locations.last?.name, rand2)
}

func testTableViewShouldHaveRowsEqualToNumberOfLocations() {
loadFromStoryboard { viewController in
_ = viewController.shouldLoad(with: [
Location(name: "", address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: []),
Location(name: "", address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: [])
])
}

XCTAssertEqual(testViewController.tableView(tableView, numberOfRowsInSection: 0), 2)
}

func testTableViewCellShouldContainLocationName() {
let rand = UUID().uuidString
loadFromStoryboard { viewController in
_ = viewController.shouldLoad(with: [
Location(name: rand, address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: []),
Location(name: "", address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: [])
])
}

let cell = testViewController.tableView(tableView, cellForRowAt: IndexPath(row: 0, section: 0))

XCTAssertEqual(cell.textLabel?.text, rand)
}

func testWhenTableViewIsSelectedAnOrderShouldBeCreatedAndPassedToTheNextView() {
let rand = UUID().uuidString
var callbackCalled = false
loadFromStoryboard { viewController in
_ = viewController.shouldLoad(with: [
Location(name: rand, address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: []),
Location(name: "", address: Address(line1: "", line2: "", city: "", state: "", zip: ""), orderTypes: [], menuTypes: [])
])
viewController.callback = { data in
callbackCalled = true
XCTAssert(data is Order, "View should pass on data as an order object")
XCTAssertEqual((data as? Order)?.location?.name, rand, "The location in the order should be the same one selected")
}
}

testViewController.tableView(tableView, didSelectRowAt: IndexPath(row: 0, section: 0))

XCTAssert(callbackCalled)
}
}
34 changes: 34 additions & 0 deletions WorkflowExampleTests/WorkflowExampleTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// WorkflowExampleTests.swift
// WorkflowExampleTests
//
// Created by Tyler Thompson on 9/25/19.
// Copyright © 2019 Tyler Thompson. All rights reserved.
//

import XCTest
@testable import WorkflowExample

class WorkflowExampleTests: XCTestCase {

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}

0 comments on commit c489e7d

Please sign in to comment.