-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Carry over relevant Preferenes tests from edit-post package
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 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
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, | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
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,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 } ); | ||
} ); | ||
} ); | ||
} ); |
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,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 ); | ||
} ); | ||
} ); | ||
} ); |