Skip to content

Commit

Permalink
Fix tests affected by adding extra param to ThanksPageData
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-at-kickstarter committed Mar 5, 2024
1 parent 13af2a3 commit fa0fbce
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ThanksViewControllerTests: TestCase {
let project = Project.cosmicSurgery
|> Project.lens.id .~ 3

let controller = ThanksViewController.configured(with: (project, Reward.template, nil))
let controller = ThanksViewController.configured(with: (project, Reward.template, nil, 1))

let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = 1_000
Expand Down
6 changes: 3 additions & 3 deletions Library/ViewModels/PledgeViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ final class PledgeViewModelTests: TestCase {

self.vm.outputs.goToRiskMessagingModal.observe(self.goToRiskMessagingModal.observer)

self.vm.outputs.goToThanks.map(first).observe(self.goToThanksProject.observer)
self.vm.outputs.goToThanks.map(second).observe(self.goToThanksReward.observer)
self.vm.outputs.goToThanks.map(third).observe(self.goToThanksCheckoutData.observer)
self.vm.outputs.goToThanks.map { $0.project }.observe(self.goToThanksProject.observer)
self.vm.outputs.goToThanks.map { $0.reward }.observe(self.goToThanksReward.observer)
self.vm.outputs.goToThanks.map { $0.checkoutData }.observe(self.goToThanksCheckoutData.observer)
self.vm.outputs.localPickupViewHidden.observe(self.localPickupViewHidden.observer)

self.vm.outputs.notifyDelegateUpdatePledgeDidSucceedWithMessage
Expand Down
36 changes: 22 additions & 14 deletions Library/ViewModels/ThanksViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ final class ThanksViewModelTests: TestCase {
self.vm.outputs.updateUserInEnvironment.observe(self.updateUserInEnvironment.observer)
}

private func thanksPageData(
project: Project = Project.template,
reward: Reward = Reward.template,
checkoutData: KSRAnalytics.CheckoutPropertiesData? = nil
) -> ThanksPageData {
return (project, reward, checkoutData, 1)
}

func testDismissToRootViewController() {
self.vm.inputs.configure(with: (Project.template, Reward.template, nil))
self.vm.inputs.configure(with: self.thanksPageData())
self.vm.inputs.viewDidLoad()

self.vm.inputs.closeButtonTapped()
Expand All @@ -71,7 +79,7 @@ final class ThanksViewModelTests: TestCase {
fetchGraphCategoryResult: .success(self.categoryEnvelope),
fetchDiscoveryResponse: response
)) {
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

scheduler.advance()
Expand All @@ -94,7 +102,7 @@ final class ThanksViewModelTests: TestCase {

func testDisplayBackedProjectText() {
let project = Project.template |> \.category .~ .games
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: self.thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

self.backedProjectText.assertValues(
Expand All @@ -109,7 +117,7 @@ final class ThanksViewModelTests: TestCase {
withEnvironment(currentUser: .template) {
showRatingAlert.assertValueCount(0, "Rating Alert does not emit")

self.vm.inputs.configure(with: (Project.template, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData())
self.vm.inputs.viewDidLoad()

showRatingAlert.assertValueCount(1, "Rating Alert emits when view did load")
Expand All @@ -130,7 +138,7 @@ final class ThanksViewModelTests: TestCase {
)

let project = Project.template |> Project.lens.category .~ .games
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

showRatingAlert.assertValueCount(0, "Rating alert does not show on games project")
Expand All @@ -146,7 +154,7 @@ final class ThanksViewModelTests: TestCase {
let secondShowGamesNewsletterAlert = TestObserver<(), Never>()
secondVM.outputs.showGamesNewsletterAlert.observe(secondShowGamesNewsletterAlert.observer)

secondVM.inputs.configure(with: (project, Reward.template, nil))
secondVM.inputs.configure(with: thanksPageData(project: project))
secondVM.inputs.viewDidLoad()

secondShowRatingAlert.assertValueCount(1, "Rating alert shows on games project")
Expand All @@ -160,7 +168,7 @@ final class ThanksViewModelTests: TestCase {
let project = Project.template |> Project.lens.category .~ .games

withEnvironment(currentUser: user) {
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

showGamesNewsletterAlert.assertValueCount(0, "Games alert does not show on games project")
Expand All @@ -171,7 +179,7 @@ final class ThanksViewModelTests: TestCase {
let project = Project.template |> Project.lens.category .~ .games

withEnvironment(currentUser: .template) {
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

showGamesNewsletterAlert.assertValueCount(1)
Expand Down Expand Up @@ -219,7 +227,7 @@ final class ThanksViewModelTests: TestCase {
let project = Project.template |> Project.lens.category .~ .games

withEnvironment(countryCode: "DE", currentUser: User.template) {
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

showGamesNewsletterAlert.assertValueCount(1)
Expand Down Expand Up @@ -251,7 +259,7 @@ final class ThanksViewModelTests: TestCase {
fetchDiscoveryResponse: response
)
) {
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

scheduler.advance()
Expand Down Expand Up @@ -291,7 +299,7 @@ final class ThanksViewModelTests: TestCase {
fetchGraphCategoryResult: .success(self.categoryEnvelope),
fetchDiscoveryResponse: response
)) {
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

scheduler.advance()
Expand All @@ -305,7 +313,7 @@ final class ThanksViewModelTests: TestCase {
let project = Project.template |> Project.lens.category .~ .games

withEnvironment(apiService: MockService(fetchDiscoveryResponse: response)) {
self.vm.inputs.configure(with: (project, Reward.template, nil))
self.vm.inputs.configure(with: thanksPageData(project: project))
self.vm.inputs.viewDidLoad()

scheduler.advance()
Expand Down Expand Up @@ -333,7 +341,7 @@ final class ThanksViewModelTests: TestCase {
)

(self.appTrackingTransparency as? MockAppTrackingTransparency)?.shouldRequestAuthStatus = false
self.vm.inputs.configure(with: (Project.template, Reward.template, checkoutData))
self.vm.inputs.configure(with: self.thanksPageData(checkoutData: checkoutData))
self.vm.inputs.viewDidLoad()

XCTAssertNil(self.segmentTrackingClient.properties.last)
Expand All @@ -357,7 +365,7 @@ final class ThanksViewModelTests: TestCase {
userHasStoredApplePayCard: true
)

self.vm.inputs.configure(with: (Project.template, Reward.template, checkoutData))
self.vm.inputs.configure(with: self.thanksPageData(checkoutData: checkoutData))
self.vm.inputs.viewDidLoad()

let segmentClientProps = self.segmentTrackingClient.properties.last
Expand Down

0 comments on commit fa0fbce

Please sign in to comment.