diff --git a/PowerHome.xcodeproj/project.pbxproj b/PowerHome.xcodeproj/project.pbxproj index b88350a..a1f51a2 100644 --- a/PowerHome.xcodeproj/project.pbxproj +++ b/PowerHome.xcodeproj/project.pbxproj @@ -8,10 +8,14 @@ /* Begin PBXBuildFile section */ ACCC0D4F20301DF10035F967 /* UISquareButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D4E20301DF10035F967 /* UISquareButton.swift */; }; + ACCC0D512030312B0035F967 /* SignUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D502030312B0035F967 /* SignUpViewController.swift */; }; + ACCC0D53203031410035F967 /* SignUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D52203031410035F967 /* SignUpView.swift */; }; + ACCC0D55203031A70035F967 /* LoginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D54203031A70035F967 /* LoginTests.swift */; }; + ACCC0D57203031BB0035F967 /* SignUpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D56203031BB0035F967 /* SignUpTests.swift */; }; + ACCC0D59203035F10035F967 /* BaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D58203035F10035F967 /* BaseView.swift */; }; ACFC97BD202FA648004A3FE3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97BC202FA648004A3FE3 /* AppDelegate.swift */; }; ACFC97C4202FA648004A3FE3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C3202FA648004A3FE3 /* Assets.xcassets */; }; ACFC97C7202FA648004A3FE3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C5202FA648004A3FE3 /* LaunchScreen.storyboard */; }; - ACFC97D2202FA648004A3FE3 /* PowerHomeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */; }; ACFC97DD202FA649004A3FE3 /* PowerHomeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97DC202FA649004A3FE3 /* PowerHomeUITests.swift */; }; ACFC97EB202FC889004A3FE3 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97EA202FC889004A3FE3 /* LoginViewController.swift */; }; ACFC97EF202FCF9F004A3FE3 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97EE202FCF9F004A3FE3 /* LoginView.swift */; }; @@ -37,13 +41,17 @@ /* Begin PBXFileReference section */ ACCC0D4E20301DF10035F967 /* UISquareButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UISquareButton.swift; sourceTree = ""; }; + ACCC0D502030312B0035F967 /* SignUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; + ACCC0D52203031410035F967 /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = ""; }; + ACCC0D54203031A70035F967 /* LoginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginTests.swift; sourceTree = ""; }; + ACCC0D56203031BB0035F967 /* SignUpTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpTests.swift; sourceTree = ""; }; + ACCC0D58203035F10035F967 /* BaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = ""; }; ACFC97B9202FA648004A3FE3 /* PowerHome.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PowerHome.app; sourceTree = BUILT_PRODUCTS_DIR; }; ACFC97BC202FA648004A3FE3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; ACFC97C3202FA648004A3FE3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; ACFC97C6202FA648004A3FE3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; ACFC97C8202FA648004A3FE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; ACFC97CD202FA648004A3FE3 /* PowerHomeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PowerHomeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowerHomeTests.swift; sourceTree = ""; }; ACFC97D3202FA648004A3FE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; ACFC97D8202FA649004A3FE3 /* PowerHomeUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PowerHomeUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; ACFC97DC202FA649004A3FE3 /* PowerHomeUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowerHomeUITests.swift; sourceTree = ""; }; @@ -124,7 +132,8 @@ ACFC97D0202FA648004A3FE3 /* PowerHomeTests */ = { isa = PBXGroup; children = ( - ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */, + ACCC0D56203031BB0035F967 /* SignUpTests.swift */, + ACCC0D54203031A70035F967 /* LoginTests.swift */, ACFC97D3202FA648004A3FE3 /* Info.plist */, ); path = PowerHomeTests; @@ -143,6 +152,8 @@ isa = PBXGroup; children = ( ACFC97EE202FCF9F004A3FE3 /* LoginView.swift */, + ACCC0D52203031410035F967 /* SignUpView.swift */, + ACCC0D58203035F10035F967 /* BaseView.swift */, ); name = Views; sourceTree = ""; @@ -151,6 +162,7 @@ isa = PBXGroup; children = ( ACFC97EA202FC889004A3FE3 /* LoginViewController.swift */, + ACCC0D502030312B0035F967 /* SignUpViewController.swift */, ); name = Controllers; sourceTree = ""; @@ -296,11 +308,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + ACCC0D512030312B0035F967 /* SignUpViewController.swift in Sources */, ACFC97EF202FCF9F004A3FE3 /* LoginView.swift in Sources */, ACFC97F2202FD0CD004A3FE3 /* Colors.swift in Sources */, + ACCC0D53203031410035F967 /* SignUpView.swift in Sources */, ACFC97EB202FC889004A3FE3 /* LoginViewController.swift in Sources */, ACFC97BD202FA648004A3FE3 /* AppDelegate.swift in Sources */, ACCC0D4F20301DF10035F967 /* UISquareButton.swift in Sources */, + ACCC0D59203035F10035F967 /* BaseView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -308,7 +323,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - ACFC97D2202FA648004A3FE3 /* PowerHomeTests.swift in Sources */, + ACCC0D57203031BB0035F967 /* SignUpTests.swift in Sources */, + ACCC0D55203031A70035F967 /* LoginTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PowerHome/BaseView.swift b/PowerHome/BaseView.swift new file mode 100644 index 0000000..292ba76 --- /dev/null +++ b/PowerHome/BaseView.swift @@ -0,0 +1,34 @@ +// +// BaseView.swift +// PowerHome +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import UIKit + +class BaseView: UIView { + + override init(frame: CGRect) { + super.init(frame: frame) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + +} + +extension BaseView: UITextFieldDelegate { + + @objc func dismissKeyboard(_ sender: Any) { + endEditing(true) + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + dismissKeyboard(Any.self) + return true + } + +} diff --git a/PowerHome/LoginView.swift b/PowerHome/LoginView.swift index f0ff813..3db9cd5 100644 --- a/PowerHome/LoginView.swift +++ b/PowerHome/LoginView.swift @@ -9,7 +9,7 @@ import UIKit /// Login view to be used in -class LoginView: UIView { +class LoginView: BaseView { lazy var usernameLabel: UILabel = { let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) @@ -158,17 +158,5 @@ extension LoginView { addConstraints(signUpButtonEqualWidthsToUsernameLabelConstraints) addConstraints([loginButtonHeightConstraint, signUpButtonHeighConstraint]) } -} - -extension LoginView: UITextFieldDelegate { - - @objc func dismissKeyboard(_ sender: Any) { - endEditing(true) - } - - func textFieldShouldReturn(_ textField: UITextField) -> Bool { - dismissKeyboard(Any.self) - return true - } } diff --git a/PowerHome/LoginViewController.swift b/PowerHome/LoginViewController.swift index f115d69..203ec87 100644 --- a/PowerHome/LoginViewController.swift +++ b/PowerHome/LoginViewController.swift @@ -16,8 +16,9 @@ class LoginViewController: UIViewController { super.viewDidLoad() view.backgroundColor = .white - view.addSubview(loginView) + + loginView.signUpButton.addTarget(self, action: #selector(showSignUp), for: .touchUpInside) // Do any additional setup after loading the view. } @@ -31,4 +32,9 @@ class LoginViewController: UIViewController { view.addConstraints(loginViewHorizontalConstraints) } + @objc func showSignUp() { + let navigationController: UINavigationController = UINavigationController(rootViewController: SignUpViewController()) + present(navigationController, animated: true, completion: nil) + } + } diff --git a/PowerHome/SignUpView.swift b/PowerHome/SignUpView.swift new file mode 100644 index 0000000..88bc586 --- /dev/null +++ b/PowerHome/SignUpView.swift @@ -0,0 +1,129 @@ +// +// SignUpView.swift +// PowerHome +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import UIKit + +class SignUpView: BaseView { + + lazy var nameLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Name" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var emailLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Email" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var passwordLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Password" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var passwordConfirmationLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Password" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var nameTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.placeholder = "First Name and Last Name" + textField.autocorrectionType = .no + textField.keyboardType = .default + textField.autocapitalizationType = .words + textField.borderStyle = .roundedRect + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var emailTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.placeholder = "Email" + textField.autocorrectionType = .no + textField.keyboardType = .emailAddress + textField.autocapitalizationType = .none + textField.borderStyle = .roundedRect + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var passwordTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.autocorrectionType = .no + textField.autocapitalizationType = .none + textField.borderStyle = .roundedRect + textField.isSecureTextEntry = true + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var passwordConfirmationTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.autocorrectionType = .no + textField.autocapitalizationType = .none + textField.borderStyle = .roundedRect + textField.isSecureTextEntry = true + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var signUpButton: UISquareButton = { + let button: UISquareButton = UISquareButton(buttonType: .system) + button.translatesAutoresizingMaskIntoConstraints = false + button.setTitle("Sign Up", for: .normal) + return button + }() + + override init(frame: CGRect) { + super.init(frame: frame) + + backgroundColor = .white + translatesAutoresizingMaskIntoConstraints = false + addSubview(nameLabel) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + +} + +// MARK: - AutoLayout +extension SignUpView { + + override func updateConstraints() { + super.updateConstraints() + + let nameLabelHorizontalConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "H:|-15-[nameLabel]-15-|", options: .alignAllBottom, metrics: nil, views: ["nameLabel": nameLabel]) + let verticalSpacingConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "V:|-15-[nameLabel]", options: .alignAllLeading, metrics: nil, views: ["nameLabel": nameLabel]) + + addConstraints(nameLabelHorizontalConstraints) + addConstraints(verticalSpacingConstraints) + } + +} diff --git a/PowerHome/SignUpViewController.swift b/PowerHome/SignUpViewController.swift new file mode 100644 index 0000000..f6f0fcb --- /dev/null +++ b/PowerHome/SignUpViewController.swift @@ -0,0 +1,47 @@ +// +// SignUpViewController.swift +// PowerHome +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import UIKit + +class SignUpViewController: UIViewController { + + let signUpView: SignUpView = SignUpView() + lazy var cancelBarButton: UIBarButtonItem = { + let cancelButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(dismiss(_:))) + return cancelButton + }() + + override func viewDidLoad() { + super.viewDidLoad() + + viewRespectsSystemMinimumLayoutMargins = false + navigationItem.leftBarButtonItem = cancelBarButton + navigationItem.title = "Sign Up" + view.addSubview(signUpView) + // Do any additional setup after loading the view. + } + + override func viewWillLayoutSubviews() { + super.viewWillLayoutSubviews() + + let signUpViewHorizontalConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "H:|-[view]-|", options: .alignAllCenterX, metrics: nil, views: ["view": signUpView]) + let signUpVerticalConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[view]-|", options: .alignAllCenterY, metrics: nil, views: ["view": signUpView]) + + view.addConstraints(signUpVerticalConstraints) + view.addConstraints(signUpViewHorizontalConstraints) + } + +} + +extension SignUpViewController { + + @objc func dismiss(_ sender: UIBarButtonItem) { + dismiss(animated: true, completion: nil) + } + +} diff --git a/PowerHomeTests/PowerHomeTests.swift b/PowerHomeTests/LoginTests.swift similarity index 54% rename from PowerHomeTests/PowerHomeTests.swift rename to PowerHomeTests/LoginTests.swift index 27a50d6..d7cb001 100644 --- a/PowerHomeTests/PowerHomeTests.swift +++ b/PowerHomeTests/LoginTests.swift @@ -1,33 +1,43 @@ // -// PowerHomeTests.swift +// LoginTests.swift // PowerHomeTests // -// Created by Francisco Javier Chacon de Dios on 10/02/18. +// Created by Francisco Javier Chacon de Dios on 11/02/18. // Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. // import XCTest @testable import PowerHome -class PowerHomeTests: XCTestCase { +class LoginTests: XCTestCase { var loginViewController: LoginViewController? override func setUp() { super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. loginViewController = LoginViewController() _ = loginViewController?.view + // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() + loginViewController = nil } - func testViewControllerInitializesProperly() { + func loginViewControllerInitializesProperly() { + loginViewController?.loginView.dismissKeyboard(Any.self) XCTAssertNotNil(loginViewController) } + func testConformsUITextFieldDelegateProtocolShouldBeTrue() { + XCTAssert((loginViewController?.loginView.conforms(to: UITextFieldDelegate.self))!) + } + + func testTextFieldShouldReturnTrueValue() { + XCTAssert((loginViewController?.loginView.textFieldShouldReturn(UITextField()))!) + } + } diff --git a/PowerHomeTests/SignUpTests.swift b/PowerHomeTests/SignUpTests.swift new file mode 100644 index 0000000..cf27375 --- /dev/null +++ b/PowerHomeTests/SignUpTests.swift @@ -0,0 +1,35 @@ +// +// SignUpTests.swift +// PowerHomeTests +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import XCTest + +class SignUpTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +}