Skip to content

Commit aa356b3

Browse files
committed
Improve test descriptions and code comments for clarity
1 parent cf691b8 commit aa356b3

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

client/my-sites/plans-features-main/hooks/test/use-domain-to-plan-credits-applicable.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,27 @@ describe( 'useDomainToPlanCreditsApplicable', () => {
3838
mockIsCurrentPlanPaid.mockImplementation( () => false );
3939
} );
4040

41-
test( 'Returns credit when site has a domain, is on a free plan, and has credits', () => {
41+
test( 'Returns the credit value for a site that is eligible (has a domain and is on the free plan)', () => {
4242
const { result } = renderHookWithProvider( () => useDomainToPlanCreditsApplicable( siteId ) );
4343
expect( result.current ).toEqual( 1000 );
4444
} );
4545

46-
test( 'Returns credit when credit value is 0', () => {
47-
mockUseMaxPlanUpgradeCredits.mockImplementation( () => 0 );
48-
const { result } = renderHookWithProvider( () => useDomainToPlanCreditsApplicable( siteId ) );
49-
expect( result.current ).toEqual( 0 );
50-
} );
51-
52-
test( 'Returns null when site has no domain', () => {
46+
test( "Returns null when the site is not eligible because it doesn't have a domain)", () => {
5347
mockHasPurchasedDomain.mockImplementation( () => false );
5448
const { result } = renderHookWithProvider( () => useDomainToPlanCreditsApplicable( siteId ) );
5549
expect( result.current ).toEqual( null );
5650
} );
5751

58-
test( 'Returns null when site is on a paid plan', () => {
52+
test( 'Returns null when the site is not eligible because it is on a paid plan', () => {
5953
mockIsCurrentPlanPaid.mockImplementation( () => true );
6054
const { result } = renderHookWithProvider( () => useDomainToPlanCreditsApplicable( siteId ) );
6155
expect( result.current ).toEqual( null );
6256
} );
57+
58+
test( 'Returns 0 (rather than null) for for a site that is eligible and has a credit value of 0', () => {
59+
// ie. distinguishes between a site having zero credits, and a site being ineligible for credits (returning null)
60+
mockUseMaxPlanUpgradeCredits.mockImplementation( () => 0 );
61+
const { result } = renderHookWithProvider( () => useDomainToPlanCreditsApplicable( siteId ) );
62+
expect( result.current ).toEqual( 0 );
63+
} );
6364
} );

client/my-sites/plans-features-main/hooks/use-domain-to-plan-credits-applicable.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { isCurrentPlanPaid } from 'calypso/state/sites/selectors';
55
import { useMaxPlanUpgradeCredits } from './use-max-plan-upgrade-credits';
66

77
/**
8-
* This hook determines if the domain-to-plan upgrade credit should be visible in the current plans display context
9-
* and returns the credits value if applicable
10-
* @param siteId Considered site id
11-
* @param visiblePlans Plans that are visible to the user
12-
* @returns number | null if the credit should not be displayed to the user
8+
* This hook determines the eligibility of a site for domain-to-plan credits and
9+
* provides the credit value if eligible or null if not
10+
* @param siteId The ID of the site
11+
* @param visiblePlans The plans that are visible to the user
12+
* @returns The credit value or null if the site is not eligible
1313
*/
1414
export function useDomainToPlanCreditsApplicable(
1515
siteId?: number | null,

0 commit comments

Comments
 (0)