Skip to content

Commit

Permalink
Fix self retain cycle in DatabaseView (#463)
Browse files Browse the repository at this point in the history
* Fix self retain cycle in DatabaseView

* Added Tests
  • Loading branch information
cocojoe authored Sep 13, 2017
1 parent 6c8b8ea commit 04087df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Lock/DatabaseOnlyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DatabaseOnlyView: UIView, DatabaseView {
self.passwordManagerButton = form.passwordField.addFieldButton(withIcon: "ic_onepassword", color: Style.Auth0.onePasswordIconColor)
} else if showPassword, let passwordInput = form.passwordField.textField {
self.showPasswordButton = form.passwordField.addFieldButton(withIcon: "ic_show_password_hidden", color: Style.Auth0.inputIconColor)
self.showPasswordButton?.onPress = { button in
self.showPasswordButton?.onPress = { [unowned self] button in
passwordInput.isSecureTextEntry = !passwordInput.isSecureTextEntry
button.icon = LazyImage(name: passwordInput.isSecureTextEntry ? "ic_show_password_hidden" : "ic_show_password_visible", bundle: Lock.bundle).image(compatibleWithTraits: self.traitCollection)
}
Expand Down Expand Up @@ -171,7 +171,7 @@ class DatabaseOnlyView: UIView, DatabaseView {
self.passwordManagerButton = form.passwordField.addFieldButton(withIcon: "ic_onepassword", color: Style.Auth0.onePasswordIconColor)
} else if showPassword, let passwordInput = form.passwordField.textField {
self.showPasswordButton = form.passwordField.addFieldButton(withIcon: "ic_show_password_hidden", color: Style.Auth0.inputIconColor)
self.showPasswordButton?.onPress = { button in
self.showPasswordButton?.onPress = { [unowned self] button in
passwordInput.isSecureTextEntry = !passwordInput.isSecureTextEntry
button.icon = LazyImage(name: passwordInput.isSecureTextEntry ? "ic_show_password_hidden" : "ic_show_password_visible", bundle: Lock.bundle).image(compatibleWithTraits: self.traitCollection)
}
Expand Down
44 changes: 30 additions & 14 deletions LockTests/Presenters/DatabasePresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ class DatabasePresenterSpec: QuickSpec {
expect(view.passwordManagerButton).to(beNil())
}

it("should have show password button") {
expect(view.showPasswordButton).toNot(beNil())
}

context("with password manager available") {

beforeEach {
Expand All @@ -237,6 +241,10 @@ class DatabasePresenterSpec: QuickSpec {
view = presenter.view as! DatabaseOnlyView
expect(view.passwordManagerButton).to(beNil())
}

it("should not have show password button") {
expect(view.showPasswordButton).to(beNil())
}
}

describe("user input") {
Expand Down Expand Up @@ -293,6 +301,12 @@ class DatabasePresenterSpec: QuickSpec {
expect(input.valid) == false
}

it("should toggle show password") {
expect(view.passwordField?.textField?.isSecureTextEntry).to(beTrue())
view.showPasswordButton?.onPress(view.showPasswordButton!)
expect(view.passwordField?.textField?.isSecureTextEntry).to(beFalse())
}

}

// MARK:- Log In
Expand Down Expand Up @@ -445,6 +459,10 @@ class DatabasePresenterSpec: QuickSpec {
expect(view.primaryButton?.title) == "SIGN UP"
}

it("should have show password button") {
expect(view.showPasswordButton).toNot(beNil())
}

describe("user input") {

it("should clear global message") {
Expand Down Expand Up @@ -504,6 +522,10 @@ class DatabasePresenterSpec: QuickSpec {
expect(view.passwordManagerButton).to(beNil())
}

it("should not show password manager when disabled") {
expect(view.passwordManagerButton).to(beNil())
}

context("with password manager available") {

beforeEach {
Expand All @@ -517,23 +539,17 @@ class DatabasePresenterSpec: QuickSpec {
expect(view.passwordManagerButton).toNot(beNil())
}

context("disable password manager") {

beforeEach {
presenter.passwordManager = passwordManager
presenter.passwordManager.enabled = false
view = presenter.view as! DatabaseOnlyView
view.switcher?.selected = .signup
view.switcher?.onSelectionChange(view.switcher!)
}

it("should not show password manager when disabled") {
expect(view.passwordManagerButton).to(beNil())
}

it("should not have show password button") {
expect(view.showPasswordButton).to(beNil())
}
}

it("should toggle show password") {
expect(view.passwordField?.textField?.isSecureTextEntry).to(beTrue())
view.showPasswordButton?.onPress(view.showPasswordButton!)
expect(view.passwordField?.textField?.isSecureTextEntry).to(beFalse())
}

}

describe("sign up action") {
Expand Down

0 comments on commit 04087df

Please sign in to comment.