|
| 1 | +// |
| 2 | +// LoginViewControlerTests.swift |
| 3 | +// LoginReduxTests |
| 4 | +// |
| 5 | +// Created by GIB on 7/29/18. |
| 6 | +// Copyright © 2018 Xmen. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import XCTest |
| 10 | +@testable import LoginRedux |
| 11 | + |
| 12 | +class LoginViewControlerTests: XCTestCase { |
| 13 | + |
| 14 | + var loginVC: LoginViewController! |
| 15 | + |
| 16 | + override func setUp() { |
| 17 | + // Put setup code here. This method is called before the invocation of each test method in the class. |
| 18 | + let storyboard = UIStoryboard(name: "Main", bundle: nil) |
| 19 | + loginVC = storyboard.instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController |
| 20 | + |
| 21 | + // loading the view in hierarchy |
| 22 | + _ = loginVC.view |
| 23 | + loginVC.viewWillAppear(true) |
| 24 | + } |
| 25 | + |
| 26 | + override func tearDown() { |
| 27 | + |
| 28 | + loginVC = nil |
| 29 | + } |
| 30 | + |
| 31 | + func testErrorInitialState() { |
| 32 | + |
| 33 | + XCTAssertEqual(loginVC.usernameErrorLabel.isHidden, true) |
| 34 | + XCTAssertEqual(loginVC.passwordErrorLabel.isHidden, true) |
| 35 | + XCTAssertEqual(loginVC.loginErrorLabel.isHidden, true) |
| 36 | + } |
| 37 | + |
| 38 | + func testUsernameValidState() { |
| 39 | + loginVC.usernameTextField.text = "farooq" |
| 40 | + XCTAssertEqual(loginVC.usernameErrorLabel.isHidden, true) |
| 41 | + } |
| 42 | + |
| 43 | + func testUsernameInvalidState() { |
| 44 | + loginVC.usernameTextField.text = "abc" |
| 45 | + let len = (loginVC.usernameTextField.text?.count)!-1 |
| 46 | + _ = loginVC.textField(loginVC.usernameTextField, shouldChangeCharactersIn: NSMakeRange(0, len), replacementString:"d") |
| 47 | + XCTAssertEqual(loginVC.usernameErrorLabel.isHidden, false) |
| 48 | + } |
| 49 | + |
| 50 | + func testPasswordValidState() { |
| 51 | + loginVC.passwordTextField.text = "abdcefgh" |
| 52 | + XCTAssertEqual(loginVC.passwordErrorLabel.isHidden, true) |
| 53 | + } |
| 54 | + |
| 55 | + func testPasswordInvalidState() { |
| 56 | + loginVC.passwordTextField.text = "abcdef" |
| 57 | + let len = (loginVC.passwordTextField.text?.count)!-1 |
| 58 | + _ = loginVC.textField(loginVC.passwordTextField, shouldChangeCharactersIn: NSMakeRange(0, len), replacementString:"g") |
| 59 | + XCTAssertEqual(loginVC.passwordErrorLabel.isHidden, false) |
| 60 | + } |
| 61 | + |
| 62 | + func testLoginSuccessState() { |
| 63 | + loginVC.usernameTextField.text = "Farooq" |
| 64 | + loginVC.passwordTextField.text = "abcd1234" |
| 65 | + loginVC.loginTapped(self) |
| 66 | + |
| 67 | + XCTAssertEqual(loginVC.loginErrorLabel.isHidden, true) |
| 68 | + XCTAssertEqual(loginVC.loginButton.isEnabled, false) |
| 69 | + } |
| 70 | + |
| 71 | + func testLoginFailureState() { |
| 72 | + loginVC.usernameTextField.text = "farooq" |
| 73 | + loginVC.passwordTextField.text = "Sabcd1234" |
| 74 | + loginVC.loginTapped(self) |
| 75 | + |
| 76 | + XCTAssertEqual(loginVC.loginErrorLabel.isHidden, false) |
| 77 | + XCTAssertEqual(loginVC.loginButton.isEnabled, true) |
| 78 | + } |
| 79 | +} |
0 commit comments