Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions PowerHome.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -37,13 +41,17 @@

/* Begin PBXFileReference section */
ACCC0D4E20301DF10035F967 /* UISquareButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UISquareButton.swift; sourceTree = "<group>"; };
ACCC0D502030312B0035F967 /* SignUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = "<group>"; };
ACCC0D52203031410035F967 /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = "<group>"; };
ACCC0D54203031A70035F967 /* LoginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginTests.swift; sourceTree = "<group>"; };
ACCC0D56203031BB0035F967 /* SignUpTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpTests.swift; sourceTree = "<group>"; };
ACCC0D58203035F10035F967 /* BaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = "<group>"; };
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 = "<group>"; };
ACFC97C3202FA648004A3FE3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
ACFC97C6202FA648004A3FE3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
ACFC97C8202FA648004A3FE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
ACFC97D3202FA648004A3FE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -124,7 +132,8 @@
ACFC97D0202FA648004A3FE3 /* PowerHomeTests */ = {
isa = PBXGroup;
children = (
ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */,
ACCC0D56203031BB0035F967 /* SignUpTests.swift */,
ACCC0D54203031A70035F967 /* LoginTests.swift */,
ACFC97D3202FA648004A3FE3 /* Info.plist */,
);
path = PowerHomeTests;
Expand All @@ -143,6 +152,8 @@
isa = PBXGroup;
children = (
ACFC97EE202FCF9F004A3FE3 /* LoginView.swift */,
ACCC0D52203031410035F967 /* SignUpView.swift */,
ACCC0D58203035F10035F967 /* BaseView.swift */,
);
name = Views;
sourceTree = "<group>";
Expand All @@ -151,6 +162,7 @@
isa = PBXGroup;
children = (
ACFC97EA202FC889004A3FE3 /* LoginViewController.swift */,
ACCC0D502030312B0035F967 /* SignUpViewController.swift */,
);
name = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -296,19 +308,23 @@
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;
};
ACFC97C9202FA648004A3FE3 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
ACFC97D2202FA648004A3FE3 /* PowerHomeTests.swift in Sources */,
ACCC0D57203031BB0035F967 /* SignUpTests.swift in Sources */,
ACCC0D55203031A70035F967 /* LoginTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
34 changes: 34 additions & 0 deletions PowerHome/BaseView.swift
Original file line number Diff line number Diff line change
@@ -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
}

}
14 changes: 1 addition & 13 deletions PowerHome/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}

}
8 changes: 7 additions & 1 deletion PowerHome/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand All @@ -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)
}

}
129 changes: 129 additions & 0 deletions PowerHome/SignUpView.swift
Original file line number Diff line number Diff line change
@@ -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)
}

}
47 changes: 47 additions & 0 deletions PowerHome/SignUpViewController.swift
Original file line number Diff line number Diff line change
@@ -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)
}

}
Original file line number Diff line number Diff line change
@@ -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()))!)
}

}
Loading