-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MBL-1604] Show bonus in add-ons (#2129)
* Show (non-functional) bonus support * Wire up bonus support * Validate bonus amount * Use bonus amount in confirm details screen * Copy add ons snapshot tests for no shipping case * Add tests * Update button cta and rerecord snapshots * Add ticket number in TODO
- Loading branch information
Showing
29 changed files
with
450 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
279 changes: 279 additions & 0 deletions
279
...s/RewardAddOnSelection/Controller/RewardAddOnSelectionNoShippingViewControllerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
@testable import Kickstarter_Framework | ||
@testable import KsApi | ||
@testable import Library | ||
import Prelude | ||
import SnapshotTesting | ||
import UIKit | ||
|
||
final class RewardAddOnSelectionNoShippingViewControllerTests: TestCase { | ||
override func setUp() { | ||
super.setUp() | ||
|
||
AppEnvironment.pushEnvironment(mainBundle: Bundle.framework) | ||
UIView.setAnimationsEnabled(false) | ||
} | ||
|
||
override func tearDown() { | ||
AppEnvironment.popEnvironment() | ||
UIView.setAnimationsEnabled(true) | ||
|
||
super.tearDown() | ||
} | ||
|
||
func testView() { | ||
let reward = Reward.template | ||
|> Reward.lens.shipping.enabled .~ false | ||
|> Reward.lens.localPickup .~ nil | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let noShippingAddOn = Reward.template | ||
|> Reward.lens.shipping.enabled .~ false | ||
|> Reward.lens.shipping.preference .~ Reward.Shipping.Preference.none | ||
|> Reward.lens.localPickup .~ nil | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let project = Project.template | ||
|> Project.lens.rewardData.rewards .~ [reward] | ||
|> Project.lens.rewardData.addOns .~ [noShippingAddOn] | ||
|
||
let mockService = MockService(fetchRewardAddOnsSelectionViewRewardsResult: .success(project)) | ||
|
||
let mockRemoteConfigClient = MockRemoteConfigClient() | ||
|> \.features .~ [RemoteConfigFeature.noShippingAtCheckout.rawValue: true] | ||
|
||
orthogonalCombos(Language.allLanguages, Device.allCases).forEach { language, device in | ||
withEnvironment( | ||
apiService: mockService, | ||
language: language, | ||
remoteConfigClient: mockRemoteConfigClient | ||
) { | ||
let controller = RewardAddOnSelectionNoShippingViewController.instantiate() | ||
|
||
let data = PledgeViewData( | ||
project: project, | ||
rewards: [reward], | ||
selectedShippingRule: nil, | ||
selectedQuantities: [:], | ||
selectedLocationId: nil, | ||
refTag: nil, | ||
context: .pledge | ||
) | ||
controller.configure(with: data) | ||
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller) | ||
parent.view.frame.size.height = 600 | ||
|
||
self.scheduler.advance() | ||
|
||
assertSnapshot( | ||
matching: parent.view, | ||
as: .image(perceptualPrecision: 0.98), | ||
named: "lang_\(language)_device_\(device)" | ||
) | ||
} | ||
} | ||
} | ||
|
||
func testView_EmptyState() { | ||
let shippingRules = [ | ||
ShippingRule.template | ||
|> ShippingRule.lens.location .~ .brooklyn, | ||
ShippingRule.template | ||
|> ShippingRule.lens.location .~ .canada, | ||
ShippingRule.template | ||
|> ShippingRule.lens.location .~ .australia | ||
] | ||
|
||
let shippingRule = ShippingRule.template | ||
|> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 55) | ||
|
||
let reward = Reward.template | ||
|> Reward.lens.shipping.enabled .~ true | ||
|> Reward.lens.shipping.preference .~ .restricted | ||
|> Reward.lens.id .~ 99 | ||
|> Reward.lens.shippingRules .~ [shippingRule] | ||
|> Reward.lens.localPickup .~ nil | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let shippingAddOn1 = Reward.template | ||
|> Reward.lens.id .~ 2 | ||
|> Reward.lens.shipping.enabled .~ true | ||
|> Reward.lens.shippingRules .~ [ | ||
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 99) | ||
] | ||
|> Reward.lens.localPickup .~ nil | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let shippingAddOn2 = Reward.template | ||
|> Reward.lens.id .~ 3 | ||
|> Reward.lens.shipping.enabled .~ true | ||
|> Reward.lens.shippingRules .~ [ | ||
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 99) | ||
] | ||
|> Reward.lens.localPickup .~ nil | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let shippingAddOn3 = Reward.template | ||
|> Reward.lens.id .~ 4 | ||
|> Reward.lens.shipping.enabled .~ true | ||
|> Reward.lens.shippingRules .~ [ | ||
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 3) | ||
] | ||
|> Reward.lens.localPickup .~ nil | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let shippingAddOn4 = Reward.template | ||
|> Reward.lens.id .~ 5 | ||
|> Reward.lens.shipping.enabled .~ true | ||
|> Reward.lens.shippingRules .~ [ | ||
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 3) | ||
] | ||
|> Reward.lens.localPickup .~ nil | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let project = Project.template | ||
|> Project.lens.rewardData.rewards .~ [reward] | ||
|> Project.lens.rewardData.addOns .~ [ | ||
shippingAddOn1, | ||
shippingAddOn2, | ||
shippingAddOn3, | ||
shippingAddOn4 | ||
] | ||
|
||
let mockService = MockService( | ||
fetchShippingRulesResult: .success(shippingRules), | ||
fetchRewardAddOnsSelectionViewRewardsResult: .success(project) | ||
) | ||
|
||
let mockRemoteConfigClient = MockRemoteConfigClient() | ||
|> \.features .~ [RemoteConfigFeature.noShippingAtCheckout.rawValue: true] | ||
|
||
orthogonalCombos(Language.allLanguages, Device.allCases).forEach { language, device in | ||
withEnvironment( | ||
apiService: mockService, | ||
language: language, | ||
remoteConfigClient: mockRemoteConfigClient | ||
) { | ||
let controller = RewardAddOnSelectionNoShippingViewController.instantiate() | ||
let data = PledgeViewData( | ||
project: project, | ||
rewards: [reward], | ||
selectedShippingRule: nil, | ||
selectedQuantities: [:], | ||
selectedLocationId: nil, | ||
refTag: nil, | ||
context: .pledge | ||
) | ||
controller.configure(with: data) | ||
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller) | ||
parent.view.frame.size.height = 600 | ||
|
||
self.scheduler.advance() | ||
|
||
self.scheduler.advance(by: .seconds(1)) | ||
|
||
assertSnapshot( | ||
matching: parent.view, | ||
as: .image(perceptualPrecision: 0.98), | ||
named: "lang_\(language)_device_\(device)" | ||
) | ||
} | ||
} | ||
} | ||
|
||
func testView_Error() { | ||
let reward = Reward.template | ||
|> Reward.lens.shipping.enabled .~ false | ||
|> Reward.lens.localPickup .~ nil | ||
let project = Project.template | ||
|
||
let mockService = MockService(fetchRewardAddOnsSelectionViewRewardsResult: .failure(.couldNotParseJSON)) | ||
|
||
let mockRemoteConfigClient = MockRemoteConfigClient() | ||
|> \.features .~ [RemoteConfigFeature.noShippingAtCheckout.rawValue: true] | ||
|
||
orthogonalCombos(Language.allLanguages, Device.allCases).forEach { language, device in | ||
withEnvironment( | ||
apiService: mockService, | ||
language: language, | ||
remoteConfigClient: mockRemoteConfigClient | ||
) { | ||
let controller = RewardAddOnSelectionNoShippingViewController.instantiate() | ||
|
||
let data = PledgeViewData( | ||
project: project, | ||
rewards: [reward], | ||
selectedShippingRule: nil, | ||
selectedQuantities: [:], | ||
selectedLocationId: nil, | ||
refTag: nil, | ||
context: .pledge | ||
) | ||
controller.configure(with: data) | ||
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller) | ||
parent.view.frame.size.height = 600 | ||
|
||
self.scheduler.advance() | ||
|
||
assertSnapshot( | ||
matching: parent.view, | ||
as: .image(perceptualPrecision: 0.98), | ||
named: "lang_\(language)_device_\(device)" | ||
) | ||
} | ||
} | ||
} | ||
|
||
func testView_NoShippingWithLocalPickup_Success() { | ||
let reward = Reward.template | ||
|> Reward.lens.shipping.enabled .~ false | ||
|> Reward.lens.localPickup .~ .australia | ||
|> Reward.lens.shipping.preference .~ .local | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let noShippingAddOn = Reward.template | ||
|> Reward.lens.shipping.enabled .~ false | ||
|> Reward.lens.shipping.preference .~ .local | ||
|> Reward.lens.localPickup .~ .australia | ||
|> Reward.lens.isAvailable .~ true | ||
|
||
let project = Project.template | ||
|> Project.lens.rewardData.rewards .~ [reward] | ||
|> Project.lens.rewardData.addOns .~ [noShippingAddOn] | ||
|
||
let mockService = MockService(fetchRewardAddOnsSelectionViewRewardsResult: .success(project)) | ||
|
||
let mockRemoteConfigClient = MockRemoteConfigClient() | ||
|> \.features .~ [RemoteConfigFeature.noShippingAtCheckout.rawValue: true] | ||
|
||
orthogonalCombos(Language.allLanguages, [Device.phone5_8inch, Device.pad]).forEach { language, device in | ||
withEnvironment( | ||
apiService: mockService, | ||
language: language, | ||
remoteConfigClient: mockRemoteConfigClient | ||
) { | ||
let controller = RewardAddOnSelectionNoShippingViewController.instantiate() | ||
|
||
let data = PledgeViewData( | ||
project: project, | ||
rewards: [reward], | ||
selectedShippingRule: nil, | ||
selectedQuantities: [:], | ||
selectedLocationId: nil, | ||
refTag: nil, | ||
context: .pledge | ||
) | ||
controller.configure(with: data) | ||
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller) | ||
parent.view.frame.size.height = 600 | ||
|
||
self.scheduler.advance() | ||
|
||
assertSnapshot( | ||
matching: parent.view, | ||
as: .image(perceptualPrecision: 0.98), | ||
named: "lang_\(language)_device_\(device)" | ||
) | ||
} | ||
} | ||
} | ||
} |
Binary file added
BIN
+71.4 KB
...OnSelectionNoShippingViewControllerTests/testView.lang_de_device_phone4inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+73.7 KB
...SelectionNoShippingViewControllerTests/testView.lang_en_device_phone4_7inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+80.6 KB
...SelectionNoShippingViewControllerTests/testView.lang_es_device_phone5_5inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+76 KB
...SelectionNoShippingViewControllerTests/testView.lang_fr_device_phone5_8inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+106 KB
...wardAddOnSelectionNoShippingViewControllerTests/testView.lang_ja_device_pad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+74.5 KB
...NoShippingViewControllerTests/testView_EmptyState.lang_de_device_phone4inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+70.4 KB
...ShippingViewControllerTests/testView_EmptyState.lang_en_device_phone4_7inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+79.4 KB
...ShippingViewControllerTests/testView_EmptyState.lang_es_device_phone5_5inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+77.7 KB
...ShippingViewControllerTests/testView_EmptyState.lang_fr_device_phone5_8inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+113 KB
...lectionNoShippingViewControllerTests/testView_EmptyState.lang_ja_device_pad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+66.1 KB
...ctionNoShippingViewControllerTests/testView_Error.lang_de_device_phone4inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+62.4 KB
...ionNoShippingViewControllerTests/testView_Error.lang_en_device_phone4_7inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+67.2 KB
...ionNoShippingViewControllerTests/testView_Error.lang_es_device_phone5_5inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+72.9 KB
...ionNoShippingViewControllerTests/testView_Error.lang_fr_device_phone5_8inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+99.1 KB
...dOnSelectionNoShippingViewControllerTests/testView_Error.lang_ja_device_pad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+78.3 KB
...ests/testView_NoShippingWithLocalPickup_Success.lang_de_device_phone5_8inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+96.4 KB
...ntrollerTests/testView_NoShippingWithLocalPickup_Success.lang_en_device_pad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+78.2 KB
...ests/testView_NoShippingWithLocalPickup_Success.lang_es_device_phone5_8inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+99.4 KB
...ntrollerTests/testView_NoShippingWithLocalPickup_Success.lang_fr_device_pad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+83.1 KB
...ests/testView_NoShippingWithLocalPickup_Success.lang_ja_device_phone5_8inch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.