@wordpress/edit-post 6.2.0 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/sidebar/post-link/index.js +1 -1
- package/build/components/sidebar/post-link/index.js.map +1 -1
- package/build/components/visual-editor/index.js +3 -3
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/editor.js +3 -2
- package/build/editor.js.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/index.native.js +3 -0
- package/build/index.native.js.map +1 -1
- package/build/store/actions.js +76 -49
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +7 -10
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +0 -80
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +86 -25
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/sidebar/post-link/index.js +1 -1
- package/build-module/components/sidebar/post-link/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +3 -3
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/editor.js +2 -2
- package/build-module/editor.js.map +1 -1
- package/build-module/index.js +3 -0
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +3 -0
- package/build-module/index.native.js.map +1 -1
- package/build-module/store/actions.js +71 -45
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +7 -10
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +1 -77
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +82 -23
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +0 -3
- package/build-style/style.css +0 -3
- package/package.json +27 -26
- package/src/components/sidebar/post-link/index.js +1 -1
- package/src/components/visual-editor/index.js +5 -3
- package/src/editor.js +3 -2
- package/src/index.js +3 -0
- package/src/index.native.js +3 -0
- package/src/store/actions.js +47 -15
- package/src/store/index.js +7 -11
- package/src/store/reducer.js +1 -74
- package/src/store/selectors.js +121 -51
- package/src/store/test/actions.js +30 -33
- package/src/store/test/reducer.js +0 -126
- package/src/store/test/selectors.js +0 -155
- package/src/style.scss +0 -4
- package/build/store/defaults.js +0 -15
- package/build/store/defaults.js.map +0 -1
- package/build-module/store/defaults.js +0 -8
- package/build-module/store/defaults.js.map +0 -1
- package/src/store/defaults.js +0 -7
package/src/store/reducer.js
CHANGED
|
@@ -1,85 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { includes } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { combineReducers } from '@wordpress/data';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { PREFERENCES_DEFAULTS } from './defaults';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Higher-order reducer creator which provides the given initial state for the
|
|
18
|
-
* original reducer.
|
|
19
|
-
*
|
|
20
|
-
* @param {*} initialState Initial state to provide to reducer.
|
|
21
|
-
*
|
|
22
|
-
* @return {Function} Higher-order reducer.
|
|
23
|
-
*/
|
|
24
|
-
const createWithInitialState = ( initialState ) => ( reducer ) => {
|
|
25
|
-
return ( state = initialState, action ) => reducer( state, action );
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Reducer returning the user preferences.
|
|
30
|
-
*
|
|
31
|
-
* @param {Object} state Current state.
|
|
32
|
-
* @param {string} state.mode Current editor mode, either
|
|
33
|
-
* "visual" or "text".
|
|
34
|
-
* @param {boolean} state.isGeneralSidebarDismissed Whether general sidebar is
|
|
35
|
-
* dismissed. False by default
|
|
36
|
-
* or when closing general
|
|
37
|
-
* sidebar, true when opening
|
|
38
|
-
* sidebar.
|
|
39
|
-
* @param {boolean} state.isSidebarOpened Whether the sidebar is
|
|
40
|
-
* opened or closed.
|
|
41
|
-
* @param {Object} state.panels The state of the different
|
|
42
|
-
* sidebar panels.
|
|
43
|
-
* @param {Object} action Dispatched action.
|
|
44
|
-
*
|
|
45
|
-
* @return {Object} Updated state.
|
|
46
|
-
*/
|
|
47
|
-
export const preferences = flow( [
|
|
48
|
-
combineReducers,
|
|
49
|
-
createWithInitialState( PREFERENCES_DEFAULTS ),
|
|
50
|
-
] )( {
|
|
51
|
-
panels( state, action ) {
|
|
52
|
-
switch ( action.type ) {
|
|
53
|
-
case 'TOGGLE_PANEL_ENABLED': {
|
|
54
|
-
const { panelName } = action;
|
|
55
|
-
return {
|
|
56
|
-
...state,
|
|
57
|
-
[ panelName ]: {
|
|
58
|
-
...state[ panelName ],
|
|
59
|
-
enabled: ! get( state, [ panelName, 'enabled' ], true ),
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
case 'TOGGLE_PANEL_OPENED': {
|
|
65
|
-
const { panelName } = action;
|
|
66
|
-
const isOpen =
|
|
67
|
-
state[ panelName ] === true ||
|
|
68
|
-
get( state, [ panelName, 'opened' ], false );
|
|
69
|
-
return {
|
|
70
|
-
...state,
|
|
71
|
-
[ panelName ]: {
|
|
72
|
-
...state[ panelName ],
|
|
73
|
-
opened: ! isOpen,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return state;
|
|
80
|
-
},
|
|
81
|
-
} );
|
|
82
|
-
|
|
83
11
|
/**
|
|
84
12
|
* Reducer storing the list of all programmatically removed panels.
|
|
85
13
|
*
|
|
@@ -263,7 +191,6 @@ const metaBoxes = combineReducers( {
|
|
|
263
191
|
export default combineReducers( {
|
|
264
192
|
activeModal,
|
|
265
193
|
metaBoxes,
|
|
266
|
-
preferences,
|
|
267
194
|
publishSidebarActive,
|
|
268
195
|
removedPanels,
|
|
269
196
|
deviceType,
|
package/src/store/selectors.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import createSelector from 'rememo';
|
|
5
|
-
import {
|
|
5
|
+
import { includes, some, flatten, values } from 'lodash';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -12,8 +12,10 @@ import { store as interfaceStore } from '@wordpress/interface';
|
|
|
12
12
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
13
13
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
14
|
import { store as editorStore } from '@wordpress/editor';
|
|
15
|
+
import deprecated from '@wordpress/deprecated';
|
|
15
16
|
|
|
16
17
|
const EMPTY_ARRAY = [];
|
|
18
|
+
const EMPTY_OBJECT = {};
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Returns the current editing mode.
|
|
@@ -89,13 +91,57 @@ export const getActiveGeneralSidebarName = createRegistrySelector(
|
|
|
89
91
|
}
|
|
90
92
|
);
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Converts panels from the new preferences store format to the old format
|
|
96
|
+
* that the post editor previously used.
|
|
97
|
+
*
|
|
98
|
+
* The resultant converted data should look like this:
|
|
99
|
+
* {
|
|
100
|
+
* panelName: {
|
|
101
|
+
* enabled: false,
|
|
102
|
+
* opened: true,
|
|
103
|
+
* },
|
|
104
|
+
* anotherPanelName: {
|
|
105
|
+
* opened: true
|
|
106
|
+
* },
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* @param {string[] | undefined} inactivePanels An array of inactive panel names.
|
|
110
|
+
* @param {string[] | undefined} openPanels An array of open panel names.
|
|
111
|
+
*
|
|
112
|
+
* @return {Object} The converted panel data.
|
|
113
|
+
*/
|
|
114
|
+
function convertPanelsToOldFormat( inactivePanels, openPanels ) {
|
|
115
|
+
// First reduce the inactive panels.
|
|
116
|
+
const panelsWithEnabledState = inactivePanels?.reduce(
|
|
117
|
+
( accumulatedPanels, panelName ) => ( {
|
|
118
|
+
...accumulatedPanels,
|
|
119
|
+
[ panelName ]: {
|
|
120
|
+
enabled: false,
|
|
121
|
+
},
|
|
122
|
+
} ),
|
|
123
|
+
{}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// Then reduce the open panels, passing in the result of the previous
|
|
127
|
+
// reduction as the initial value so that both open and inactive
|
|
128
|
+
// panel state is combined.
|
|
129
|
+
const panels = openPanels?.reduce( ( accumulatedPanels, panelName ) => {
|
|
130
|
+
const currentPanelState = accumulatedPanels?.[ panelName ];
|
|
131
|
+
return {
|
|
132
|
+
...accumulatedPanels,
|
|
133
|
+
[ panelName ]: {
|
|
134
|
+
...currentPanelState,
|
|
135
|
+
opened: true,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}, panelsWithEnabledState ?? {} );
|
|
139
|
+
|
|
140
|
+
// The panels variable will only be set if openPanels wasn't `undefined`.
|
|
141
|
+
// If it isn't set just return `panelsWithEnabledState`, and if that isn't
|
|
142
|
+
// set return an empty object.
|
|
143
|
+
return panels ?? panelsWithEnabledState ?? EMPTY_OBJECT;
|
|
144
|
+
}
|
|
99
145
|
|
|
100
146
|
/**
|
|
101
147
|
* Returns the preferences (these preferences are persisted locally).
|
|
@@ -104,34 +150,50 @@ const MIGRATED_KEYS = [
|
|
|
104
150
|
*
|
|
105
151
|
* @return {Object} Preferences Object.
|
|
106
152
|
*/
|
|
107
|
-
export const getPreferences = createRegistrySelector(
|
|
108
|
-
( select
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
{}
|
|
153
|
+
export const getPreferences = createRegistrySelector( ( select ) => () => {
|
|
154
|
+
deprecated( `wp.data.select( 'core/edit-post' ).getPreferences`, {
|
|
155
|
+
since: '6.0',
|
|
156
|
+
alternative: `wp.data.select( 'core/preferences' ).get`,
|
|
157
|
+
} );
|
|
158
|
+
|
|
159
|
+
// These preferences now exist in the preferences store.
|
|
160
|
+
// Fetch them so that they can be merged into the post
|
|
161
|
+
// editor preferences.
|
|
162
|
+
const preferences = [
|
|
163
|
+
'hiddenBlockTypes',
|
|
164
|
+
'editorMode',
|
|
165
|
+
'preferredStyleVariations',
|
|
166
|
+
].reduce( ( accumulatedPrefs, preferenceKey ) => {
|
|
167
|
+
const value = select( preferencesStore ).get(
|
|
168
|
+
'core/edit-post',
|
|
169
|
+
preferenceKey
|
|
127
170
|
);
|
|
128
171
|
|
|
129
172
|
return {
|
|
130
|
-
...
|
|
131
|
-
|
|
173
|
+
...accumulatedPrefs,
|
|
174
|
+
[ preferenceKey ]: value,
|
|
132
175
|
};
|
|
133
|
-
}
|
|
134
|
-
|
|
176
|
+
}, {} );
|
|
177
|
+
|
|
178
|
+
// Panels were a preference, but the data structure changed when the state
|
|
179
|
+
// was migrated to the preferences store. They need to be converted from
|
|
180
|
+
// the new preferences store format to old format to ensure no breaking
|
|
181
|
+
// changes for plugins.
|
|
182
|
+
const inactivePanels = select( preferencesStore ).get(
|
|
183
|
+
'core/edit-post',
|
|
184
|
+
'inactivePanels'
|
|
185
|
+
);
|
|
186
|
+
const openPanels = select( preferencesStore ).get(
|
|
187
|
+
'core/edit-post',
|
|
188
|
+
'openPanels'
|
|
189
|
+
);
|
|
190
|
+
const panels = convertPanelsToOldFormat( inactivePanels, openPanels );
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
...preferences,
|
|
194
|
+
panels,
|
|
195
|
+
};
|
|
196
|
+
} );
|
|
135
197
|
|
|
136
198
|
/**
|
|
137
199
|
*
|
|
@@ -142,11 +204,13 @@ export const getPreferences = createRegistrySelector(
|
|
|
142
204
|
* @return {*} Preference Value.
|
|
143
205
|
*/
|
|
144
206
|
export function getPreference( state, preferenceKey, defaultValue ) {
|
|
207
|
+
deprecated( `wp.data.select( 'core/edit-post' ).getPreference`, {
|
|
208
|
+
since: '6.0',
|
|
209
|
+
alternative: `wp.data.select( 'core/preferences' ).get`,
|
|
210
|
+
} );
|
|
211
|
+
|
|
145
212
|
// Avoid using the `getPreferences` registry selector where possible.
|
|
146
|
-
const
|
|
147
|
-
const preferences = isMigratedKey
|
|
148
|
-
? getPreferences( state )
|
|
149
|
-
: state.preferences;
|
|
213
|
+
const preferences = getPreferences( state );
|
|
150
214
|
const value = preferences[ preferenceKey ];
|
|
151
215
|
return value === undefined ? defaultValue : value;
|
|
152
216
|
}
|
|
@@ -198,14 +262,18 @@ export function isEditorPanelRemoved( state, panelName ) {
|
|
|
198
262
|
*
|
|
199
263
|
* @return {boolean} Whether or not the panel is enabled.
|
|
200
264
|
*/
|
|
201
|
-
export
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
265
|
+
export const isEditorPanelEnabled = createRegistrySelector(
|
|
266
|
+
( select ) => ( state, panelName ) => {
|
|
267
|
+
const inactivePanels = select( preferencesStore ).get(
|
|
268
|
+
'core/edit-post',
|
|
269
|
+
'inactivePanels'
|
|
270
|
+
);
|
|
271
|
+
return (
|
|
272
|
+
! isEditorPanelRemoved( state, panelName ) &&
|
|
273
|
+
! inactivePanels?.includes( panelName )
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
);
|
|
209
277
|
|
|
210
278
|
/**
|
|
211
279
|
* Returns true if the given panel is open, or false otherwise. Panels are
|
|
@@ -216,13 +284,15 @@ export function isEditorPanelEnabled( state, panelName ) {
|
|
|
216
284
|
*
|
|
217
285
|
* @return {boolean} Whether or not the panel is open.
|
|
218
286
|
*/
|
|
219
|
-
export
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
287
|
+
export const isEditorPanelOpened = createRegistrySelector(
|
|
288
|
+
( select ) => ( state, panelName ) => {
|
|
289
|
+
const openPanels = select( preferencesStore ).get(
|
|
290
|
+
'core/edit-post',
|
|
291
|
+
'openPanels'
|
|
292
|
+
);
|
|
293
|
+
return !! openPanels?.includes( panelName );
|
|
294
|
+
}
|
|
295
|
+
);
|
|
226
296
|
|
|
227
297
|
/**
|
|
228
298
|
* Returns true if a modal is active, or false otherwise.
|
|
@@ -157,7 +157,6 @@ describe( 'actions', () => {
|
|
|
157
157
|
|
|
158
158
|
const expected = [ 'core/quote', 'core/table' ];
|
|
159
159
|
|
|
160
|
-
// TODO - remove once `getPreference` is deprecated.
|
|
161
160
|
expect(
|
|
162
161
|
registry
|
|
163
162
|
.select( editPostStore )
|
|
@@ -167,6 +166,9 @@ describe( 'actions', () => {
|
|
|
167
166
|
expect(
|
|
168
167
|
registry.select( editPostStore ).getHiddenBlockTypes()
|
|
169
168
|
).toEqual( expected );
|
|
169
|
+
|
|
170
|
+
// Expect a deprecation message for `getPreference`.
|
|
171
|
+
expect( console ).toHaveWarned();
|
|
170
172
|
} );
|
|
171
173
|
} );
|
|
172
174
|
|
|
@@ -178,7 +180,6 @@ describe( 'actions', () => {
|
|
|
178
180
|
|
|
179
181
|
const expectedA = [ 'core/quote', 'core/table' ];
|
|
180
182
|
|
|
181
|
-
// TODO - remove once `getPreference` is deprecated.
|
|
182
183
|
expect(
|
|
183
184
|
registry
|
|
184
185
|
.select( editPostStore )
|
|
@@ -195,7 +196,6 @@ describe( 'actions', () => {
|
|
|
195
196
|
|
|
196
197
|
const expectedB = [ 'core/quote' ];
|
|
197
198
|
|
|
198
|
-
// TODO - remove once `getPreference` is deprecated.
|
|
199
199
|
expect(
|
|
200
200
|
registry
|
|
201
201
|
.select( editPostStore )
|
|
@@ -210,22 +210,21 @@ describe( 'actions', () => {
|
|
|
210
210
|
|
|
211
211
|
describe( 'toggleEditorPanelEnabled', () => {
|
|
212
212
|
it( 'toggles panels to be enabled and not enabled', () => {
|
|
213
|
-
const defaultState = {
|
|
214
|
-
'post-status': {
|
|
215
|
-
opened: true,
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
|
|
219
213
|
// This will switch it off, since the default is on.
|
|
220
214
|
registry
|
|
221
215
|
.dispatch( editPostStore )
|
|
222
216
|
.toggleEditorPanelEnabled( 'control-panel' );
|
|
223
217
|
|
|
224
|
-
|
|
218
|
+
expect(
|
|
219
|
+
registry
|
|
220
|
+
.select( editPostStore )
|
|
221
|
+
.isEditorPanelEnabled( 'control-panel' )
|
|
222
|
+
).toBe( false );
|
|
223
|
+
|
|
224
|
+
// Also check that the `getPreference` selector includes panels.
|
|
225
225
|
expect(
|
|
226
226
|
registry.select( editPostStore ).getPreference( 'panels' )
|
|
227
227
|
).toEqual( {
|
|
228
|
-
...defaultState,
|
|
229
228
|
'control-panel': {
|
|
230
229
|
enabled: false,
|
|
231
230
|
},
|
|
@@ -236,36 +235,34 @@ describe( 'actions', () => {
|
|
|
236
235
|
.dispatch( editPostStore )
|
|
237
236
|
.toggleEditorPanelEnabled( 'control-panel' );
|
|
238
237
|
|
|
239
|
-
|
|
238
|
+
expect(
|
|
239
|
+
registry
|
|
240
|
+
.select( editPostStore )
|
|
241
|
+
.isEditorPanelEnabled( 'control-panel' )
|
|
242
|
+
).toBe( true );
|
|
243
|
+
|
|
240
244
|
expect(
|
|
241
245
|
registry.select( editPostStore ).getPreference( 'panels' )
|
|
242
|
-
).toEqual( {
|
|
243
|
-
...defaultState,
|
|
244
|
-
'control-panel': {
|
|
245
|
-
enabled: true,
|
|
246
|
-
},
|
|
247
|
-
} );
|
|
246
|
+
).toEqual( {} );
|
|
248
247
|
} );
|
|
249
248
|
} );
|
|
250
249
|
|
|
251
250
|
describe( 'toggleEditorPanelOpened', () => {
|
|
252
251
|
it( 'toggles panels open and closed', () => {
|
|
253
|
-
const defaultState = {
|
|
254
|
-
'post-status': {
|
|
255
|
-
opened: true,
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
|
|
259
252
|
// This will open it, since the default is closed.
|
|
260
253
|
registry
|
|
261
254
|
.dispatch( editPostStore )
|
|
262
255
|
.toggleEditorPanelOpened( 'control-panel' );
|
|
263
256
|
|
|
264
|
-
|
|
257
|
+
expect(
|
|
258
|
+
registry
|
|
259
|
+
.select( editPostStore )
|
|
260
|
+
.isEditorPanelOpened( 'control-panel' )
|
|
261
|
+
).toBe( true );
|
|
262
|
+
|
|
265
263
|
expect(
|
|
266
264
|
registry.select( editPostStore ).getPreference( 'panels' )
|
|
267
265
|
).toEqual( {
|
|
268
|
-
...defaultState,
|
|
269
266
|
'control-panel': {
|
|
270
267
|
opened: true,
|
|
271
268
|
},
|
|
@@ -276,15 +273,15 @@ describe( 'actions', () => {
|
|
|
276
273
|
.dispatch( editPostStore )
|
|
277
274
|
.toggleEditorPanelOpened( 'control-panel' );
|
|
278
275
|
|
|
279
|
-
|
|
276
|
+
expect(
|
|
277
|
+
registry
|
|
278
|
+
.select( editPostStore )
|
|
279
|
+
.isEditorPanelOpened( 'control-panel' )
|
|
280
|
+
).toBe( false );
|
|
281
|
+
|
|
280
282
|
expect(
|
|
281
283
|
registry.select( editPostStore ).getPreference( 'panels' )
|
|
282
|
-
).toEqual( {
|
|
283
|
-
...defaultState,
|
|
284
|
-
'control-panel': {
|
|
285
|
-
opened: false,
|
|
286
|
-
},
|
|
287
|
-
} );
|
|
284
|
+
).toEqual( {} );
|
|
288
285
|
} );
|
|
289
286
|
} );
|
|
290
287
|
|
|
@@ -7,7 +7,6 @@ import deepFreeze from 'deep-freeze';
|
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
|
-
preferences,
|
|
11
10
|
activeModal,
|
|
12
11
|
isSavingMetaBoxes,
|
|
13
12
|
metaBoxLocations,
|
|
@@ -15,135 +14,10 @@ import {
|
|
|
15
14
|
blockInserterPanel,
|
|
16
15
|
listViewPanel,
|
|
17
16
|
} from '../reducer';
|
|
18
|
-
import { PREFERENCES_DEFAULTS } from '../defaults';
|
|
19
17
|
|
|
20
18
|
import { setIsInserterOpened, setIsListViewOpened } from '../actions';
|
|
21
19
|
|
|
22
20
|
describe( 'state', () => {
|
|
23
|
-
describe( 'preferences()', () => {
|
|
24
|
-
it( 'should apply all defaults', () => {
|
|
25
|
-
const state = preferences( undefined, {} );
|
|
26
|
-
|
|
27
|
-
expect( state ).toEqual( PREFERENCES_DEFAULTS );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
it( 'should disable panels by default', () => {
|
|
31
|
-
const original = deepFreeze( {
|
|
32
|
-
panels: {},
|
|
33
|
-
} );
|
|
34
|
-
const state = preferences( original, {
|
|
35
|
-
type: 'TOGGLE_PANEL_ENABLED',
|
|
36
|
-
panelName: 'post-status',
|
|
37
|
-
} );
|
|
38
|
-
expect( state.panels ).toEqual( {
|
|
39
|
-
'post-status': { enabled: false },
|
|
40
|
-
} );
|
|
41
|
-
} );
|
|
42
|
-
|
|
43
|
-
it( 'should disable panels that are enabled', () => {
|
|
44
|
-
const original = deepFreeze( {
|
|
45
|
-
panels: {
|
|
46
|
-
'post-status': { enabled: true },
|
|
47
|
-
},
|
|
48
|
-
} );
|
|
49
|
-
const state = preferences( original, {
|
|
50
|
-
type: 'TOGGLE_PANEL_ENABLED',
|
|
51
|
-
panelName: 'post-status',
|
|
52
|
-
} );
|
|
53
|
-
expect( state.panels ).toEqual( {
|
|
54
|
-
'post-status': { enabled: false },
|
|
55
|
-
} );
|
|
56
|
-
} );
|
|
57
|
-
|
|
58
|
-
it( 'should enable panels that are disabled', () => {
|
|
59
|
-
const original = deepFreeze( {
|
|
60
|
-
panels: {
|
|
61
|
-
'post-status': { enabled: false },
|
|
62
|
-
},
|
|
63
|
-
} );
|
|
64
|
-
const state = preferences( original, {
|
|
65
|
-
type: 'TOGGLE_PANEL_ENABLED',
|
|
66
|
-
panelName: 'post-status',
|
|
67
|
-
} );
|
|
68
|
-
expect( state.panels ).toEqual( {
|
|
69
|
-
'post-status': { enabled: true },
|
|
70
|
-
} );
|
|
71
|
-
} );
|
|
72
|
-
|
|
73
|
-
it( 'should open panels by default', () => {
|
|
74
|
-
const original = deepFreeze( {
|
|
75
|
-
panels: {},
|
|
76
|
-
} );
|
|
77
|
-
const state = preferences( original, {
|
|
78
|
-
type: 'TOGGLE_PANEL_OPENED',
|
|
79
|
-
panelName: 'post-status',
|
|
80
|
-
} );
|
|
81
|
-
expect( state.panels ).toEqual( {
|
|
82
|
-
'post-status': { opened: true },
|
|
83
|
-
} );
|
|
84
|
-
} );
|
|
85
|
-
|
|
86
|
-
it( 'should open panels that are closed', () => {
|
|
87
|
-
const original = deepFreeze( {
|
|
88
|
-
panels: {
|
|
89
|
-
'post-status': { opened: false },
|
|
90
|
-
},
|
|
91
|
-
} );
|
|
92
|
-
const state = preferences( original, {
|
|
93
|
-
type: 'TOGGLE_PANEL_OPENED',
|
|
94
|
-
panelName: 'post-status',
|
|
95
|
-
} );
|
|
96
|
-
expect( state.panels ).toEqual( {
|
|
97
|
-
'post-status': { opened: true },
|
|
98
|
-
} );
|
|
99
|
-
} );
|
|
100
|
-
|
|
101
|
-
it( 'should close panels that are opened', () => {
|
|
102
|
-
const original = deepFreeze( {
|
|
103
|
-
panels: {
|
|
104
|
-
'post-status': { opened: true },
|
|
105
|
-
},
|
|
106
|
-
} );
|
|
107
|
-
const state = preferences( original, {
|
|
108
|
-
type: 'TOGGLE_PANEL_OPENED',
|
|
109
|
-
panelName: 'post-status',
|
|
110
|
-
} );
|
|
111
|
-
expect( state.panels ).toEqual( {
|
|
112
|
-
'post-status': { opened: false },
|
|
113
|
-
} );
|
|
114
|
-
} );
|
|
115
|
-
|
|
116
|
-
it( 'should open panels that are legacy closed', () => {
|
|
117
|
-
const original = deepFreeze( {
|
|
118
|
-
panels: {
|
|
119
|
-
'post-status': false,
|
|
120
|
-
},
|
|
121
|
-
} );
|
|
122
|
-
const state = preferences( original, {
|
|
123
|
-
type: 'TOGGLE_PANEL_OPENED',
|
|
124
|
-
panelName: 'post-status',
|
|
125
|
-
} );
|
|
126
|
-
expect( state.panels ).toEqual( {
|
|
127
|
-
'post-status': { opened: true },
|
|
128
|
-
} );
|
|
129
|
-
} );
|
|
130
|
-
|
|
131
|
-
it( 'should close panels that are legacy opened', () => {
|
|
132
|
-
const original = deepFreeze( {
|
|
133
|
-
panels: {
|
|
134
|
-
'post-status': true,
|
|
135
|
-
},
|
|
136
|
-
} );
|
|
137
|
-
const state = preferences( original, {
|
|
138
|
-
type: 'TOGGLE_PANEL_OPENED',
|
|
139
|
-
panelName: 'post-status',
|
|
140
|
-
} );
|
|
141
|
-
expect( state.panels ).toEqual( {
|
|
142
|
-
'post-status': { opened: false },
|
|
143
|
-
} );
|
|
144
|
-
} );
|
|
145
|
-
} );
|
|
146
|
-
|
|
147
21
|
describe( 'activeModal', () => {
|
|
148
22
|
it( 'should default to null', () => {
|
|
149
23
|
const state = activeModal( undefined, {} );
|