-
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] Any good example project should include ideas on how to tes…
…t it, so let's add tests! - TT
- Loading branch information
1 parent
a6f922f
commit c489e7d
Showing
12 changed files
with
389 additions
and
28 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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,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
108
WorkflowExampleTests/LocationsViewControllerTests.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,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) | ||
} | ||
} |
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 @@ | ||
// | ||
// 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. | ||
} | ||
} | ||
|
||
} |