Skip to content

Commit

Permalink
update snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottkicks committed May 23, 2023
1 parent bc6989c commit a5e5070
Show file tree
Hide file tree
Showing 193 changed files with 12 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,43 +174,7 @@ internal final class CommentsViewControllerTests: TestCase {
}
}

func testView_CurrentUser_LoggedIn_IsBacking_CommentFlaggingEnabledFeatureFlag_True() {
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.commentFlaggingEnabled.rawValue: true]

let mockService =
MockService(fetchProjectCommentsEnvelopeResult: .success(CommentsEnvelope.multipleCommentTemplate))

let project = Project.template
|> \.personalization.isBacking .~ true

combos(Language.allLanguages, [Device.phone4_7inch, Device.pad]).forEach {
language, device in
withEnvironment(
apiService: mockService,
currentUser: .template,
language: language,
optimizelyClient: mockOptimizelyClient
) {
let controller = CommentsViewController.configuredWith(project: project)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = 1_100

self.scheduler.run()

assertSnapshot(
matching: parent.view,
as: .image,
named: "Comments - lang_\(language)_device_\(device)"
)
}
}
}

func testView_CurrentUser_LoggedIn_IsBacking_CommentFlaggingEnabledFeatureFlag_False() {
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.commentFlaggingEnabled.rawValue: false]

