-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Domains Dashboard Card: Presentation Criteria (#20423)
* Implement directDomainPurchaseDashboardCard remote feature flag * Created DomainsDashboardCardHelper with shouldShowCard logic - Added blog and user conditions based on which we show domains dashboard card - Added DomainsDashboardCardHelperTests to tests the different cases * Integrate domain dashboard card presentation logic into DashboardCard * Use blog.domainList instead of blog.domains to only include non-wpcom domains * Refresh domains when blog is synced Until now, domains were only refreshed when the blog details were opened, however, now we need to have blog domains list up-to-date * Remove extra empty line
- Loading branch information
Showing
8 changed files
with
181 additions
and
1 deletion.
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
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
34 changes: 34 additions & 0 deletions
34
...ss/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Domains/DomainsDashboardCardHelper.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,34 @@ | ||
import Foundation | ||
|
||
final class DomainsDashboardCardHelper { | ||
|
||
/// Checks conditions for showing domain dashboard cards | ||
static func shouldShowCard( | ||
for blog: Blog, | ||
isJetpack: Bool = AppConfiguration.isJetpack, | ||
featureFlagEnabled: Bool = RemoteFeatureFlag.directDomainsPurchaseDashboardCard.enabled() | ||
) -> Bool { | ||
guard isJetpack, featureFlagEnabled else { | ||
return false | ||
} | ||
|
||
let isHostedAtWPcom = blog.isHostedAtWPcom | ||
let isAtomic = blog.isAtomic() | ||
let isAdmin = blog.isAdmin | ||
let hasOtherDomains = blog.domainsList.count > 0 | ||
let hasDomainCredit = blog.hasDomainCredit | ||
|
||
return (isHostedAtWPcom || isAtomic) && isAdmin && !hasOtherDomains && !hasDomainCredit | ||
} | ||
|
||
static func hideCard(for blog: Blog?) { | ||
guard let blog, | ||
let siteID = blog.dotComID?.intValue else { | ||
DDLogError("Domains Dashboard Card: error hiding the card.") | ||
return | ||
} | ||
|
||
BlogDashboardPersonalizationService(siteID: siteID) | ||
.setEnabled(false, for: .domainsDashboardCard) | ||
} | ||
} |
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
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
88 changes: 88 additions & 0 deletions
88
WordPress/WordPressTest/Dashboard/DomainsDashboardCardHelperTests.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,88 @@ | ||
import XCTest | ||
@testable import WordPress | ||
|
||
final class DomainsDashboardCardHelperTests: CoreDataTestCase { | ||
func testShouldShowCardEnabledFeatureFlagAndHostedAtWPcom() { | ||
let blog = BlogBuilder(mainContext) | ||
.isHostedAtWPcom() | ||
.with(atomic: false) | ||
.with(isAdmin: true) | ||
.with(registeredDomainCount: 0) | ||
.with(hasDomainCredit: false) | ||
.build() | ||
|
||
let result = DomainsDashboardCardHelper.shouldShowCard(for: blog, isJetpack: true, featureFlagEnabled: true) | ||
|
||
XCTAssertTrue(result, "Card should show for WPcom hosted blogs") | ||
} | ||
|
||
func testShouldShowCardEnabledFeatureFlagAndAtomic() { | ||
let blog = BlogBuilder(mainContext) | ||
.isNotHostedAtWPcom() | ||
.with(atomic: true) | ||
.with(isAdmin: true) | ||
.with(registeredDomainCount: 0) | ||
.with(hasDomainCredit: false) | ||
.build() | ||
|
||
let result = DomainsDashboardCardHelper.shouldShowCard(for: blog, isJetpack: true, featureFlagEnabled: true) | ||
|
||
XCTAssertTrue(result, "Card should show for Atomic blogs") | ||
} | ||
|
||
func testShouldNotShowCardNotAdmin() { | ||
let blog = BlogBuilder(mainContext) | ||
.isHostedAtWPcom() | ||
.with(atomic: false) | ||
.with(isAdmin: false) | ||
.with(registeredDomainCount: 0) | ||
.with(hasDomainCredit: false) | ||
.build() | ||
|
||
let result = DomainsDashboardCardHelper.shouldShowCard(for: blog, isJetpack: true, featureFlagEnabled: true) | ||
|
||
XCTAssertFalse(result, "Card should not show for non-admin users") | ||
} | ||
|
||
func testShouldNotShowCardHasOtherDomains() { | ||
let blog = BlogBuilder(mainContext) | ||
.isHostedAtWPcom() | ||
.with(atomic: false) | ||
.with(isAdmin: true) | ||
.with(registeredDomainCount: 2) | ||
.with(hasDomainCredit: false) | ||
.build() | ||
|
||
let result = DomainsDashboardCardHelper.shouldShowCard(for: blog, isJetpack: true, featureFlagEnabled: true) | ||
|
||
XCTAssertFalse(result, "Card should not show for blogs with more than one domain") | ||
} | ||
|
||
func testShouldNotShowCardHasDomainCredit() { | ||
let blog = BlogBuilder(mainContext) | ||
.isHostedAtWPcom() | ||
.with(atomic: false) | ||
.with(isAdmin: true) | ||
.with(registeredDomainCount: 0) | ||
.with(hasDomainCredit: true) | ||
.build() | ||
|
||
let result = DomainsDashboardCardHelper.shouldShowCard(for: blog, isJetpack: true, featureFlagEnabled: true) | ||
|
||
XCTAssertFalse(result, "Card should not show for blogs with domain credit") | ||
} | ||
|
||
func testShouldNotShowCardFeatureFlagDisabled() { | ||
let blog = BlogBuilder(mainContext) | ||
.isHostedAtWPcom() | ||
.with(atomic: false) | ||
.with(isAdmin: true) | ||
.with(registeredDomainCount: 0) | ||
.with(hasDomainCredit: false) | ||
.build() | ||
|
||
let result = DomainsDashboardCardHelper.shouldShowCard(for: blog, isJetpack: true, featureFlagEnabled: false) | ||
|
||
XCTAssertFalse(result, "Card should not show when the feature flag is disabled") | ||
} | ||
} |