-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Domains: show info notice when user has domain credit
- Loading branch information
Showing
7 changed files
with
163 additions
and
9 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import find from 'lodash/find'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { initialSiteState } from './reducer'; | ||
|
||
export function getPlansBySite( state, site ) { | ||
if ( ! site ) { | ||
return initialSiteState; | ||
} | ||
return getPlansBySiteId( state, site.ID ); | ||
} | ||
|
||
return state.sites.plans[ site.ID ] || initialSiteState; | ||
export function getPlansBySiteId( state, siteId ) { | ||
if ( ! siteId ) { | ||
return initialSiteState; | ||
} | ||
return state.sites.plans[ siteId ] || initialSiteState; | ||
} | ||
|
||
export function hasDomainCredit( state, siteId ) { | ||
const plans = getPlansBySiteId( state, siteId ); | ||
if ( plans.data ) { | ||
const currentPlan = find( plans.data, 'currentPlan' ); | ||
return currentPlan.hasDomainCredit; | ||
} | ||
return null; | ||
} |
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,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { expect } from 'chai'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
getPlansBySite, | ||
getPlansBySiteId, | ||
hasDomainCredit | ||
} from '../selectors'; | ||
|
||
describe( 'selectors', () => { | ||
describe( '#getPlansBySite()', () => { | ||
it( 'should return plans by site', () => { | ||
const plans1 = { data: [ { currentPlan: false }, { currentPlan: false }, { currentPlan: true } ] }; | ||
const plans2 = { data: [ { currentPlan: true }, { currentPlan: false }, { currentPlan: false } ] }; | ||
const state = { | ||
sites: { | ||
plans: { | ||
2916284: plans1, | ||
77203074: plans2 | ||
} | ||
} | ||
}; | ||
const plans = getPlansBySite( state, { ID: 77203074 } ); | ||
|
||
expect( plans ).to.eql( plans2 ); | ||
} ); | ||
} ); | ||
describe( '#getPlansBySiteId()', () => { | ||
it( 'should return plans by site id', () => { | ||
const plans1 = { data: [ { currentPlan: false }, { currentPlan: false }, { currentPlan: true } ] }; | ||
const plans2 = { data: [ { currentPlan: true }, { currentPlan: false }, { currentPlan: false } ] }; | ||
const state = { | ||
sites: { | ||
plans: { | ||
2916284: plans1, | ||
77203074: plans2 | ||
} | ||
} | ||
}; | ||
const plans = getPlansBySiteId( state, 2916284 ); | ||
|
||
expect( plans ).to.eql( plans1 ); | ||
} ); | ||
} ); | ||
describe( '#hasDomainCredit()', () => { | ||
it( 'should return if plan has domain credit', () => { | ||
const state = { | ||
sites: { | ||
plans: { | ||
2916284: { | ||
data: [ { currentPlan: false }, { currentPlan: false }, { currentPlan: true, hasDomainCredit: false } ] | ||
}, | ||
77203074: { | ||
data: [ { currentPlan: false }, { currentPlan: true, hasDomainCredit: true }, { currentPlan: false } ] | ||
} | ||
|
||
} | ||
} | ||
}; | ||
|
||
expect( hasDomainCredit( state, 77203074 ) ).to.equal( true ); | ||
expect( hasDomainCredit( state, 2916284 ) ).to.equal( false ); | ||
} ); | ||
} ); | ||
} ); |
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