Skip to content

Commit

Permalink
Carry over relevant Preferenes tests from edit-post package
Browse files Browse the repository at this point in the history
  • Loading branch information
vindl committed Mar 12, 2020
1 parent 081d4b5 commit 92214a5
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/edit-site/src/store/test/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Internal dependencies
*/
import { toggleFeature } from '../actions';

describe( 'actions', () => {
describe( 'toggleFeature', () => {
it( 'should return TOGGLE_FEATURE action', () => {
const feature = 'name';
expect( toggleFeature( feature ) ).toEqual( {
type: 'TOGGLE_FEATURE',
feature,
} );
} );
} );
} );
32 changes: 32 additions & 0 deletions packages/edit-site/src/store/test/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* External dependencies
*/
import deepFreeze from 'deep-freeze';

/**
* Internal dependencies
*/
import { preferences } from '../reducer';
import { PREFERENCES_DEFAULTS } from '../defaults';

describe( 'state', () => {
describe( 'preferences()', () => {
it( 'should apply all defaults', () => {
const state = preferences( undefined, {} );

expect( state ).toEqual( PREFERENCES_DEFAULTS );
} );

it( 'should toggle a feature flag', () => {
const state = preferences(
deepFreeze( { features: { chicken: true } } ),
{
type: 'TOGGLE_FEATURE',
feature: 'chicken',
}
);

expect( state.features ).toEqual( { chicken: false } );
} );
} );
} );
51 changes: 51 additions & 0 deletions packages/edit-site/src/store/test/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Internal dependencies
*/
import { isFeatureActive } from '../selectors';

describe( 'selectors', () => {
describe( 'isFeatureActive', () => {
it( 'is tolerant to an undefined features preference', () => {
// See: https://github.com/WordPress/gutenberg/issues/14580
const state = {
preferences: {},
};

expect( isFeatureActive( state, 'chicken' ) ).toBe( false );
} );

it( 'should return true if feature is active', () => {
const state = {
preferences: {
features: {
chicken: true,
},
},
};

expect( isFeatureActive( state, 'chicken' ) ).toBe( true );
} );

it( 'should return false if feature is not active', () => {
const state = {
preferences: {
features: {
chicken: false,
},
},
};

expect( isFeatureActive( state, 'chicken' ) ).toBe( false );
} );

it( 'should return false if feature is not referred', () => {
const state = {
preferences: {
features: {},
},
};

expect( isFeatureActive( state, 'chicken' ) ).toBe( false );
} );
} );
} );

0 comments on commit 92214a5

Please sign in to comment.