diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/BlogDashboardPersonalizeCardCell.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/BlogDashboardPersonalizeCardCell.swift index ed11b9aa3543..15d1c343cee6 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/BlogDashboardPersonalizeCardCell.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/BlogDashboardPersonalizeCardCell.swift @@ -78,7 +78,7 @@ final class BlogDashboardPersonalizeCardCell: DashboardCollectionViewCell { } WPAnalytics.track(.dashboardCardItemTapped, properties: ["type": DashboardCard.personalize.rawValue], blog: blog) let viewController = UIHostingController(rootView: NavigationView { - BlogDashboardPersonalizationView(viewModel: .init(service: .init(siteID: siteID))) + BlogDashboardPersonalizationView(viewModel: .init(service: .init(siteID: siteID), quickStartType: blog.quickStartType)) }.navigationViewStyle(.stack)) // .stack is required for iPad if UIDevice.isPad() { viewController.modalPresentationStyle = .formSheet diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/DashboardCard.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/DashboardCard.swift index 054247c49345..070ea9e501c2 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/DashboardCard.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/DashboardCard.swift @@ -156,6 +156,7 @@ enum DashboardCard: String, CaseIterable { .prompts, .pages, .activityLog + .quickStart ] /// Includes all cards that should be fetched from the backend diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Service/BlogDashboardPersonalizationService.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Service/BlogDashboardPersonalizationService.swift index f90476fb037b..a5a9eed27e23 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Service/BlogDashboardPersonalizationService.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Service/BlogDashboardPersonalizationService.swift @@ -62,7 +62,9 @@ private func makeKey(for card: DashboardCard) -> String? { return "activity-log-card-enabled-site-settings" case .pages: return "pages-card-enabled-site-settings" - case .quickStart, .jetpackBadge, .jetpackInstall, .nextPost, .createPost, .failure, .ghost, .personalize, .empty: + case .quickStart: + return "quick-start-card-enabled-site-settings" + case .jetpackBadge, .jetpackInstall, .nextPost, .createPost, .failure, .ghost, .personalize, .empty: return nil } } diff --git a/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationView.swift b/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationView.swift index 27101c564dcf..db45dfa0cd70 100644 --- a/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationView.swift +++ b/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationView.swift @@ -52,7 +52,7 @@ private extension BlogDashboardPersonalizationView { struct BlogDashboardPersonalizationView_Previews: PreviewProvider { static var previews: some View { NavigationView { - BlogDashboardPersonalizationView(viewModel: .init(service: .init(repository: UserDefaults.standard, siteID: 1))) + BlogDashboardPersonalizationView(viewModel: .init(service: .init(repository: UserDefaults.standard, siteID: 1), quickStartType: .newSite)) } } } diff --git a/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationViewModel.swift b/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationViewModel.swift index 3b0e090e9bc3..66f1bd18711b 100644 --- a/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationViewModel.swift +++ b/WordPress/Classes/ViewRelated/Blog/BlogPersonalization/BlogDashboardPersonalizationViewModel.swift @@ -3,9 +3,13 @@ import SwiftUI final class BlogDashboardPersonalizationViewModel: ObservableObject { let cards: [BlogDashboardPersonalizationCardCellViewModel] - init(service: BlogDashboardPersonalizationService) { - self.cards = DashboardCard.personalizableCards.map { - BlogDashboardPersonalizationCardCellViewModel(card: $0, service: service) + init(service: BlogDashboardPersonalizationService, quickStartType: QuickStartType) { + self.cards = DashboardCard.personalizableCards.compactMap { + if $0 == .quickStart && quickStartType == .undefined { + return nil + } + let title = $0.getLocalizedTitle(quickStartType: quickStartType) + return BlogDashboardPersonalizationCardCellViewModel(card: $0, title: title, service: service) } } } @@ -15,7 +19,7 @@ final class BlogDashboardPersonalizationCardCellViewModel: ObservableObject, Ide private let service: BlogDashboardPersonalizationService var id: DashboardCard { card } - var title: String { card.localizedTitle } + let title: String var isOn: Bool { get { service.isEnabled(card) } @@ -25,14 +29,15 @@ final class BlogDashboardPersonalizationCardCellViewModel: ObservableObject, Ide } } - init(card: DashboardCard, service: BlogDashboardPersonalizationService) { + init(card: DashboardCard, title: String, service: BlogDashboardPersonalizationService) { self.card = card + self.title = title self.service = service } } private extension DashboardCard { - var localizedTitle: String { + func getLocalizedTitle(quickStartType: QuickStartType) -> String { switch self { case .prompts: return NSLocalizedString("personalizeHome.dashboardCard.prompts", value: "Blogging prompts", comment: "Card title for the pesonalization menu") @@ -48,7 +53,17 @@ private extension DashboardCard { return NSLocalizedString("personalizeHome.dashboardCard.activityLog", value: "Recent activity", comment: "Card title for the pesonalization menu") case .pages: return NSLocalizedString("personalizeHome.dashboardCard.pages", value: "Pages", comment: "Card title for the pesonalization menu") - case .quickStart, .nextPost, .createPost, .ghost, .failure, .personalize, .jetpackBadge, .jetpackInstall, .domainsDashboardCard, .freeToPaidPlansDashboardCard, .domainRegistration, .empty: + case .quickStart: + switch quickStartType { + case .undefined: + assertionFailure(".quickStart card should only appear in the personalization menu if there are remaining steps") + return "" + case .existingSite: + return NSLocalizedString("personalizeHome.dashboardCard.nextSteps", value: "Get to know the app", comment: "Card title for the pesonalization menu") + case .newSite: + return NSLocalizedString("personalizeHome.dashboardCard.nextSteps", value: "Next steps", comment: "Card title for the pesonalization menu") + } + case .nextPost, .createPost, .ghost, .failure, .personalize, .jetpackBadge, .jetpackInstall, .empty, .domainsDashboardCard: assertionFailure("\(self) card should not appear in the personalization menus") return "" // These cards don't appear in the personalization menus } diff --git a/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationServiceTests.swift b/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationServiceTests.swift index aaae265862df..fb20d0e08c61 100644 --- a/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationServiceTests.swift +++ b/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationServiceTests.swift @@ -44,4 +44,12 @@ final class BlogDashboardPersonalizationServiceTests: XCTestCase { // Then settings for site 1 are ignored XCTAssertTrue(service.isEnabled(.quickStart)) } + + func testThatUserDefaultsKeysAreSpecifiedForAllPersonalizableCards() { + let service = BlogDashboardPersonalizationService(repository: repository, siteID: 1) + for card in DashboardCard.personalizableCards { + service.setEnabled(false, for: card) + XCTAssertFalse(service.isEnabled(card)) + } + } } diff --git a/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationViewModelTests.swift b/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationViewModelTests.swift index 4c8ea5bb8735..2d787dcbb6b2 100644 --- a/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationViewModelTests.swift +++ b/WordPress/WordPressTest/Dashboard/BlogDashboardPersonalizationViewModelTests.swift @@ -12,7 +12,7 @@ final class BlogDashboardPersonalizationViewModelTests: XCTestCase { override func setUp() { super.setUp() - viewModel = BlogDashboardPersonalizationViewModel(service: service) + viewModel = BlogDashboardPersonalizationViewModel(service: service, quickStartType: .undefined) } func testThatCardStateIsToggled() throws { @@ -30,4 +30,23 @@ final class BlogDashboardPersonalizationViewModelTests: XCTestCase { XCTAssertFalse(cardViewModel.isOn) XCTAssertFalse(service.isEnabled(card), "Service wasn't updated") } + + func testThatAllCardsHaveTitles() { + for card in viewModel.cards { + XCTAssertTrue(!card.title.isEmpty) + } + } + + + func testThatQuickStartCardsIsNotDisplayedWhenTourIsActive() { + // Given + viewModel = BlogDashboardPersonalizationViewModel(service: service, quickStartType: .newSite) + + // Then + XCTAssertTrue(viewModel.cards.contains(where: { $0.id == .quickStart })) + } + + func testThatQuickStartCardsIsNotDisplayedWhenNoTourIsActive() { + XCTAssertFalse(viewModel.cards.contains(where: { $0.id == .quickStart })) + } }