Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix self retain cycle in DatabaseView #463

Merged
merged 2 commits into from
Sep 13, 2017
Merged
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
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