From e8fe4270ee4649c7e5f57b730a73e9828ea061cd Mon Sep 17 00:00:00 2001 From: Justin Swart Date: Thu, 11 Jun 2020 17:19:24 -0700 Subject: [PATCH 1/3] Do not set the background of DiscoveryPageVC when contained in editorial VC --- .../Views/Controllers/DiscoveryPageViewController.swift | 2 +- .../Views/Controllers/EditorialProjectsViewController.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift b/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift index 13b3389e7f..9bd0a12625 100644 --- a/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift +++ b/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift @@ -314,7 +314,7 @@ internal final class DiscoveryPageViewController: UITableViewController { self.viewModel.outputs.backgroundColor .observeForUI() .observeValues { [weak self] backgroundColor in - guard let self = self else { return } + guard let self = self, !(self.parent is EditorialProjectsViewController) else { return } _ = self.view |> \.backgroundColor .~ backgroundColor diff --git a/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift b/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift index 945e617ef7..1a5a98bbec 100644 --- a/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift +++ b/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift @@ -194,12 +194,12 @@ public final class EditorialProjectsViewController: UIViewController { // MARK: - Layout private func configureSubviews() { - _ = (self.discoveryPageViewController.view, self.view) + _ = (self.headerView, self.view) |> ksr_addSubviewToParent() - |> ksr_constrainViewToEdgesInParent() - _ = (self.headerView, self.view) + _ = (self.discoveryPageViewController.view, self.view) |> ksr_addSubviewToParent() + |> ksr_constrainViewToEdgesInParent() _ = (self.headerTopLayoutGuide, self.headerView) |> ksr_addLayoutGuideToView() From c2b8e078d224f06ef48c7ff35751ba110a957400 Mon Sep 17 00:00:00 2001 From: Justin Swart Date: Fri, 12 Jun 2020 15:25:52 -0700 Subject: [PATCH 2/3] Use shared function to provide the background color for discovery --- .../Library/SharedFunctionsTests.swift | 24 ++++ .../Cells/ActivitySampleBackingCell.swift | 1 + .../Cells/ActivitySampleFollowCell.swift | 1 + .../Views/Cells/DiscoveryEditorialCell.swift | 4 +- .../Views/Cells/DiscoveryOnboardingCell.swift | 2 +- .../Views/Cells/PersonalizationCell.swift | 1 + .../DiscoveryPageViewController.swift | 24 +--- .../EditorialProjectsViewController.swift | 4 +- Library/OptimizelyClientType.swift | 14 ++- Library/SharedFunctions.swift | 11 ++ .../TestHelpers/MockOptimizelyClient.swift | 15 ++- .../CategorySelectionViewModel.swift | 2 +- .../CategorySelectionViewModelTests.swift | 10 +- .../ViewModels/DiscoveryPageViewModel.swift | 20 +--- .../DiscoveryPageViewModelTests.swift | 40 ------- Library/ViewModels/LandingPageViewModel.swift | 2 +- .../LandingPageViewModelTests.swift | 2 +- Library/ViewModels/LandingViewModel.swift | 2 +- ...PledgeCTAContainerViewViewModelTests.swift | 2 - Library/ViewModels/PledgeViewModel.swift | 8 +- Library/ViewModels/PledgeViewModelTests.swift | 106 +++++++++--------- .../ProjectDescriptionViewModelTests.swift | 6 +- .../ProjectPamphletMainCellViewModel.swift | 2 +- ...rojectPamphletMainCellViewModelTests.swift | 6 +- .../ViewModels/ProjectPamphletViewModel.swift | 5 +- .../ProjectPamphletViewModelTests.swift | 12 +- 26 files changed, 148 insertions(+), 178 deletions(-) diff --git a/Kickstarter-iOS/Library/SharedFunctionsTests.swift b/Kickstarter-iOS/Library/SharedFunctionsTests.swift index 5dc8cfe3b7..c138507a7b 100644 --- a/Kickstarter-iOS/Library/SharedFunctionsTests.swift +++ b/Kickstarter-iOS/Library/SharedFunctionsTests.swift @@ -209,4 +209,28 @@ internal final class SharedFunctionsTests: XCTestCase { func testPledgeAmountSubtractingShippingAmount() { XCTAssertEqual(ksr_pledgeAmount(700.50, subtractingShippingAmount: 100), 600.50) } + + func testDiscoveryPageBackgroundColor_Control() { + let optimizelyClient = MockOptimizelyClient() + |> \.experiments .~ [ + OptimizelyExperiment.Key.nativeProjectCards.rawValue: + OptimizelyExperiment.Variant.control.rawValue + ] + + withEnvironment(optimizelyClient: optimizelyClient) { + XCTAssertEqual(discoveryPageBackgroundColor(), .white) + } + } + + func testDiscoveryPageBackgroundColor_Variant1() { + let optimizelyClient = MockOptimizelyClient() + |> \.experiments .~ [ + OptimizelyExperiment.Key.nativeProjectCards.rawValue: + OptimizelyExperiment.Variant.variant1.rawValue + ] + + withEnvironment(optimizelyClient: optimizelyClient) { + XCTAssertEqual(discoveryPageBackgroundColor(), .ksr_grey_200) + } + } } diff --git a/Kickstarter-iOS/Views/Cells/ActivitySampleBackingCell.swift b/Kickstarter-iOS/Views/Cells/ActivitySampleBackingCell.swift index d151b0fdc7..91b7d5364b 100644 --- a/Kickstarter-iOS/Views/Cells/ActivitySampleBackingCell.swift +++ b/Kickstarter-iOS/Views/Cells/ActivitySampleBackingCell.swift @@ -35,6 +35,7 @@ internal final class ActivitySampleBackingCell: UITableViewCell, ValueCell { _ = self |> activitySampleCellStyle + |> \.backgroundColor .~ discoveryPageBackgroundColor() |> UITableViewCell.lens.accessibilityHint %~ { _ in Strings.dashboard_tout_accessibility_hint_opens_project() } diff --git a/Kickstarter-iOS/Views/Cells/ActivitySampleFollowCell.swift b/Kickstarter-iOS/Views/Cells/ActivitySampleFollowCell.swift index e9f7d0db50..a852d9077f 100644 --- a/Kickstarter-iOS/Views/Cells/ActivitySampleFollowCell.swift +++ b/Kickstarter-iOS/Views/Cells/ActivitySampleFollowCell.swift @@ -35,6 +35,7 @@ internal final class ActivitySampleFollowCell: UITableViewCell, ValueCell { _ = self |> activitySampleCellStyle + |> \.backgroundColor .~ discoveryPageBackgroundColor() _ = self.activityStackView |> activitySampleStackViewStyle diff --git a/Kickstarter-iOS/Views/Cells/DiscoveryEditorialCell.swift b/Kickstarter-iOS/Views/Cells/DiscoveryEditorialCell.swift index bb6da24265..9ad47406c9 100644 --- a/Kickstarter-iOS/Views/Cells/DiscoveryEditorialCell.swift +++ b/Kickstarter-iOS/Views/Cells/DiscoveryEditorialCell.swift @@ -90,7 +90,9 @@ final class DiscoveryEditorialCell: UITableViewCell, ValueCell { |> \.accessibilityTraits .~ [UIAccessibilityTraits.button] |> \.accessibilityLabel %~ { _ in Strings.Introducing_Lights_On() } |> \.accessibilityHint %~ { _ in Strings.Support_creative_spaces_and_businesses_affected_by() } - |> \.backgroundColor .~ .clear + + _ = self + |> \.backgroundColor .~ discoveryPageBackgroundColor() _ = self.rootStackView |> rootStackViewStyle diff --git a/Kickstarter-iOS/Views/Cells/DiscoveryOnboardingCell.swift b/Kickstarter-iOS/Views/Cells/DiscoveryOnboardingCell.swift index c31f3d4b00..fa70b4f905 100644 --- a/Kickstarter-iOS/Views/Cells/DiscoveryOnboardingCell.swift +++ b/Kickstarter-iOS/Views/Cells/DiscoveryOnboardingCell.swift @@ -25,7 +25,7 @@ internal final class DiscoveryOnboardingCell: UITableViewCell, ValueCell { internal override func bindStyles() { _ = self |> baseTableViewCellStyle() - |> \.backgroundColor .~ .clear + |> \.backgroundColor .~ discoveryPageBackgroundColor() |> DiscoveryOnboardingCell.lens.contentView.layoutMargins %~~ { layoutMargins, cell in cell.traitCollection.isRegularRegular ? .init(top: Styles.grid(5), left: Styles.grid(30), bottom: 0, right: Styles.grid(30)) diff --git a/Kickstarter-iOS/Views/Cells/PersonalizationCell.swift b/Kickstarter-iOS/Views/Cells/PersonalizationCell.swift index fd7e0eb61d..16d57a3267 100644 --- a/Kickstarter-iOS/Views/Cells/PersonalizationCell.swift +++ b/Kickstarter-iOS/Views/Cells/PersonalizationCell.swift @@ -76,6 +76,7 @@ final class PersonalizationCell: UITableViewCell, ValueCell { _ = self |> baseTableViewCellStyle() + |> \.backgroundColor .~ discoveryPageBackgroundColor() |> \.accessibilityElements .~ [self.containerView, self.dismissButton] |> PersonalizationCell.lens.contentView.layoutMargins %~~ { _, cell in cell.traitCollection.isRegularRegular diff --git a/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift b/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift index 9bd0a12625..357acf0ab3 100644 --- a/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift +++ b/Kickstarter-iOS/Views/Controllers/DiscoveryPageViewController.swift @@ -23,7 +23,6 @@ internal final class DiscoveryPageViewController: UITableViewController { fileprivate var emptyStatesController: EmptyStatesViewController? private lazy var headerLabel = { UILabel(frame: .zero) }() private var onboardingCompletedObserver: Any? - internal var preferredBackgroundColor: UIColor? private var sessionEndedObserver: Any? private var sessionStartedObserver: Any? @@ -134,10 +133,11 @@ internal final class DiscoveryPageViewController: UITableViewController { |> \.rowHeight .~ UITableView.automaticDimension |> \.estimatedRowHeight .~ 200.0 - if let preferredBackgroundColor = self.preferredBackgroundColor { - _ = self - |> \.view.backgroundColor .~ preferredBackgroundColor - } + _ = self.view + |> \.backgroundColor .~ ( + // Update the background if it is not currently clear (contained in EditorialProjectsViewController) + self.view.backgroundColor != .clear ? discoveryPageBackgroundColor() : self.view.backgroundColor + ) _ = self.headerLabel |> headerLabelStyle @@ -311,20 +311,6 @@ internal final class DiscoveryPageViewController: UITableViewController { self?.present(nav, animated: true, completion: nil) } - self.viewModel.outputs.backgroundColor - .observeForUI() - .observeValues { [weak self] backgroundColor in - guard let self = self, !(self.parent is EditorialProjectsViewController) else { return } - - _ = self.view - |> \.backgroundColor .~ backgroundColor - - _ = self.tableView - |> \.backgroundColor .~ backgroundColor - - self.preferredBackgroundColor = backgroundColor - } - self.viewModel.outputs.contentInset .observeForUI() .observeValues { [weak self] inset in diff --git a/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift b/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift index 1a5a98bbec..0c1702d493 100644 --- a/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift +++ b/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift @@ -13,7 +13,6 @@ public final class EditorialProjectsViewController: UIViewController { internal lazy var discoveryPageViewController: DiscoveryPageViewController = { DiscoveryPageViewController.configuredWith(sort: .distance) - |> \.preferredBackgroundColor .~ .clear |> \.delegate .~ self }() @@ -100,6 +99,9 @@ public final class EditorialProjectsViewController: UIViewController { _ = self.view |> \.backgroundColor .~ UIColor.white + _ = self.discoveryPageViewController.view + |> \.backgroundColor .~ .clear + _ = self.headerView |> UIView.lens.layoutMargins %~~ { _, view in view.traitCollection.isRegularRegular diff --git a/Library/OptimizelyClientType.swift b/Library/OptimizelyClientType.swift index cb529d74b4..b4acde3344 100644 --- a/Library/OptimizelyClientType.swift +++ b/Library/OptimizelyClientType.swift @@ -78,15 +78,17 @@ extension OptimizelyClientType { attributes: optimizelyUserAttributes() ) } - + public func track(eventName: String) { let userAttributes = optimizelyUserAttributes() let userId = deviceIdentifier(uuid: UUID()) - try? self.track(eventKey: eventName, - userId: userId, - attributes: userAttributes, - eventTags: nil) + try? self.track( + eventKey: eventName, + userId: userId, + attributes: userAttributes, + eventTags: nil + ) } } @@ -131,7 +133,7 @@ public func optimizelyProperties(environment: Environment? = AppEnvironment.curr "optimizely_experiments": allExperiments ] } - + public func optimizelyUserAttributes( with project: Project? = nil, refTag: RefTag? = nil diff --git a/Library/SharedFunctions.swift b/Library/SharedFunctions.swift index 39ca14f8dc..63b52a4543 100644 --- a/Library/SharedFunctions.swift +++ b/Library/SharedFunctions.swift @@ -249,3 +249,14 @@ public func ksr_pledgeAmount( return (pledgeAmount as NSDecimalNumber).doubleValue } + +public func discoveryPageBackgroundColor() -> UIColor { + let variant = OptimizelyExperiment.nativeProjectCardsExperimentVariant() + + switch variant { + case .variant1: + return UIColor.ksr_grey_200 + case .variant2, .control: + return UIColor.white + } +} diff --git a/Library/TestHelpers/MockOptimizelyClient.swift b/Library/TestHelpers/MockOptimizelyClient.swift index a7fd0e2c85..99048afe29 100644 --- a/Library/TestHelpers/MockOptimizelyClient.swift +++ b/Library/TestHelpers/MockOptimizelyClient.swift @@ -19,9 +19,9 @@ internal class MockOptimizelyClient: OptimizelyClientType { var features: [String: Bool] = [:] var getVariantPathCalled: Bool = false var userAttributes: [String: Any?]? - + // MARK: - Event Tracking Test Properties - + var trackedAttributes: [String: Any?]? var trackedEventKey: String? var trackedUserId: String? @@ -56,9 +56,14 @@ internal class MockOptimizelyClient: OptimizelyClientType { } return experimentVariant - } - - func track(eventKey: String, userId: String, attributes: [String: Any?]?, eventTags: [String: Any]?) throws { + } + + func track( + eventKey: String, + userId: String, + attributes: [String: Any?]?, + eventTags _: [String: Any]? + ) throws { self.trackedEventKey = eventKey self.trackedAttributes = attributes self.trackedUserId = userId diff --git a/Library/ViewModels/CategorySelectionViewModel.swift b/Library/ViewModels/CategorySelectionViewModel.swift index 6efbc627ab..bc42b97930 100644 --- a/Library/ViewModels/CategorySelectionViewModel.swift +++ b/Library/ViewModels/CategorySelectionViewModel.swift @@ -114,7 +114,7 @@ public final class CategorySelectionViewModel: CategorySelectionViewModelType, trackOptimizelyClientButtonClicked(buttonTitle: "Skip") } - self.continueButtonTappedProperty.signal.observeValues { buttonTitle in + self.continueButtonTappedProperty.signal.observeValues { _ in let optimizelyProps = optimizelyProperties() ?? [:] AppEnvironment.current.koala.trackOnboardingContinueButtonClicked(optimizelyProperties: optimizelyProps) trackOptimizelyClientButtonClicked(buttonTitle: "Continue") diff --git a/Library/ViewModels/CategorySelectionViewModelTests.swift b/Library/ViewModels/CategorySelectionViewModelTests.swift index b11201c0c9..611cf5fad1 100644 --- a/Library/ViewModels/CategorySelectionViewModelTests.swift +++ b/Library/ViewModels/CategorySelectionViewModelTests.swift @@ -334,11 +334,10 @@ final class CategorySelectionViewModelTests: TestCase { self.vm.inputs.categorySelected(with: (artIndexPath, .art)) self.vm.inputs.categorySelected(with: (illustrationIndexPath, .illustration)) self.vm.inputs.categorySelected(with: (gamesIndexPath, .games)) - + XCTAssertNil(self.optimizelyClient.trackedEventKey) XCTAssertNil(self.optimizelyClient.trackedAttributes) - XCTAssertNil(mockKVStore.onboardingCategories) XCTAssertFalse(mockKVStore.hasCompletedCategoryPersonalizationFlow) @@ -353,7 +352,7 @@ final class CategorySelectionViewModelTests: TestCase { XCTAssertEqual(encodedCategories, mockKVStore.onboardingCategories) XCTAssertTrue(mockKVStore.hasCompletedCategoryPersonalizationFlow) - + XCTAssertEqual("Continue Button Clicked", self.optimizelyClient.trackedEventKey) XCTAssertEqual(["Onboarding Continue Button Clicked"], self.trackingClient.events) XCTAssertEqual(self.trackingClient.properties(forKey: "context_location"), ["onboarding"]) @@ -428,15 +427,14 @@ final class CategorySelectionViewModelTests: TestCase { self.scheduler.advance() self.dismiss.assertDidNotEmitValue() - + XCTAssertNil(self.optimizelyClient.trackedEventKey) XCTAssertNil(self.optimizelyClient.trackedAttributes) - self.vm.inputs.skipButtonTapped() self.dismiss.assertValueCount(1) - + XCTAssertEqual(self.optimizelyClient.trackedEventKey, "Skip Button Clicked") XCTAssertEqual(self.trackingClient.events, ["Onboarding Skip Button Clicked"]) XCTAssertEqual(self.trackingClient.properties(forKey: "context_location"), ["onboarding"]) diff --git a/Library/ViewModels/DiscoveryPageViewModel.swift b/Library/ViewModels/DiscoveryPageViewModel.swift index 765ba6f33d..9a25a35aac 100644 --- a/Library/ViewModels/DiscoveryPageViewModel.swift +++ b/Library/ViewModels/DiscoveryPageViewModel.swift @@ -78,9 +78,6 @@ public protocol DiscoveryPageViewModelOutputs { /// Hopefully in the future we can remove this when we can resolve postcard display issues. var asyncReloadData: Signal { get } - /// Emits the background color for the view - var backgroundColor: Signal { get } - /// Emits the contentInset for the UITableView var contentInset: Signal { get } @@ -229,18 +226,6 @@ public final class DiscoveryPageViewModel: DiscoveryPageViewModelType, Discovery self.asyncReloadData = self.projectsLoaded.take(first: 1).ignoreValues() - self.backgroundColor = self.viewWillAppearProperty.signal - .map { _ in - let variant = OptimizelyExperiment.nativeProjectCardsExperimentVariant() - - switch variant { - case .variant1: - return UIColor.ksr_grey_200 - case .variant2, .control: - return UIColor.white - } - } - self.contentInset = self.viewWillAppearProperty.signal .map { _ in let variant = OptimizelyExperiment.nativeProjectCardsExperimentVariant() @@ -444,9 +429,9 @@ public final class DiscoveryPageViewModel: DiscoveryPageViewModelType, Discovery let personalizationCellTappedAndRefTag = self.personalizationCellTappedProperty.signal .mapConst(RefTag.onboarding) - + personalizationCellTappedAndRefTag - .observeValues { refTag in + .observeValues { _ in AppEnvironment.current.optimizelyClient?.track(eventName: "Editorial Card Clicked") } @@ -591,7 +576,6 @@ public final class DiscoveryPageViewModel: DiscoveryPageViewModelType, Discovery public let activitiesForSample: Signal<[Activity], Never> public let asyncReloadData: Signal - public let backgroundColor: Signal public let contentInset: Signal public let dismissPersonalizationCell: Signal public let goToActivityProject: Signal<(Project, RefTag), Never> diff --git a/Library/ViewModels/DiscoveryPageViewModelTests.swift b/Library/ViewModels/DiscoveryPageViewModelTests.swift index b2e8463ae5..6e7e84f10b 100644 --- a/Library/ViewModels/DiscoveryPageViewModelTests.swift +++ b/Library/ViewModels/DiscoveryPageViewModelTests.swift @@ -11,7 +11,6 @@ internal final class DiscoveryPageViewModelTests: TestCase { fileprivate let activitiesForSample = TestObserver<[Activity], Never>() fileprivate let asyncReloadData = TestObserver<(), Never>() - fileprivate let backgroundColor = TestObserver() fileprivate let contentInset = TestObserver() fileprivate let dismissPersonalizationCell = TestObserver() fileprivate let goToActivityProject = TestObserver() @@ -47,7 +46,6 @@ internal final class DiscoveryPageViewModelTests: TestCase { self.vm.outputs.activitiesForSample.observe(self.activitiesForSample.observer) self.vm.outputs.asyncReloadData.observe(self.asyncReloadData.observer) - self.vm.outputs.backgroundColor.observe(self.backgroundColor.observer) self.vm.outputs.contentInset.observe(self.contentInset.observer) self.vm.outputs.dismissPersonalizationCell.observe(self.dismissPersonalizationCell.observer) self.vm.outputs.hideEmptyState.observe(self.hideEmptyState.observer) @@ -356,44 +354,6 @@ internal final class DiscoveryPageViewModelTests: TestCase { } } - func testBackgroundColor_IsNativeProjectCardsControl() { - let mockOptimizelyClient = MockOptimizelyClient() - |> \.experiments .~ [ - OptimizelyExperiment.Key.nativeProjectCards.rawValue: - OptimizelyExperiment.Variant.control.rawValue - ] - - withEnvironment(optimizelyClient: mockOptimizelyClient) { - self.vm.inputs.configureWith(sort: .magic) - self.vm.inputs.viewWillAppear() - self.vm.inputs.viewDidAppear() - self.scheduler.advance() - - self.backgroundColor.assertValues([.white]) - - XCTAssertTrue(mockOptimizelyClient.getVariantPathCalled) - } - } - - func testBackgroundColor_IsNativeProjectCardsVariant1() { - let mockOptimizelyClient = MockOptimizelyClient() - |> \.experiments .~ [ - OptimizelyExperiment.Key.nativeProjectCards.rawValue: - OptimizelyExperiment.Variant.variant1.rawValue - ] - - withEnvironment(optimizelyClient: mockOptimizelyClient) { - self.vm.inputs.configureWith(sort: .magic) - self.vm.inputs.viewWillAppear() - self.vm.inputs.viewDidAppear() - self.scheduler.advance() - - self.backgroundColor.assertValues([UIColor.ksr_grey_200]) - - XCTAssertTrue(mockOptimizelyClient.getVariantPathCalled) - } - } - func testContentInset_IsNativeProjectCardsControl() { let mockOptimizelyClient = MockOptimizelyClient() |> \.experiments .~ [ diff --git a/Library/ViewModels/LandingPageViewModel.swift b/Library/ViewModels/LandingPageViewModel.swift index bc665455de..a2a0730486 100644 --- a/Library/ViewModels/LandingPageViewModel.swift +++ b/Library/ViewModels/LandingPageViewModel.swift @@ -42,7 +42,7 @@ public final class LandingPageViewModel: LandingPageViewModelType, LandingPageVi AppEnvironment.current.koala .trackOnboardingGetStartedButtonClicked(optimizelyProperties: optimizelyProps) - + AppEnvironment.current.optimizelyClient?.track(eventName: "Get Started Button Clicked") } } diff --git a/Library/ViewModels/LandingPageViewModelTests.swift b/Library/ViewModels/LandingPageViewModelTests.swift index 24ffd9385d..4f8cfdeb5d 100644 --- a/Library/ViewModels/LandingPageViewModelTests.swift +++ b/Library/ViewModels/LandingPageViewModelTests.swift @@ -29,7 +29,7 @@ internal final class LandingPageViewModelTests: TestCase { func testTrackingGetStartedButtonTapped() { XCTAssertEqual(self.optimizelyClient.trackedEventKey, nil) - + self.viewModel.inputs.ctaButtonTapped() XCTAssertEqual(self.optimizelyClient.trackedEventKey, "Get Started Button Clicked") diff --git a/Library/ViewModels/LandingViewModel.swift b/Library/ViewModels/LandingViewModel.swift index 2fe67852d5..c64ff781a2 100644 --- a/Library/ViewModels/LandingViewModel.swift +++ b/Library/ViewModels/LandingViewModel.swift @@ -31,7 +31,7 @@ public final class LandingViewModel: LandingViewModelType, LandingViewModelInput AppEnvironment.current.koala .trackOnboardingGetStartedButtonClicked(optimizelyProperties: optimizelyProps) - + AppEnvironment.current.optimizelyClient?.track(eventName: "Get Started Button Clicked") } } diff --git a/Library/ViewModels/PledgeCTAContainerViewViewModelTests.swift b/Library/ViewModels/PledgeCTAContainerViewViewModelTests.swift index 98b64eb11c..7df3ddea86 100644 --- a/Library/ViewModels/PledgeCTAContainerViewViewModelTests.swift +++ b/Library/ViewModels/PledgeCTAContainerViewViewModelTests.swift @@ -281,8 +281,6 @@ internal final class PledgeCTAContainerViewViewModelTests: TestCase { ) XCTAssertEqual(optimizelyClient.userAttributes?["session_apple_pay_device"] as? Bool, true) XCTAssertEqual(optimizelyClient.userAttributes?["session_device_format"] as? String, "phone") - - } } diff --git a/Library/ViewModels/PledgeViewModel.swift b/Library/ViewModels/PledgeViewModel.swift index bbfb550afc..a102d0037c 100644 --- a/Library/ViewModels/PledgeViewModel.swift +++ b/Library/ViewModels/PledgeViewModel.swift @@ -648,11 +648,11 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge refTag: refTag ) } - + createBackingDataAndIsApplePay.takeWhen(createBackingCompletionEvents) - .observeValues { data, isApplePay in - AppEnvironment.current.optimizelyClient?.track(eventName: "App Completed Checkout") - } + .observeValues { _, _ in + AppEnvironment.current.optimizelyClient?.track(eventName: "App Completed Checkout") + } Signal.combineLatest(project, updateBackingData, context) .takeWhen(updateButtonTapped) diff --git a/Library/ViewModels/PledgeViewModelTests.swift b/Library/ViewModels/PledgeViewModelTests.swift index 04296807db..91ddd0fa35 100644 --- a/Library/ViewModels/PledgeViewModelTests.swift +++ b/Library/ViewModels/PledgeViewModelTests.swift @@ -1250,7 +1250,7 @@ final class PledgeViewModelTests: TestCase { ) } } - + func testApplePay_OptimizelyExperimentTracking() { let createBacking = CreateBackingEnvelope.CreateBacking( checkout: Checkout( @@ -1552,7 +1552,7 @@ final class PledgeViewModelTests: TestCase { ) } } - + func testCreateBacking_Success_OptimizelyExperimentTracking() { let createBacking = CreateBackingEnvelope.CreateBacking( checkout: Checkout( @@ -3935,12 +3935,12 @@ final class PledgeViewModelTests: TestCase { XCTAssertEqual(trackingClient.properties(forKey: "project_user_has_watched", as: Bool.self), [nil]) } } - + func testTrackingEvents_OptimizelyClient_PledgeScreenViewed_LoggedOut() { let project = Project.template |> \.category.parentId .~ Project.Category.art.id |> \.category.parentName .~ Project.Category.art.name - + self.vm.inputs.configureWith(project: project, reward: .template, refTag: .discovery, context: .pledge) XCTAssertEqual([], self.trackingClient.events) @@ -3950,13 +3950,13 @@ final class PledgeViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedUserId, "DEADBEEF-DEAD-BEEF-DEAD-DEADBEEFBEEF") XCTAssertEqual(self.optimizelyClient.trackedEventKey, "Pledge Screen Viewed") - + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_backed_projects_count"] as? Int, nil) XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_launched_projects_count"] as? Int, nil) XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_country"] as? String, "us") XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_facebook_account"] as? Bool, nil) XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_display_language"] as? String, "en") - + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_ref_tag"] as? String, nil) XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_referrer_credit"] as? String, nil) XCTAssertEqual( @@ -3971,53 +3971,53 @@ final class PledgeViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_apple_pay_device"] as? Bool, true) XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_device_format"] as? String, "phone") } - + func testTrackingEvents_OptimizelyClient_PledgeScreenViewed_LoggedIn() { - let user = User.template - |> \.location .~ Location.template - |> \.stats.backedProjectsCount .~ 50 - |> \.stats.createdProjectsCount .~ 25 - |> \.facebookConnected .~ true - - withEnvironment(currentUser: user) { - let project = Project.template - |> \.category.parentId .~ Project.Category.art.id - |> \.category.parentName .~ Project.Category.art.name - |> Project.lens.stats.currentCurrency .~ "USD" - |> \.personalization.isStarred .~ true - - self.vm.inputs.configureWith( - project: project, reward: .template, refTag: .discovery, context: .pledge - ) - - XCTAssertEqual([], self.trackingClient.events) - self.vm.inputs.viewDidLoad() - - XCTAssertEqual(["Checkout Payment Page Viewed"], self.trackingClient.events) - - XCTAssertEqual(self.optimizelyClient.trackedUserId, "DEADBEEF-DEAD-BEEF-DEAD-DEADBEEFBEEF") - XCTAssertEqual(self.optimizelyClient.trackedEventKey, "Pledge Screen Viewed") - - XCTAssertNil(self.optimizelyClient.trackedAttributes?["user_distinct_id"] as? String) - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_backed_projects_count"] as? Int, 50) - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_launched_projects_count"] as? Int, 25) - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_country"] as? String, "us") - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_facebook_account"] as? Bool, true) - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_display_language"] as? String, "en") - XCTAssertEqual( - self.optimizelyClient.trackedAttributes?["session_os_version"] as? String, - "MockSystemVersion" - ) - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_user_is_logged_in"] as? Bool, true) - XCTAssertEqual( - self.optimizelyClient.trackedAttributes?["session_app_release_version"] as? String, - "1.2.3.4.5.6.7.8.9.0" - ) - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_apple_pay_device"] as? Bool, true) - XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_device_format"] as? String, "phone") - } + let user = User.template + |> \.location .~ Location.template + |> \.stats.backedProjectsCount .~ 50 + |> \.stats.createdProjectsCount .~ 25 + |> \.facebookConnected .~ true + + withEnvironment(currentUser: user) { + let project = Project.template + |> \.category.parentId .~ Project.Category.art.id + |> \.category.parentName .~ Project.Category.art.name + |> Project.lens.stats.currentCurrency .~ "USD" + |> \.personalization.isStarred .~ true + + self.vm.inputs.configureWith( + project: project, reward: .template, refTag: .discovery, context: .pledge + ) + + XCTAssertEqual([], self.trackingClient.events) + self.vm.inputs.viewDidLoad() + + XCTAssertEqual(["Checkout Payment Page Viewed"], self.trackingClient.events) + + XCTAssertEqual(self.optimizelyClient.trackedUserId, "DEADBEEF-DEAD-BEEF-DEAD-DEADBEEFBEEF") + XCTAssertEqual(self.optimizelyClient.trackedEventKey, "Pledge Screen Viewed") + + XCTAssertNil(self.optimizelyClient.trackedAttributes?["user_distinct_id"] as? String) + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_backed_projects_count"] as? Int, 50) + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_launched_projects_count"] as? Int, 25) + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_country"] as? String, "us") + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_facebook_account"] as? Bool, true) + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_display_language"] as? String, "en") + XCTAssertEqual( + self.optimizelyClient.trackedAttributes?["session_os_version"] as? String, + "MockSystemVersion" + ) + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_user_is_logged_in"] as? Bool, true) + XCTAssertEqual( + self.optimizelyClient.trackedAttributes?["session_app_release_version"] as? String, + "1.2.3.4.5.6.7.8.9.0" + ) + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_apple_pay_device"] as? Bool, true) + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_device_format"] as? String, "phone") + } } - + func testTrackingEvents_PledgeScreenViewed_LoggedIn() { let user = User.template |> \.location .~ Location.template @@ -4061,7 +4061,7 @@ final class PledgeViewModelTests: TestCase { XCTAssertEqual(trackingClient.properties(forKey: "project_user_has_watched", as: Bool.self), [true]) } } - + func testTrackingEvents_PledgeScreenViewed_DistinctID_LoggedIn_Beta_Staging() { let user = User.template |> \.location .~ Location.template @@ -4096,7 +4096,7 @@ final class PledgeViewModelTests: TestCase { ) } } - + func testTrackingEvents_PledgeScreenViewed_DistinctID_LoggedIn_Release_Production() { let user = User.template |> \.location .~ Location.template diff --git a/Library/ViewModels/ProjectDescriptionViewModelTests.swift b/Library/ViewModels/ProjectDescriptionViewModelTests.swift index 631f2093f6..17a95237f7 100644 --- a/Library/ViewModels/ProjectDescriptionViewModelTests.swift +++ b/Library/ViewModels/ProjectDescriptionViewModelTests.swift @@ -465,7 +465,7 @@ final class ProjectDescriptionViewModelTests: TestCase { self.pledgeCTAContainerViewIsHidden.assertValues([true]) } } - + func testOptimizelyTrackingCampaignDetailsPledgeButtonTapped_LiveProject_LoggedIn_NonBacked_Variant1() { let user = User.template |> \.location .~ Location.template @@ -537,7 +537,7 @@ final class ProjectDescriptionViewModelTests: TestCase { self.vm.inputs.viewDidLoad() XCTAssertEqual(self.trackingClient.events, []) - + // Optimizely Client XCTAssertEqual(optimizelyClient.trackedUserId, nil) XCTAssertEqual(optimizelyClient.trackedEventKey, nil) @@ -562,7 +562,7 @@ final class ProjectDescriptionViewModelTests: TestCase { XCTAssertNotNil(properties?["optimizely_api_key"], "Event includes Optimizely properties") XCTAssertNotNil(properties?["optimizely_environment"], "Event includes Optimizely properties") XCTAssertNotNil(properties?["optimizely_experiments"], "Event includes Optimizely properties") - + // Optimizely Client XCTAssertEqual(optimizelyClient.trackedEventKey, "Campaign Details Pledge Button Clicked") XCTAssertEqual( diff --git a/Library/ViewModels/ProjectPamphletMainCellViewModel.swift b/Library/ViewModels/ProjectPamphletMainCellViewModel.swift index 955a3a6987..eea18ba566 100644 --- a/Library/ViewModels/ProjectPamphletMainCellViewModel.swift +++ b/Library/ViewModels/ProjectPamphletMainCellViewModel.swift @@ -370,7 +370,7 @@ public final class ProjectPamphletMainCellViewModel: ProjectPamphletMainCellView cookieRefTag: cookieRefTag, optimizelyProperties: optyProperties ?? [:] ) - + AppEnvironment.current.optimizelyClient?.track(eventName: "Creator Details Clicked") } } diff --git a/Library/ViewModels/ProjectPamphletMainCellViewModelTests.swift b/Library/ViewModels/ProjectPamphletMainCellViewModelTests.swift index ec92f0a1bb..9db596b1f5 100644 --- a/Library/ViewModels/ProjectPamphletMainCellViewModelTests.swift +++ b/Library/ViewModels/ProjectPamphletMainCellViewModelTests.swift @@ -680,7 +680,7 @@ final class ProjectPamphletMainCellViewModelTests: TestCase { ) } } - + func testOptimizelyTrackingCreatorBylineTapped_LiveProject_LoggedIn_NonBacked() { let creatorDetails = ProjectCreatorDetailsEnvelope.template @@ -726,7 +726,7 @@ final class ProjectPamphletMainCellViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_device_format"] as? String, "phone") } } - + func testOptimizelyTrackingCampaignDetailsButtonTapped_NonLiveProject_LoggedIn_Backed() { let creatorDetails = ProjectCreatorDetailsEnvelope.template let user = User.template @@ -749,7 +749,7 @@ final class ProjectPamphletMainCellViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedUserId, "DEADBEEF-DEAD-BEEF-DEAD-DEADBEEFBEEF") XCTAssertEqual(self.optimizelyClient.trackedEventKey, "Campaign Details Button Clicked") - + XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_backed_projects_count"] as? Int, 50) XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_launched_projects_count"] as? Int, nil) XCTAssertEqual(self.optimizelyClient.trackedAttributes?["user_country"] as? String, "us") diff --git a/Library/ViewModels/ProjectPamphletViewModel.swift b/Library/ViewModels/ProjectPamphletViewModel.swift index 6855694ba9..b403c47016 100644 --- a/Library/ViewModels/ProjectPamphletViewModel.swift +++ b/Library/ViewModels/ProjectPamphletViewModel.swift @@ -203,14 +203,13 @@ public final class ProjectPamphletViewModel: ProjectPamphletViewModelType, Proje .map(cookieFrom(refTag:project:)) .skipNil() .observeValues { AppEnvironment.current.cookieStorage.setCookie($0) } - - + let shouldTrackCTATappedEvent = ctaButtonTappedWithType .filter { [.pledge, .seeTheRewards, .viewTheRewards].contains($0) } Signal.combineLatest(project, refTag) .takeWhen(shouldTrackCTATappedEvent) - .observeValues { project, refTag in + .observeValues { _, _ in AppEnvironment.current.optimizelyClient?.track(eventName: "Project Page Pledge Button Clicked") } } diff --git a/Library/ViewModels/ProjectPamphletViewModelTests.swift b/Library/ViewModels/ProjectPamphletViewModelTests.swift index e0c6656054..6c25562806 100644 --- a/Library/ViewModels/ProjectPamphletViewModelTests.swift +++ b/Library/ViewModels/ProjectPamphletViewModelTests.swift @@ -894,7 +894,7 @@ final class ProjectPamphletViewModelTests: TestCase { XCTAssertNotNil(properties?["optimizely_experiments"], "Event includes Optimizely properties") } } - + func testOptimizelyTrackingProjectPageViewed_LoggedIn() { let user = User.template |> \.location .~ Location.template @@ -928,7 +928,7 @@ final class ProjectPamphletViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedAttributes?["session_device_format"] as? String, "phone") } } - + func testOptimizelyTrackingProjectPageViewed_LoggedOut() { withEnvironment(currentUser: nil) { self.vm.inputs.configureWith(projectOrParam: .left(.template), refTag: .discovery) @@ -1031,7 +1031,7 @@ final class ProjectPamphletViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedEventKey, nil) XCTAssertNil(self.optimizelyClient.trackedAttributes) } - + func testOptimizelyTrackingPledgeCTAButtonTapped_SeeTheRewards() { let project = Project.cosmicSurgery @@ -1057,7 +1057,7 @@ final class ProjectPamphletViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedEventKey, "Project Page Pledge Button Clicked") } - + func testOptimizelyTrackingPledgeCTAButtonTapped_LoggedIn_NonBacked() { let user = User.template |> \.location .~ Location.template @@ -1071,14 +1071,12 @@ final class ProjectPamphletViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedEventKey, nil) XCTAssertNil(self.optimizelyClient.trackedAttributes) - self.vm.inputs.pledgeCTAButtonTapped(with: .manage) XCTAssertEqual(self.optimizelyClient.trackedUserId, nil) XCTAssertEqual(self.optimizelyClient.trackedEventKey, nil) XCTAssertNil(self.optimizelyClient.trackedAttributes) - // Only track for non-backed, pledge state self.vm.inputs.pledgeCTAButtonTapped(with: .pledge) @@ -1128,14 +1126,12 @@ final class ProjectPamphletViewModelTests: TestCase { XCTAssertEqual(self.optimizelyClient.trackedEventKey, nil) XCTAssertNil(self.optimizelyClient.trackedAttributes) - self.vm.inputs.pledgeCTAButtonTapped(with: .manage) XCTAssertEqual(self.optimizelyClient.trackedUserId, nil) XCTAssertEqual(self.optimizelyClient.trackedEventKey, nil) XCTAssertNil(self.optimizelyClient.trackedAttributes) - // Only track for non-backed, pledge state self.vm.inputs.pledgeCTAButtonTapped(with: .manage) From cf13af9711b99f5ea11f8b5df7f81fde16f5dea2 Mon Sep 17 00:00:00 2001 From: Justin Swart Date: Mon, 15 Jun 2020 17:53:03 -0700 Subject: [PATCH 3/3] Don't apply transform for lights on --- .../Views/Controllers/EditorialProjectsViewController.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift b/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift index 0c1702d493..8af38d31f0 100644 --- a/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift +++ b/Kickstarter-iOS/Views/Controllers/EditorialProjectsViewController.swift @@ -183,12 +183,6 @@ public final class EditorialProjectsViewController: UIViewController { self?.setNeedsStatusBarAppearanceUpdate() } - self.viewModel.outputs.applyViewTransformsWithYOffset - .observeForControllerAction() - .observeValues { [weak self] y in - self?.applyViewTransforms(withYOffset: y) - } - self.editorialTitleLabel.rac.text = self.viewModel.outputs.titleLabelText self.closeButton.rac.tintColor = self.viewModel.outputs.closeButtonImageTintColor }