Skip to content

Commit

Permalink
add UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpbrett committed Dec 30, 2020
1 parent e470053 commit 120beaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions BeeSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
resetStateIfUITesting()

UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.font :
UIFont.beeminder.defaultFontPlain.withSize(20)]
Expand Down Expand Up @@ -148,4 +149,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
completionHandler([.alert, .sound, .badge])
}
}

private func resetStateIfUITesting() {
if ProcessInfo.processInfo.arguments.contains("UI-Testing") {
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
}
}
}
16 changes: 8 additions & 8 deletions BeeSwift/BeeSwiftUITests/LaunchScreenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ import XCTest
class LaunchScreenTests: XCTestCase {

static var app: XCUIApplication?
var userDefaults: UserDefaults?
let userDefaultsSuiteName = "TestDefaults"

override func setUp() {
super.setUp()
UserDefaults().removePersistentDomain(forName: userDefaultsSuiteName)
userDefaults = UserDefaults(suiteName: userDefaultsSuiteName)
if let appDomain = Bundle.main.bundleIdentifier {
UserDefaults.standard.removePersistentDomain(forName: appDomain)
}
let app = XCUIApplication()
app.launchArguments += ["UI-Testing"]
app.launch()
}

Expand All @@ -30,12 +38,4 @@ class LaunchScreenTests: XCTestCase {
XCTAssertTrue(app.buttons["Sign In"].exists)
XCTAssertTrue(app.textFields["Email or username"].exists)
}

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

}
1 change: 1 addition & 0 deletions BeeSwift/CurrentUserManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class CurrentUserManager : NSObject {

func fetchGoals(success: ((_ goals : [JSONGoal]) -> ())?, error: ((_ error : Error?, _ errorMessage : String?) -> ())?) {
guard let username = self.username else {
CurrentUserManager.sharedManager.signOut()
success?([])
return
}
Expand Down

0 comments on commit 120beaa

Please sign in to comment.