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

[NT-635] CTA fix button navigation #1027

Merged
merged 4 commits into from
Jan 13, 2020
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
8 changes: 8 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,8 @@
D6B9F90A22035840003282A5 /* Author.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B9F90922035840003282A5 /* Author.swift */; };
D6B9F943220358D1003282A5 /* AuthorTemplates.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B9F942220358D1003282A5 /* AuthorTemplates.swift */; };
D6B9F94522035E34003282A5 /* AuthorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B9F94422035E34003282A5 /* AuthorTests.swift */; };
D6BD66BB23CCF79D008694BB /* Equatable+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BD66BA23CCF79D008694BB /* Equatable+Helpers.swift */; };
D6BD66BD23CCF7B6008694BB /* EquatableHelpersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BD66BC23CCF7B6008694BB /* EquatableHelpersTests.swift */; };
D6C3845B210B9AC400ADB671 /* SettingsNewslettersTopCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C38459210B9AC400ADB671 /* SettingsNewslettersTopCell.swift */; };
D6C3845C210B9AC400ADB671 /* SettingsNewslettersTopCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6C3845A210B9AC400ADB671 /* SettingsNewslettersTopCell.xib */; };
D6C9A20E1F755FE200981E64 /* GraphSchemaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C9A20D1F755FE200981E64 /* GraphSchemaTests.swift */; };
Expand Down Expand Up @@ -2541,6 +2543,8 @@
D6B9F942220358D1003282A5 /* AuthorTemplates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorTemplates.swift; sourceTree = "<group>"; };
D6B9F94422035E34003282A5 /* AuthorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorTests.swift; sourceTree = "<group>"; };
D6B9FA1422089C05003282A5 /* SelectCurrencyViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectCurrencyViewControllerTests.swift; sourceTree = "<group>"; };
D6BD66BA23CCF79D008694BB /* Equatable+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Equatable+Helpers.swift"; sourceTree = "<group>"; };
D6BD66BC23CCF7B6008694BB /* EquatableHelpersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EquatableHelpersTests.swift; sourceTree = "<group>"; };
D6C38459210B9AC400ADB671 /* SettingsNewslettersTopCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsNewslettersTopCell.swift; sourceTree = "<group>"; };
D6C3845A210B9AC400ADB671 /* SettingsNewslettersTopCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsNewslettersTopCell.xib; sourceTree = "<group>"; };
D6C9A20D1F755FE200981E64 /* GraphSchemaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphSchemaTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3258,6 +3262,8 @@
7703B42123217D4F00169EF3 /* EnvironmentType.swift */,
3705CF0E222EE7670025D37E /* EnvironmentVariables.swift */,
3705CF47222EE77E0025D37E /* EnvironmentVariablesTests.swift */,
D6BD66BA23CCF79D008694BB /* Equatable+Helpers.swift */,
D6BD66BC23CCF7B6008694BB /* EquatableHelpersTests.swift */,
A72C3A8A1D00F6A80075227E /* ExpandableRow.swift */,
77556F1C20A09993008CEA57 /* ExperimentName+Helpers.swift */,
D667C2BB2305F03300EC094A /* ExperimentName+HelpersTests.swift */,
Expand Down Expand Up @@ -4847,6 +4853,7 @@
D69C552B239EFA6C00B0987A /* ActivityErroredBackingsCellViewModel.swift in Sources */,
A7F441CB1D005A9400FE6FC5 /* MessagesSearchViewModel.swift in Sources */,
A7CC14651D00E81B00035C52 /* FriendsSource.swift in Sources */,
D6BD66BB23CCF79D008694BB /* Equatable+Helpers.swift in Sources */,
3706408622A8A6D700889CBD /* PledgeShippingLocationViewModel.swift in Sources */,
3757D0CE228E51F800241AE6 /* UIFont.swift in Sources */,
778F891C22D3E37300D095C5 /* Feature+Helpers.swift in Sources */,
Expand Down Expand Up @@ -5061,6 +5068,7 @@
A7ED1FE41E831C5C00BFFA01 /* EmptyStatesViewModelTests.swift in Sources */,
D04AACA8218BB72100CF713E /* FindFriendsCellViewModelTests.swift in Sources */,
8AA524932384CAC100FD52CF /* EditorialProjectsViewModelTests.swift in Sources */,
D6BD66BD23CCF7B6008694BB /* EquatableHelpersTests.swift in Sources */,
D04AACA6218BB72100CF713E /* ChangePasswordViewModelTests.swift in Sources */,
8A213CF5239EAF5600BBB4C7 /* TrackingClientConfigurationTests.swift in Sources */,
77E023D62305E02C00C63444 /* PKPaymentAuthorizationViewControllerHelpersTests.swift in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions Library/Equatable+Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

extension Equatable {
func isAny(of elements: Self...) -> Bool {
return elements.contains(self)
}
}
9 changes: 9 additions & 0 deletions Library/EquatableHelpersTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@testable import Library
import XCTest

final class EquatableHelpersTests: TestCase {
func testIsAnyOf() {
XCTAssertTrue("one".isAny(of: "one", "two", "three"))
XCTAssertFalse("five".isAny(of: "one", "two", "three"))
}
}
6 changes: 5 additions & 1 deletion Library/ViewModels/ProjectPamphletViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public final class ProjectPamphletViewModel: ProjectPamphletViewModelType, Proje
.filter(featureNativeCheckoutPledgeViewIsEnabled >>> isFalse)

let shouldGoToManagePledge = ctaButtonTappedWithType
.filter { $0 == .viewBacking || $0 == .manage }
.filter(shouldGoToManagePledge(with:))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler didn't let me simply add $0 == .fix here, so I had to extract the logic to a separated function.

.ignoreValues()
.filter(featureNativeCheckoutPledgeViewIsEnabled)

Expand Down Expand Up @@ -356,3 +356,7 @@ private func fetchProject(projectOrParam: Either<Project, Param>, shouldPrefix:

return projectProducer
}

private func shouldGoToManagePledge(with type: PledgeStateCTAType) -> Bool {
return type.isAny(of: .viewBacking, .manage, .fix)
}
55 changes: 43 additions & 12 deletions Library/ViewModels/ProjectPamphletViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,40 @@ final class ProjectPamphletViewModelTests: TestCase {
}
}

func testGoToManageViewPledge_ManagingPledge_FeatureNativeCheckoutPledgeView_Enabled() {
func testGoToDeprecatedManagePledge_ManagingPledge_featureNativeCheckoutPledgeView_Disabled() {
let config = .template
|> Config.lens.features .~ [Feature.nativeCheckoutPledgeView.rawValue: false]

withEnvironment(config: config) {
let reward = Project.cosmicSurgery.rewards.first!
let backing = Backing.template
|> Backing.lens.reward .~ reward
|> Backing.lens.rewardId .~ reward.id

let project = Project.cosmicSurgery
|> Project.lens.personalization.backing .~ backing
|> Project.lens.personalization.isBacking .~ true

self.configureInitialState(.left(project))

self.goToDeprecatedManagePledgeProject.assertDidNotEmitValue()
self.goToDeprecatedManagePledgeReward.assertDidNotEmitValue()
self.goToDeprecatedManagePledgeRefTag.assertDidNotEmitValue()

self.vm.inputs.pledgeCTAButtonTapped(with: .manage)

self.goToDeprecatedManagePledgeProject.assertValues([project])
self.goToDeprecatedManagePledgeReward.assertValues([project.rewards[0]])
self.goToDeprecatedManagePledgeRefTag.assertValues([.discovery])

self.goToManageViewPledge.assertDidNotEmitValue()

self.goToDeprecatedViewBackingUser.assertDidNotEmitValue()
self.goToDeprecatedViewBackingProject.assertDidNotEmitValue()
}
}

func testGoToManageViewPledge_FixingPledge_FeatureNativeCheckoutPledgeView_Enabled() {
let config = .template
|> Config.lens.features .~ [Feature.nativeCheckoutPledgeView.rawValue: true]

Expand All @@ -433,7 +466,7 @@ final class ProjectPamphletViewModelTests: TestCase {

self.goToManageViewPledge.assertDidNotEmitValue()

self.vm.inputs.pledgeCTAButtonTapped(with: .manage)
self.vm.inputs.pledgeCTAButtonTapped(with: .fix)

self.goToManageViewPledge.assertValues([project])

Expand All @@ -446,9 +479,9 @@ final class ProjectPamphletViewModelTests: TestCase {
}
}

func testGoToDeprecatedManagePledge_ManagingPledge_featureNativeCheckoutPledgeView_Disabled() {
func testGoToManageViewPledge_ManagingPledge_FeatureNativeCheckoutPledgeView_Enabled() {
let config = .template
|> Config.lens.features .~ [Feature.nativeCheckoutPledgeView.rawValue: false]
|> Config.lens.features .~ [Feature.nativeCheckoutPledgeView.rawValue: true]

withEnvironment(config: config) {
let reward = Project.cosmicSurgery.rewards.first!
Expand All @@ -462,20 +495,18 @@ final class ProjectPamphletViewModelTests: TestCase {

self.configureInitialState(.left(project))

self.goToDeprecatedManagePledgeProject.assertDidNotEmitValue()
self.goToDeprecatedManagePledgeReward.assertDidNotEmitValue()
self.goToDeprecatedManagePledgeRefTag.assertDidNotEmitValue()
self.goToManageViewPledge.assertDidNotEmitValue()

self.vm.inputs.pledgeCTAButtonTapped(with: .manage)

self.goToDeprecatedManagePledgeProject.assertValues([project])
self.goToDeprecatedManagePledgeReward.assertValues([project.rewards[0]])
self.goToDeprecatedManagePledgeRefTag.assertValues([.discovery])

self.goToManageViewPledge.assertDidNotEmitValue()
self.goToManageViewPledge.assertValues([project])

self.goToDeprecatedViewBackingUser.assertDidNotEmitValue()
self.goToDeprecatedViewBackingProject.assertDidNotEmitValue()

self.goToDeprecatedManagePledgeProject.assertDidNotEmitValue()
self.goToDeprecatedManagePledgeReward.assertDidNotEmitValue()
self.goToDeprecatedManagePledgeRefTag.assertDidNotEmitValue()
}
}

Expand Down