Skip to content

Commit

Permalink
Fix text replacement on return (#460)
Browse files Browse the repository at this point in the history
* Fix text replacement on return
Fix #427

* Added InputField delegate tests
  • Loading branch information
cocojoe authored Sep 11, 2017
1 parent 16563d9 commit a07efbb
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 27 deletions.
12 changes: 12 additions & 0 deletions Lock.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
5B568F801E4B64D2004B3D98 /* Passwordless.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B568F7F1E4B64D2004B3D98 /* Passwordless.swift */; };
5B568F821E4B6506004B3D98 /* PasswordlessAuthenticatableError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B568F811E4B6506004B3D98 /* PasswordlessAuthenticatableError.swift */; };
5B5F9F9F1E4B3FBE00EAB9EE /* PasswordlessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B5F9F9E1E4B3FBE00EAB9EE /* PasswordlessView.swift */; };
5B64AC4F1F668CD0000A8842 /* InputFieldSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B64AC4D1F668B18000A8842 /* InputFieldSpec.swift */; };
5B6E02C01EA77B4E00B28579 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6E02BF1EA77B4E00B28579 /* Extensions.swift */; };
5B889AEE1E700FCA00C9FBAF /* CountryCodes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B889AED1E700FCA00C9FBAF /* CountryCodes.swift */; };
5B8B795B1E8BAE5E00D0C57E /* passwordless_country_codes.plist in Resources */ = {isa = PBXBuildFile; fileRef = 5B8B795A1E8BAE5E00D0C57E /* passwordless_country_codes.plist */; };
Expand Down Expand Up @@ -269,6 +270,7 @@
5B568F7F1E4B64D2004B3D98 /* Passwordless.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Passwordless.swift; sourceTree = "<group>"; };
5B568F811E4B6506004B3D98 /* PasswordlessAuthenticatableError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordlessAuthenticatableError.swift; sourceTree = "<group>"; };
5B5F9F9E1E4B3FBE00EAB9EE /* PasswordlessView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordlessView.swift; sourceTree = "<group>"; };
5B64AC4D1F668B18000A8842 /* InputFieldSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputFieldSpec.swift; sourceTree = "<group>"; };
5B6631511DDB990B001CB043 /* EnterpriseDomainInteractorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnterpriseDomainInteractorSpec.swift; sourceTree = "<group>"; };
5B6E02BF1EA77B4E00B28579 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
5B889AED1E700FCA00C9FBAF /* CountryCodes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryCodes.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -493,6 +495,14 @@
name = Extension;
sourceTree = "<group>";
};
5B64AC4C1F668AF5000A8842 /* Components */ = {
isa = PBXGroup;
children = (
5B64AC4D1F668B18000A8842 /* InputFieldSpec.swift */,
);
name = Components;
sourceTree = "<group>";
};
5B94D5AC1E8E6AF400E9D4F1 /* Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -800,6 +810,7 @@
5FEAE1D41D1A5154005C0028 /* LockTests */ = {
isa = PBXGroup;
children = (
5B64AC4C1F668AF5000A8842 /* Components */,
5F9231D31D5B6C2800D92580 /* Views */,
5F508FF81D1DB01D00EAA650 /* Interactors */,
5FBE5CCB1D3ED9210038536D /* Models */,
Expand Down Expand Up @@ -1280,6 +1291,7 @@
5FBE5CC21D3E5EF50038536D /* MultifactorInteractorSpec.swift in Sources */,
5B3874D51E97C14000244326 /* PolicyViewSpec.swift in Sources */,
5B1FD9721E546F500055C1AC /* PasswordlessInteractorSpec.swift in Sources */,
5B64AC4F1F668CD0000A8842 /* InputFieldSpec.swift in Sources */,
5F73CDDE1D30B16900D8D8D1 /* DatabaseForgotPasswordPresenterSpec.swift in Sources */,
5BB142EF1E97C2F300315607 /* LockViewControllerSpec.swift in Sources */,
5F9231D51D5B6C5E00D92580 /* AuthCollectionViewSpec.swift in Sources */,
Expand Down
53 changes: 29 additions & 24 deletions Lock/InputField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import UIKit

class InputField: UIView, UITextFieldDelegate, Stylable {
class InputField: UIView, Stylable {

weak var containerView: UIView?
weak var textField: UITextField?
Expand Down Expand Up @@ -246,28 +246,6 @@ class InputField: UIView, UITextFieldDelegate, Stylable {
}
}

func textFieldDidBeginEditing(_ textField: UITextField) {
self.onBeginEditing(self)
}

func textFieldDidEndEditing(_ textField: UITextField) {
self.onEndEditing(self)
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.onReturn(self)
if let field = self.nextField?.textField {
Queue.main.async {
field.becomeFirstResponder()
}
} else {
Queue.main.async {
textField.resignFirstResponder()
}
}
return true
}

func textChanged(_ field: UITextField) {
self.onTextChange(self)
}
Expand Down Expand Up @@ -361,7 +339,6 @@ class InputField: UIView, UITextFieldDelegate, Stylable {
}

// MARK: - Styable

func apply(style: Style) {
self.borderColor = style.inputBorderColor
self.borderColorError = style.inputBorderColorError
Expand All @@ -375,3 +352,31 @@ class InputField: UIView, UITextFieldDelegate, Stylable {
self.iconView?.tintColor = style.inputIconColor
}
}

// MARK: - UITextFieldDelegate
extension InputField: UITextFieldDelegate {

func textFieldDidBeginEditing(_ textField: UITextField) {
self.onBeginEditing(self)
}

func textFieldDidEndEditing(_ textField: UITextField) {
self.onEndEditing(self)
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.onTextChange(self)
self.onReturn(self)
if let field = self.nextField?.textField {
Queue.main.async {
field.becomeFirstResponder()
}
} else {
Queue.main.async {
textField.resignFirstResponder()
}
}
return true
}

}
84 changes: 84 additions & 0 deletions LockTests/InputFieldSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// InputFieldSpec.swift
//
// Copyright (c) 2016 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Quick
import Nimble
@testable import Lock

class InputFieldSpec: QuickSpec {

override func spec() {

describe("delegate") {

var input: InputField!
var text: UITextField!
var didTextChange: Bool!
var didReturn: Bool!
var didBegin: Bool!
var didEnd: Bool!

beforeEach {
didTextChange = false
didReturn = false
didBegin = false
didEnd = false
input = InputField()
input.onReturn = { _ in didReturn = true }
input.onTextChange = { _ in didTextChange = true }
input.onBeginEditing = { _ in didBegin = true }
input.onEndEditing = { _ in didEnd = true }
text = UITextField()
text.text = "test"
}

describe("delegate") {

it("on return editing called") {
expect(input.textFieldShouldReturn(text)).to(beTrue())
expect(didReturn).to(beTrue())
expect(didTextChange).to(beTrue())
}

it("on begin editing called") {
input.textFieldDidBeginEditing(text)
expect(didBegin).to(beTrue())
}

it("on end editing called") {
input.textFieldDidEndEditing(text)
expect(didEnd).to(beTrue())
}
}

describe("text change") {

it("text updated") {
input.textChanged(text)
expect(didTextChange).to(beTrue())
}

}

}
}
}
4 changes: 2 additions & 2 deletions LockTests/Interactors/PasswordlessInteractorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class PasswordlessInteractorSpec: QuickSpec {
}

it("should have empty passwordless transcation store") {
expect(passwordlessActivity.current).to(beNil())
expect(passwordlessActivity.current).toEventually(beNil())
}

it("should store passwordless transaction on sending link") {
Expand All @@ -268,7 +268,7 @@ class PasswordlessInteractorSpec: QuickSpec {
done()
}
}
expect(passwordlessActivity.current).toNot(beNil())
expect(passwordlessActivity.current).toEventuallyNot(beNil())
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ By default a show password icon is shown in password fields to toggle visibility

Auth0 helps you to:

* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amongst others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
* Add support for [Custom OAuth2 Connections](https://auth0.com/docs/connections/social/oauth2).
* Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
* Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
Expand Down

0 comments on commit a07efbb

Please sign in to comment.