-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a323d5c
commit 4099266
Showing
8 changed files
with
182 additions
and
2 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
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,136 @@ | ||
// | ||
// Created by David Whetstone on 2018-11-04. | ||
// Copyright (c) 2018 Segment. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Quick | ||
import Nimble | ||
import SwiftTryCatch | ||
@testable import Analytics | ||
|
||
class AutoScreenReportingTests: QuickSpec { | ||
|
||
override func spec() { | ||
|
||
var window: UIWindow! | ||
var rootVC: UIViewController! | ||
|
||
beforeEach { | ||
let config = SEGAnalyticsConfiguration(writeKey: "foobar") | ||
config.trackApplicationLifecycleEvents = true | ||
config.recordScreenViews = true | ||
|
||
window = UIWindow() | ||
rootVC = UIViewController() | ||
window.addSubview(rootVC.view) | ||
} | ||
|
||
|
||
describe("given a single view controller") { | ||
|
||
it("seg_topViewController returns that view controller") { | ||
let actualVC = UIViewController.seg_topViewController(rootVC) | ||
expect(actualVC) === rootVC | ||
} | ||
} | ||
|
||
describe("given a presented view controller") { | ||
|
||
var expectedVC: UIViewController! | ||
|
||
beforeEach { | ||
expectedVC = UIViewController() | ||
rootVC.present(expectedVC, animated: false) | ||
} | ||
|
||
it("seg_topViewController returns the presented view controller") { | ||
let actualVC = UIViewController.seg_topViewController(rootVC) | ||
expect(actualVC) === expectedVC | ||
} | ||
} | ||
|
||
describe("given a pushed view controller") { | ||
|
||
var expectedVC: UIViewController! | ||
|
||
beforeEach { | ||
expectedVC = UIViewController() | ||
let nc = UINavigationController() | ||
rootVC.present(nc, animated: false) | ||
nc.pushViewController(expectedVC, animated: false) | ||
} | ||
|
||
it("seg_topViewController returns the pushed view controller") { | ||
let actualVC = UIViewController.seg_topViewController(rootVC) | ||
expect(actualVC) === expectedVC | ||
} | ||
} | ||
|
||
describe("given a child of a UITabBarController") { | ||
|
||
var expectedVC: UIViewController! | ||
|
||
beforeEach { | ||
expectedVC = UIViewController() | ||
let tabBarController = UITabBarController() | ||
rootVC.present(tabBarController, animated: false) | ||
tabBarController.viewControllers = [UIViewController(), expectedVC, UIViewController()] | ||
tabBarController.selectedIndex = 1 | ||
} | ||
|
||
it("seg_topViewController returns the currently selected view controller") { | ||
let actualVC = UIViewController.seg_topViewController(rootVC) | ||
expect(actualVC) === expectedVC | ||
} | ||
} | ||
|
||
describe("given a child of a custom container view controller conforming to SEGScreenReporting") { | ||
|
||
class CustomContainerViewController: UIViewController, SEGScreenReporting { | ||
var selectedIndex: Int = 0 | ||
var seg_mainViewController: UIViewController? { | ||
return childViewControllers[selectedIndex] | ||
} | ||
} | ||
|
||
var expectedVC: UIViewController! | ||
|
||
beforeEach { | ||
expectedVC = UIViewController() | ||
let containerVC = CustomContainerViewController() | ||
rootVC.present(containerVC, animated: false) | ||
[UIViewController(), expectedVC, UIViewController()].forEach { child in | ||
containerVC.addChildViewController(child) | ||
} | ||
containerVC.selectedIndex = 1 | ||
} | ||
|
||
it("seg_topViewController returns the currently selected view controller") { | ||
let actualVC = UIViewController.seg_topViewController(rootVC) | ||
expect(actualVC) === expectedVC | ||
} | ||
} | ||
|
||
describe("given a child of a container view controller NOT conforming to SEGScreenReporting") { | ||
|
||
var expectedVC: UIViewController! | ||
|
||
beforeEach { | ||
expectedVC = UIViewController() | ||
let containerVC = UIViewController() | ||
rootVC.present(containerVC, animated: false) | ||
[expectedVC, UIViewController(), UIViewController()].forEach { child in | ||
containerVC.addChildViewController(child) | ||
} | ||
} | ||
|
||
it("seg_topViewController returns the first child view controller") { | ||
let actualVC = UIViewController.seg_topViewController(rootVC) | ||
expect(actualVC) === expectedVC | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
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,21 @@ | ||
// | ||
// UIViewController+SegScreenTest.h | ||
// Analytics | ||
// | ||
// Created by David Whetstone on 7/15/19. | ||
// Copyright © 2019 Segment. All rights reserved. | ||
// | ||
|
||
#ifndef UIViewController_SegScreenTest_h | ||
#define UIViewController_SegScreenTest_h | ||
|
||
|
||
@interface UIViewController (Testing) | ||
/// We need to expose this normally private method to tests, as the public facing | ||
/// `+ (UIViewController *)seg_topViewController` relies on the `application` property | ||
/// of `SEGAnalyticsConfiguration`, which won't be set in these tests. | ||
+ (UIViewController *)seg_topViewController:(UIViewController *)rootViewController; | ||
@end | ||
|
||
|
||
#endif /* UIViewController_SegScreenTest_h */ |
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