Skip to content

Commit 8e34e1f

Browse files
authored
Merge pull request #8730 from woocommerce/issue/8729-update-ipp-feedback-status
[IPPInAppFeedback] Update and save feedback status upon merchant submission
2 parents 288d41f + d025922 commit 8e34e1f

File tree

3 files changed

+118
-16
lines changed

3 files changed

+118
-16
lines changed

WooCommerce/Classes/ViewRelated/Orders/OrderListViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,7 @@ private extension OrderListViewController {
832832
let shareIPPFeedbackAction = TopBannerViewModel.ActionButton(title: Localization.shareFeedbackButton, action: { [weak self] _ in
833833
self?.displayIPPFeedbackBannerSurvey(survey: survey)
834834
self?.viewModel.IPPFeedbackBannerCTATapped(for: campaign)
835-
// We dismiss the banner at this point as we cannot know if the user successfully submitted it
836-
self?.viewModel.IPPFeedbackBannerWasDismissed(for: campaign)
835+
self?.viewModel.IPPFeedbackBannerWasSubmitted()
837836
})
838837

839838
let viewModel = TopBannerViewModel(

WooCommerce/Classes/ViewRelated/Orders/OrderListViewModel.swift

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,25 +224,17 @@ final class OrderListViewModel {
224224
stores.dispatch(action)
225225
}
226226

227-
// This is a temporary method in order to update the IPP feedback status to `.pending`, and
228-
// then load feedback visibility. We need to reset the banner status on UserDefaults for
229-
// the banner to appear again for testing purposes.
227+
// Requests if the In-Person Payments feedback banner should be shown,
228+
// in which case we proceed to sync the view model by fetching transactions
230229
private func syncIPPBannerVisibility() {
231-
let action = AppSettingsAction.updateFeedbackStatus(type: .inPersonPayments, status: .pending) { _ in
232-
self.loadIPPFeedbackBannerVisibility()
233-
self.fetchIPPTransactions()
234-
}
235-
stores.dispatch(action)
236-
}
237-
238-
private func loadIPPFeedbackBannerVisibility() {
239-
let action = AppSettingsAction.loadFeedbackVisibility(type: .inPersonPayments) { [weak self] result in
240-
switch result {
230+
let action = AppSettingsAction.loadFeedbackVisibility(type: .inPersonPayments) { [weak self] visibility in
231+
switch visibility {
241232
case .success(let visible):
242233
self?.hideIPPFeedbackBanner = !visible
234+
self?.fetchIPPTransactions()
243235
case .failure(let error):
244236
self?.hideIPPFeedbackBanner = true
245-
ServiceLocator.crashLogging.logError(error)
237+
DDLogError("Couldn't load feedback visibility. \(error)")
246238
}
247239
}
248240
self.stores.dispatch(action)
@@ -425,6 +417,22 @@ extension OrderListViewModel {
425417
func IPPFeedbackBannerWasDismissed(for campaign: FeatureAnnouncementCampaign) {
426418
dismissIPPFeedbackBanner(remindAfterDays: nil, campaign: campaign)
427419
}
420+
421+
func IPPFeedbackBannerWasSubmitted() {
422+
// Updates the IPP feedback banner status as given
423+
let updateFeedbackStatus = AppSettingsAction.updateFeedbackStatus(type: .inPersonPayments, status: .given(Date())) { [weak self] _ in
424+
self?.hideIPPFeedbackBanner = true
425+
}
426+
stores.dispatch(updateFeedbackStatus)
427+
428+
// Updates the IPP feedback banner status to not be reminded again
429+
let updateBannerVisibility = AppSettingsAction.setFeatureAnnouncementDismissed(
430+
campaign: .inPersonPaymentsPowerUsers,
431+
remindAfterDays: nil,
432+
onCompletion: nil
433+
)
434+
stores.dispatch(updateBannerVisibility)
435+
}
428436
}
429437

430438
// MARK: - Remote Notifications Observation

WooCommerce/WooCommerceTests/ViewRelated/Orders/OrderListViewModelTests.swift

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,101 @@ final class OrderListViewModelTests: XCTestCase {
542542
assertEqual(expectedSource, actualProperties["source"] as? String)
543543
assertEqual(expectedRemindLater, actualProperties["remind_later"] as? Bool)
544544
}
545+
546+
func test_IPPFeedbackBannerWasSubmitted_hides_banner_after_being_called() {
547+
// Given
548+
let viewModel = OrderListViewModel(siteID: siteID, filters: nil)
549+
550+
// When
551+
viewModel.IPPFeedbackBannerWasSubmitted()
552+
viewModel.hasErrorLoadingData = false
553+
viewModel.hideOrdersBanners = true
554+
555+
// Then
556+
waitUntil {
557+
viewModel.topBanner == .none
558+
}
559+
}
560+
561+
func test_IPPFeedbackBannerWasSubmitted_then_it_calls_updateFeedbackStatus_with_right_parameters() {
562+
// Given
563+
let viewModel = OrderListViewModel(siteID: siteID, stores: stores, filters: nil)
564+
var updatedFeedbackStatus: FeedbackSettings.Status?
565+
var receivedFeedbackType: FeedbackType?
566+
567+
// When
568+
stores.whenReceivingAction(ofType: AppSettingsAction.self) { action in
569+
switch action {
570+
case let .updateFeedbackStatus(type, status, onCompletion):
571+
receivedFeedbackType = type
572+
updatedFeedbackStatus = status
573+
onCompletion(.success(()))
574+
default:
575+
break
576+
}
577+
}
578+
579+
viewModel.activate()
580+
viewModel.IPPFeedbackBannerWasSubmitted()
581+
582+
// Then
583+
XCTAssertTrue(viewModel.hideIPPFeedbackBanner)
584+
585+
XCTAssertEqual(receivedFeedbackType, .inPersonPayments)
586+
587+
switch updatedFeedbackStatus {
588+
case .given:
589+
break
590+
default:
591+
XCTFail()
592+
}
593+
}
594+
595+
func test_IPPFeedbackBannerWasSubmitted_then_it_calls_setFeatureAnnouncementDismissed_with_right_parameters() {
596+
// Given
597+
let viewModel = OrderListViewModel(siteID: siteID, stores: stores, filters: nil)
598+
var receivedCampaign: FeatureAnnouncementCampaign?
599+
var receivedRemindAfterDays: Int?
600+
601+
// When
602+
stores.whenReceivingAction(ofType: AppSettingsAction.self) { action in
603+
switch action {
604+
case let .setFeatureAnnouncementDismissed(campaign, remindAfterDays, _):
605+
receivedRemindAfterDays = remindAfterDays
606+
receivedCampaign = campaign
607+
default:
608+
break
609+
}
610+
}
611+
612+
viewModel.activate()
613+
viewModel.IPPFeedbackBannerWasSubmitted()
614+
615+
// Then
616+
XCTAssertEqual(receivedCampaign, .inPersonPaymentsPowerUsers)
617+
XCTAssertNil(receivedRemindAfterDays)
618+
}
619+
620+
func test_feedback_status_when_IPPFeedbackBannerWasSubmitted_is_not_called_then_feedback_status_is_nil() {
621+
// Given
622+
let viewModel = OrderListViewModel(siteID: siteID, stores: stores, filters: nil)
623+
var feedbackStatus: FeedbackSettings.Status?
624+
625+
// When
626+
stores.whenReceivingAction(ofType: AppSettingsAction.self) { action in
627+
switch action {
628+
case let .updateFeedbackStatus(.inPersonPayments, status, onCompletion):
629+
feedbackStatus = status
630+
onCompletion(.success(()))
631+
default:
632+
break
633+
}
634+
}
635+
viewModel.activate()
636+
637+
// Then
638+
assertEqual(nil, feedbackStatus)
639+
}
545640
}
546641

547642
// MARK: - Helpers

0 commit comments

Comments
 (0)