Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectors: Add areAllSitesSingleUser #13123

Merged
merged 2 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions client/state/selectors/are-all-sites-single-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Internal dependencies
*/
import createSelector from 'lib/create-selector';
import { isSingleUserSite } from 'state/sites/selectors';

/**
* Returns true if every site of the current user is a single user site
*
* @param {Object} state Global state tree
* @return {Boolean} True if all sites are single user sites
*/
export default createSelector( ( state ) => {
const siteIds = Object.keys( state.sites.items );
return siteIds && siteIds.every( ( siteId ) => isSingleUserSite( state, siteId ) );
}, ( state ) => ( state.sites.items ) );
1 change: 1 addition & 0 deletions client/state/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* to its individual file.
*/

export areAllSitesSingleUser from './are-all-sites-single-user';
export areSitePermalinksEditable from './are-site-permalinks-editable';
export canCurrentUser from './can-current-user';
export countPostLikes from './count-post-likes';
Expand Down
51 changes: 51 additions & 0 deletions client/state/selectors/test/are-all-sites-single-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* External dependencies
*/
import { expect } from 'chai';

/**
* Internal dependencies
*/
import { areAllSitesSingleUser } from '../';

describe( 'areAllSitesSingleUser()', () => {
it( 'should return false if single_user_site isn\'t true for all sites', () => {
const state = {
sites: {
items: {
2916284: {
ID: 2916284,
single_user_site: true
},
2916285: {
ID: 2916285,
single_user_site: false
}
}
}
};

const allAreSingleUser = areAllSitesSingleUser( state );
expect( allAreSingleUser ).to.be.false;
} );

it( 'should return true if single_user_site is true for all sites', () => {
const state = {
sites: {
items: {
2916284: {
ID: 2916284,
single_user_site: true
},
2916285: {
ID: 2916285,
single_user_site: true
}
}
}
};

const allAreSingleUser = areAllSitesSingleUser( state );
expect( allAreSingleUser ).to.be.true;
} );
} );