I'm attempting to write a quick/nimble test that will just confirm a few things on the screen after my opening screen. The opening screen is simply a button which leads to oauth2 sign in to validate users. I'm just wondering how it is I can spoof a sign in so that I can get to the next screen. I know this is probably not a lot of information but I'm really new to the testing aspect of swift as a whole but I know it's very important to have unit tests.
Here is code that might help:
import UIKit
class ViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate {
@IBOutlet weak var signInButton: GIDSignInButton!
@IBOutlet weak var errorLabel: UILabel!
var googleViewController: GoogleViewController!
var permittedList:[String] = ["me@mysite.com"]
let env = NSProcessInfo.processInfo().environment
override func viewDidLoad() {
self.view.backgroundColor = UIColor(rgb: 0x6a737b)
super.viewDidLoad()
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().clientID = env["CLIENT_ID"] as? String
GIDSignIn.sharedInstance().signInSilently()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "googledisplay" {
googleViewController = segue.destinationViewController as! GoogleViewController
}
}
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
if let err = error {
println(error)
}
else {
if !contains(permittedList, GIDSignIn.sharedInstance().currentUser.profile.email) {
GIDSignIn.sharedInstance().signOut()
GIDSignIn.sharedInstance().disconnect()
self.errorLabel.text = "You must sign in with a permitted email address"
}
else{
self.errorLabel.text = ""
performSegueWithIdentifier("googledisplay", sender: self)
}
}
}
}
test:
import Foundation
import Quick
import Nimble
import PasswordRecovery
class PasswordViewControllerSpec: QuickSpec {
var viewController = PasswordViewController()
override func spec() {
let _ = PasswordViewController().view
viewController.setNewEmail("s@s.com")
viewController.setNewLRA("unknown")
viewController.reset_code(t: 1447267160)
expect(self.viewController.getLRA()).to(equal("LRA"))
}
}
PasswordViewController is the name of the view which is loaded after the original screen. Thank you for any help, if there is anything more needed please tell me!
Aucun commentaire:
Enregistrer un commentaire