From 94f779a21abb6d3a1cca70e75e7ba189397b15bd Mon Sep 17 00:00:00 2001 From: Nino Collaco Date: Fri, 10 Jan 2020 15:29:53 -0500 Subject: [PATCH 1/4] Fixed navigation from ProjectPage to ManagePledge with .fix state --- Library/ViewModels/ProjectPamphletViewModel.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/ViewModels/ProjectPamphletViewModel.swift b/Library/ViewModels/ProjectPamphletViewModel.swift index c46f330f5f..f907094883 100644 --- a/Library/ViewModels/ProjectPamphletViewModel.swift +++ b/Library/ViewModels/ProjectPamphletViewModel.swift @@ -127,7 +127,7 @@ public final class ProjectPamphletViewModel: ProjectPamphletViewModelType, Proje .filter(featureNativeCheckoutPledgeViewIsEnabled >>> isFalse) let shouldGoToManagePledge = ctaButtonTappedWithType - .filter { $0 == .viewBacking || $0 == .manage } + .filter(shouldGoToManagePledge(with:)) .ignoreValues() .filter(featureNativeCheckoutPledgeViewIsEnabled) @@ -356,3 +356,7 @@ private func fetchProject(projectOrParam: Either, shouldPrefix: return projectProducer } + +private func shouldGoToManagePledge(with type: PledgeStateCTAType) -> Bool { + return type == .viewBacking || type == .manage || type == .fix +} From 356ec841eb2e9822fe928f044f004178a6692792 Mon Sep 17 00:00:00 2001 From: Nino Collaco Date: Fri, 10 Jan 2020 15:50:23 -0500 Subject: [PATCH 2/4] Tests --- .../ProjectPamphletViewModelTests.swift | 55 +++++++++++++++---- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/Library/ViewModels/ProjectPamphletViewModelTests.swift b/Library/ViewModels/ProjectPamphletViewModelTests.swift index 056e24be43..183a3583d4 100644 --- a/Library/ViewModels/ProjectPamphletViewModelTests.swift +++ b/Library/ViewModels/ProjectPamphletViewModelTests.swift @@ -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] @@ -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]) @@ -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! @@ -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() } } From 2a32a341ccdab01d8e5a023cbd18799e25dd4c83 Mon Sep 17 00:00:00 2001 From: Nino Collaco Date: Mon, 13 Jan 2020 14:17:16 -0500 Subject: [PATCH 3/4] Added Equatable extension to make the logic more descriptive --- Kickstarter.xcodeproj/project.pbxproj | 8 ++++++++ Library/Equatable+Helpers.swift | 7 +++++++ Library/EquatableHelpersTests.swift | 10 ++++++++++ Library/ViewModels/ProjectPamphletViewModel.swift | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Library/Equatable+Helpers.swift create mode 100644 Library/EquatableHelpersTests.swift diff --git a/Kickstarter.xcodeproj/project.pbxproj b/Kickstarter.xcodeproj/project.pbxproj index 2dc8cbed94..993fbeb480 100644 --- a/Kickstarter.xcodeproj/project.pbxproj +++ b/Kickstarter.xcodeproj/project.pbxproj @@ -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 */; }; @@ -2541,6 +2543,8 @@ D6B9F942220358D1003282A5 /* AuthorTemplates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorTemplates.swift; sourceTree = ""; }; D6B9F94422035E34003282A5 /* AuthorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorTests.swift; sourceTree = ""; }; D6B9FA1422089C05003282A5 /* SelectCurrencyViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectCurrencyViewControllerTests.swift; sourceTree = ""; }; + D6BD66BA23CCF79D008694BB /* Equatable+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Equatable+Helpers.swift"; sourceTree = ""; }; + D6BD66BC23CCF7B6008694BB /* EquatableHelpersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EquatableHelpersTests.swift; sourceTree = ""; }; D6C38459210B9AC400ADB671 /* SettingsNewslettersTopCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsNewslettersTopCell.swift; sourceTree = ""; }; D6C3845A210B9AC400ADB671 /* SettingsNewslettersTopCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsNewslettersTopCell.xib; sourceTree = ""; }; D6C9A20D1F755FE200981E64 /* GraphSchemaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphSchemaTests.swift; sourceTree = ""; }; @@ -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 */, @@ -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 */, @@ -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 */, diff --git a/Library/Equatable+Helpers.swift b/Library/Equatable+Helpers.swift new file mode 100644 index 0000000000..b88c0453d2 --- /dev/null +++ b/Library/Equatable+Helpers.swift @@ -0,0 +1,7 @@ +import Foundation + +extension Equatable { + func isAny(of elements: Self...) -> Bool { + return elements.contains(self) + } +} diff --git a/Library/EquatableHelpersTests.swift b/Library/EquatableHelpersTests.swift new file mode 100644 index 0000000000..de52ff046c --- /dev/null +++ b/Library/EquatableHelpersTests.swift @@ -0,0 +1,10 @@ +import XCTest +@testable import Library + +final class EquatableHelpersTests: TestCase { + + func testIsAnyOf() { + XCTAssertTrue("one".isAny(of: "one", "two", "three")) + XCTAssertFalse("five".isAny(of: "one", "two", "three")) + } +} diff --git a/Library/ViewModels/ProjectPamphletViewModel.swift b/Library/ViewModels/ProjectPamphletViewModel.swift index f907094883..e8f440ce2c 100644 --- a/Library/ViewModels/ProjectPamphletViewModel.swift +++ b/Library/ViewModels/ProjectPamphletViewModel.swift @@ -358,5 +358,5 @@ private func fetchProject(projectOrParam: Either, shouldPrefix: } private func shouldGoToManagePledge(with type: PledgeStateCTAType) -> Bool { - return type == .viewBacking || type == .manage || type == .fix + return type.isAny(of: .viewBacking, .manage, .fix) } From 232ee34fb4896767b2465529a11e7b6f3de05958 Mon Sep 17 00:00:00 2001 From: Nino Collaco Date: Mon, 13 Jan 2020 17:06:06 -0500 Subject: [PATCH 4/4] SwiftFormat --- Library/EquatableHelpersTests.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/EquatableHelpersTests.swift b/Library/EquatableHelpersTests.swift index de52ff046c..726a419ad3 100644 --- a/Library/EquatableHelpersTests.swift +++ b/Library/EquatableHelpersTests.swift @@ -1,8 +1,7 @@ -import XCTest @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"))