Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
fix for recurring web address launch from app (#932)
Browse files Browse the repository at this point in the history
* fix + tests

* comment
  • Loading branch information
sashei authored Apr 26, 2019
1 parent 0007afa commit 97e80d7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
3 changes: 3 additions & 0 deletions lockbox-ios/Presenter/ItemDetailPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class ItemDetailPresenter {
target.itemDetailStore.itemDetailId
.take(1)
.flatMap { target.dataStore.get($0) }
// The first `take(1)` call does not push a completion after it emits, so a second one is necessary here
// to ensure that subsequent updates to the item do not result in subsequent dispacthed actions.
.take(1)
.map { item -> [Action] in
var actions: [Action] = []
if copyableFields.contains(value) {
Expand Down
57 changes: 33 additions & 24 deletions lockbox-iosTests/ItemDetailPresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class ItemDetailPresenterSpec: QuickSpec {
}

class FakeDispatcher: Dispatcher {
var dispatchActionArgument: Action?
var dispatchActionArgument: [Action] = []

override func dispatch(action: Action) {
self.dispatchActionArgument = action
self.dispatchActionArgument.append(action)
}
}

Expand Down Expand Up @@ -134,8 +134,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("starts the password display as hidden") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! ItemDetailDisplayAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.first as! ItemDetailDisplayAction
expect(action).to(equal(.togglePassword(displayed: false)))
}

Expand All @@ -152,8 +152,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("dispatches the password action with the value") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! ItemDetailDisplayAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.last as! ItemDetailDisplayAction
expect(action).to(equal(.togglePassword(displayed: passwordRevealSelected)))
}
}
Expand All @@ -170,8 +170,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("routes to the item list") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let argument = self.dispatcher.dispatchActionArgument as! MainRouteAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let argument = self.dispatcher.dispatchActionArgument.last as! MainRouteAction
expect(argument).to(equal(.list))
}
}
Expand Down Expand Up @@ -203,8 +203,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("dispatches the copy action") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! CopyAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.last as! CopyAction
expect(action).to(equal(CopyAction(text: username, field: .username, itemID: "", actionType: .tap)))
}
}
Expand All @@ -216,8 +216,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("dispatches the copy action with no text") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! CopyAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.last as! CopyAction
expect(action).to(equal(CopyAction(text: "", field: .username, itemID: "", actionType: .tap)))
}
}
Expand Down Expand Up @@ -250,8 +250,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("dispatches the copy action") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! CopyAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.last as! CopyAction
expect(action).to(equal(CopyAction(text: password, field: .password, itemID: "", actionType: .tap)))
}
}
Expand All @@ -263,8 +263,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("dispatches the copy action with no text") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! CopyAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.last as! CopyAction
expect(action).to(equal(CopyAction(text: "", field: .password, itemID: "", actionType: .tap)))
}
}
Expand All @@ -289,18 +289,27 @@ class ItemDetailPresenterSpec: QuickSpec {

describe("getting the item") {
let webAddress = "https://www.mozilla.org"
let item = LoginRecord(fromJSONDict: ["id": "sdfdfsfd", "hostname": webAddress, "username": "ffs", "password": "ilikecatz"])

beforeEach {
let item = LoginRecord(fromJSONDict: ["id": "sdfdfsfd", "hostname": webAddress, "username": "ffs", "password": "ilikecatz"])

self.dataStore.onItemStub.onNext(item)
}

it("dispatches the externalLink action") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! ExternalLinkAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.last as! ExternalLinkAction
expect(action).to(equal(ExternalLinkAction(baseURLString: webAddress)))
}

describe("subsequent pushes of the same item") {
beforeEach {
self.dataStore.onItemStub.onNext(item)
}

it("dispatches nothing new") {
expect(self.dispatcher.dispatchActionArgument.count).to(equal(2))
}
}
}
}

Expand Down Expand Up @@ -488,8 +497,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("dispatches the faq link action") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let argument = self.dispatcher.dispatchActionArgument as! ExternalWebsiteRouteAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let argument = self.dispatcher.dispatchActionArgument.last as! ExternalWebsiteRouteAction
expect(argument).to(equal(
ExternalWebsiteRouteAction(
urlString: Constant.app.editExistingEntriesFAQ,
Expand Down Expand Up @@ -524,8 +533,8 @@ class ItemDetailPresenterSpec: QuickSpec {
}

it("sends copy action") {
expect(self.dispatcher.dispatchActionArgument).notTo(beNil())
let action = self.dispatcher.dispatchActionArgument as! CopyAction
expect(self.dispatcher.dispatchActionArgument).notTo(beEmpty())
let action = self.dispatcher.dispatchActionArgument.last as! CopyAction
expect(action).to(equal(CopyAction(text: "asdf", field: CopyField.username, itemID: "1234", actionType: CopyActionType.dnd)))
}
}
Expand Down

0 comments on commit 97e80d7

Please sign in to comment.