Skip to content

Commit 3739d6c

Browse files
author
Khawaja Farooq
committed
LoginViewController Tests
1 parent b842135 commit 3739d6c

File tree

4 files changed

+91
-7
lines changed

4 files changed

+91
-7
lines changed

LoginRedux.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
0315EE7A210CDEBB00927F3F /* LoginHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0315EE79210CDEBB00927F3F /* LoginHelpers.swift */; };
1919
0315EE7C210CDEF100927F3F /* LoginReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0315EE7B210CDEF100927F3F /* LoginReducer.swift */; };
2020
0315EE7F210CF3D200927F3F /* LoginStateTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0315EE7E210CF3D200927F3F /* LoginStateTranslator.swift */; };
21+
038A5AB8210DCBB400C1E363 /* LoginViewControlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038A5AB7210DCBB400C1E363 /* LoginViewControlerTests.swift */; };
2122
08974617D825ED85EFC8FC9A /* Pods_LoginRedux.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4F2A747708C636AF271716E /* Pods_LoginRedux.framework */; };
2223
094674448491251CE138C468 /* Pods_LoginReduxTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81214DA8F51F4A4E086A031F /* Pods_LoginReduxTests.framework */; };
2324
/* End PBXBuildFile section */
@@ -48,6 +49,7 @@
4849
0315EE79210CDEBB00927F3F /* LoginHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginHelpers.swift; sourceTree = "<group>"; };
4950
0315EE7B210CDEF100927F3F /* LoginReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginReducer.swift; sourceTree = "<group>"; };
5051
0315EE7E210CF3D200927F3F /* LoginStateTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginStateTranslator.swift; sourceTree = "<group>"; };
52+
038A5AB7210DCBB400C1E363 /* LoginViewControlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewControlerTests.swift; sourceTree = "<group>"; };
5153
074CC28295FB465A1C9AC0B9 /* Pods-LoginRedux.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LoginRedux.release.xcconfig"; path = "Pods/Target Support Files/Pods-LoginRedux/Pods-LoginRedux.release.xcconfig"; sourceTree = "<group>"; };
5254
81214DA8F51F4A4E086A031F /* Pods_LoginReduxTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LoginReduxTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5355
867B7B5C3E71A52B4C5C13B4 /* Pods-LoginReduxTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LoginReduxTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-LoginReduxTests/Pods-LoginReduxTests.release.xcconfig"; sourceTree = "<group>"; };
@@ -119,6 +121,7 @@
119121
children = (
120122
0315EE6A210CDBDD00927F3F /* LoginReduxTests.swift */,
121123
0315EE6C210CDBDD00927F3F /* Info.plist */,
124+
038A5AB7210DCBB400C1E363 /* LoginViewControlerTests.swift */,
122125
);
123126
path = LoginReduxTests;
124127
sourceTree = "<group>";
@@ -319,6 +322,7 @@
319322
buildActionMask = 2147483647;
320323
files = (
321324
0315EE6B210CDBDD00927F3F /* LoginReduxTests.swift in Sources */,
325+
038A5AB8210DCBB400C1E363 /* LoginViewControlerTests.swift in Sources */,
322326
);
323327
runOnlyForDeploymentPostprocessing = 0;
324328
};

LoginRedux/Base.lproj/Main.storyboard

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<!--Login View Controller-->
1313
<scene sceneID="tne-QT-ifu">
1414
<objects>
15-
<viewController id="BYZ-38-t0r" customClass="LoginViewController" customModule="LoginRedux" customModuleProvider="target" sceneMemberID="viewController">
15+
<viewController storyboardIdentifier="LoginViewController" id="BYZ-38-t0r" customClass="LoginViewController" customModule="LoginRedux" customModuleProvider="target" sceneMemberID="viewController">
1616
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1717
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1818
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>

LoginRedux/LoginViewController.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import ReSwift
1212
class LoginViewController: UIViewController {
1313

1414
// MARK:- Outlets
15-
@IBOutlet weak private var usernameTextField: UITextField!
16-
@IBOutlet weak private var usernameErrorLabel: UILabel!
17-
@IBOutlet weak private var passwordTextField: UITextField!
18-
@IBOutlet weak private var passwordErrorLabel: UILabel!
19-
@IBOutlet weak private var loginButton: UIButton!
20-
@IBOutlet weak private var loginErrorLabel: UILabel!
15+
@IBOutlet weak var usernameTextField: UITextField!
16+
@IBOutlet weak var usernameErrorLabel: UILabel!
17+
@IBOutlet weak var passwordTextField: UITextField!
18+
@IBOutlet weak var passwordErrorLabel: UILabel!
19+
@IBOutlet weak var loginButton: UIButton!
20+
@IBOutlet weak var loginErrorLabel: UILabel!
2121

2222
// MARK:- Properties
2323
let mainStore = Store<LoginState>(
@@ -101,6 +101,7 @@ extension LoginViewController: StoreSubscriber {
101101
passwordErrorLabel.text = state.passwordErrorText
102102
loginButton.isEnabled = state.loginButtonEnable
103103
loginErrorLabel.text = state.loginErrorText
104+
loginErrorLabel.isHidden = state.loginErrorHidden
104105
}
105106
}
106107

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)