func testView_CurrentUser_LoggedIn_IsBacking() {
let mockService =
MockService(fetchProjectCommentsEnvelopeResult: .success(CommentsEnvelope.multipleCommentTemplate))

Expand All @@ -222,8 +186,7 @@ internal final class CommentsViewControllerTests: TestCase {
withEnvironment(
apiService: mockService,
currentUser: .template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let controller = CommentsViewController.configuredWith(project: project)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
Expand Down Expand Up @@ -294,11 +257,10 @@ internal final class CommentsViewControllerTests: TestCase {
}

func testCommentsViewControllerCreation_Success() {
let mockOptimizelyClient = MockOptimizelyClient()
let mockService = MockService(fetchProjectResult: .success(.template))

withEnvironment(
apiService: mockService, optimizelyClient: mockOptimizelyClient
apiService: mockService
) {
XCTAssert(commentsViewController(for: .template).isKind(of: CommentsViewController.self))
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
func testView_PledgeContext_AddNewCardNonLoadingState_Success() {
let response = UserEnvelope<GraphUser>(me: self.userWithCards)
let envelope = ClientSecretEnvelope(clientSecret: "test")
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.paymentSheetEnabled.rawValue: true]
let mockService = MockService(
createStripeSetupIntentResult: .success(envelope),
fetchGraphUserResult: .success(response)
Expand All @@ -42,8 +40,7 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
withEnvironment(
apiService: mockService,
currentUser: User.template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let controller = PledgePaymentMethodsViewController.instantiate()

Expand All @@ -70,8 +67,6 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {

func testView_PledgeContext_AddNewCardLoadingState_Success() {
let response = UserEnvelope<GraphUser>(me: self.userWithCards)
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.paymentSheetEnabled.rawValue: true]
/// Using .failure case to prevent real Stripe sheet from being shown.
let mockService = MockService(
createStripeSetupIntentResult: .failure(.couldNotParseJSON),
Expand All @@ -84,8 +79,7 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
withEnvironment(
apiService: mockService,
currentUser: User.template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let controller = PledgePaymentMethodsViewController.instantiate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,77 +151,12 @@ internal final class ProjectPageViewControllerTests: TestCase {
fetchProjectRewardsResult: .success([reward])
)

let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: true
]

combos(Language.allLanguages, [Device.phone4inch, Device.pad]).forEach { language, device in
withEnvironment(
apiService: mockService,
config: config,
currentUser: .template,
language: language,
optimizelyClient: mockOptimizelyClient
) {
let vc = ProjectPageViewController.configuredWith(
projectOrParam: .left(project), refTag: nil
)

let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)
parent.view.frame.size.height = device == .pad ? 1_200 : parent.view.frame.size.height

self.scheduler.run()

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
}
}

func testLoggedIn_Backer_LiveProject_NotShowingCampaign_Success() {
let config = Config.template
let reward = Reward.template
|> Reward.lens.title .~ "Magic Lamp"
let project = Project.cosmicSurgery
|> Project.lens.photo.full .~ ""
|> (Project.lens.creator.avatar .. User.Avatar.lens.small) .~ ""
|> Project.lens.personalization.isBacking .~ false
|> Project.lens.personalization.backing .~ nil
|> Project.lens.state .~ .live
|> Project.lens.stats.convertedPledgedAmount .~ 29_236
|> Project.lens.rewardData.rewards .~ []
|> \.extendedProjectProperties .~ self.extendedProjectProperties

let backing = Backing.template
|> Backing.lens.reward .~ reward

let projectPamphletData = Project.ProjectPamphletData(project: project, backingId: 1)
let projectAndEnvelope = ProjectAndBackingEnvelope(project: project, backing: backing)

let mockService = MockService(
fetchManagePledgeViewBackingResult: .success(projectAndEnvelope),
fetchProjectPamphletResult: .success(projectPamphletData),
fetchProjectRewardsResult: .success([reward])
)

let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: false
]

combos(Language.allLanguages, [Device.phone4inch, Device.pad]).forEach { language, device in
withEnvironment(
apiService: mockService,
config: config,
currentUser: .template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let vc = ProjectPageViewController.configuredWith(
projectOrParam: .left(project), refTag: nil
Expand Down Expand Up @@ -980,17 +915,10 @@ internal final class ProjectPageViewControllerTests: TestCase {
|> Project.lens.rewardData.rewards .~ []
|> \.extendedProjectProperties .~ self.extendedProjectProperties

let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: true
]

combos(Language.allLanguages, [Device.phone4inch, Device.pad]).forEach { language, device in
withEnvironment(
config: config,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let vc = ProjectPageViewController.configuredWith(
projectOrParam: .left(project), refTag: nil
Expand Down Expand Up @@ -1025,17 +953,10 @@ internal final class ProjectPageViewControllerTests: TestCase {
|> Project.lens.rewardData.rewards .~ []
|> \.extendedProjectProperties .~ self.extendedProjectProperties

let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: true
]

combos(Language.allLanguages, [Device.phone4inch, Device.pad]).forEach { language, device in
withEnvironment(
config: config,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let vc = ProjectPageViewController.configuredWith(
projectOrParam: .left(project), refTag: nil
Expand Down Expand Up @@ -1070,18 +991,11 @@ internal final class ProjectPageViewControllerTests: TestCase {
|> Project.lens.rewardData.rewards .~ []
|> \.extendedProjectProperties .~ self.extendedProjectProperties

let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: true
]

combos(Language.allLanguages, [Device.phone4inch, Device.pad]).forEach { language, device in
withEnvironment(
config: config,
currentUser: .template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let vc = ProjectPageViewController.configuredWith(
projectOrParam: .left(project), refTag: nil
Expand Down Expand Up @@ -1125,17 +1039,10 @@ internal final class ProjectPageViewControllerTests: TestCase {
|> Project.lens.rewardData.rewards .~ []
|> \.extendedProjectProperties .~ self.extendedProjectProperties

let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: true
]

combos(Language.allLanguages, [Device.phone4inch, Device.pad]).forEach { language, device in
withEnvironment(
config: config,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let vc = ProjectPageViewController.configuredWith(
projectOrParam: .left(project), refTag: nil
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions Kickstarter-iOS/Library/SharedFunctionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ internal final class SharedFunctionsTests: TestCase {
}

func testDiscoveryPageBackgroundColor() {
withEnvironment(optimizelyClient: optimizelyClient) {
XCTAssertEqual(discoveryPageBackgroundColor(), .ksr_white)
}
XCTAssertEqual(discoveryPageBackgroundColor(), .ksr_white)
}

func testSelectedRewardQuantities_NoAddOns() {
Expand Down Expand Up @@ -305,9 +303,7 @@ internal final class SharedFunctionsTests: TestCase {
}

func testIsNativeRiskMessagingControlEnabled() {
withEnvironment(optimizelyClient: optimizelyClient) {
XCTAssertTrue(isNativeRiskMessagingControlEnabled())
}
XCTAssertTrue(isNativeRiskMessagingControlEnabled())
}

func testRewardIsAvailable_NotLimitedBaseReward_NotBacked() {
Expand Down

0 comments on commit a5e5070

Please sign in to comment.