Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NT-400] Pledge View attributedString crash fix #900

Merged
merged 4 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ final class PledgeViewControllerTests: TestCase {
controller.configureWith(project: .template, reward: reward, refTag: nil, context: .update)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)

self.scheduler.advance(by: .milliseconds(10))
self.scheduler.run()

FBSnapshotVerifyView(parent.view, identifier: "lang_\(language)_device_\(device)")
Expand Down
1 change: 1 addition & 0 deletions Library/ViewModels/PledgeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge
project,
project.takeWhen(self.traitCollectionDidChangeSignal)
)
.ksr_debounce(.milliseconds(10), on: AppEnvironment.current.scheduler)
.map(attributedConfirmationString(with:))
.skipNil()

Expand Down
49 changes: 49 additions & 0 deletions Library/ViewModels/PledgeViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class PledgeViewModelTests: TestCase {
private let configureWithPledgeViewDataReward = TestObserver<Reward, Never>()

private let confirmationLabelAttributedText = TestObserver<NSAttributedString, Never>()
private let confirmationLabelText = TestObserver<String, Never>()
private let confirmationLabelHidden = TestObserver<Bool, Never>()

private let continueViewHidden = TestObserver<Bool, Never>()
Expand Down Expand Up @@ -82,6 +83,8 @@ final class PledgeViewModelTests: TestCase {
self.vm.outputs.submitButtonHidden.observe(self.submitButtonHidden.observer)
self.vm.outputs.submitButtonTitle.observe(self.submitButtonTitle.observer)
self.vm.outputs.confirmationLabelAttributedText.observe(self.confirmationLabelAttributedText.observer)
self.vm.outputs.confirmationLabelAttributedText.map { $0.string }
.observe(self.confirmationLabelText.observer)
self.vm.outputs.confirmationLabelHidden.observe(self.confirmationLabelHidden.observer)

self.vm.outputs.continueViewHidden.observe(self.continueViewHidden.observer)
Expand Down Expand Up @@ -237,6 +240,52 @@ final class PledgeViewModelTests: TestCase {
}
}

func testUpdateContext_ConfirmationLabel() {
let dateComponents = DateComponents()
|> \.month .~ 11
|> \.day .~ 1
|> \.year .~ 2_019
|> \.timeZone .~ TimeZone.init(secondsFromGMT: 0)

let calendar = Calendar(identifier: .gregorian)
|> \.timeZone .~ TimeZone.init(secondsFromGMT: 0)!

withEnvironment(calendar: calendar, locale: Locale(identifier: "en")) {
let date = AppEnvironment.current.calendar.date(from: dateComponents)

let project = Project.template
|> Project.lens.dates.deadline .~ date!.timeIntervalSince1970
let reward = Reward.template
|> Reward.lens.shipping.enabled .~ true

self.vm.inputs.configureWith(project: project, reward: reward, refTag: .projectPage, context: .update)
self.vm.inputs.viewDidLoad()

self.confirmationLabelHidden.assertValues([false])
self.confirmationLabelAttributedText.assertDidNotEmitValue()

scheduler.advance(by: .milliseconds(10))

self.confirmationLabelAttributedText.assertValueCount(1)
self.confirmationLabelText.assertValues([
"If the project reaches its funding goal, you will be charged on November 1, 2019."
])

self.vm.inputs.traitCollectionDidChange()
self.vm.inputs.traitCollectionDidChange()

self.confirmationLabelAttributedText.assertValueCount(1, "Debounces signals")

scheduler.advance(by: .milliseconds(10))

self.confirmationLabelAttributedText.assertValueCount(2)
self.confirmationLabelText.assertValues([
"If the project reaches its funding goal, you will be charged on November 1, 2019.",
"If the project reaches its funding goal, you will be charged on November 1, 2019."
])
}
}

func testChangePaymentMethodContext() {
let mockService = MockService(serverConfig: ServerConfig.staging)

Expand Down