Skip to content

Commit e00b44b

Browse files
committed
Fix unit tests
1 parent 40f773f commit e00b44b

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

packages/block-editor/src/store/private-selectors.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
getBlockOrder,
1616
getBlockParents,
1717
getBlockEditingMode,
18-
getBlockRootClientId,
1918
getSettings,
2019
canInsertBlockType,
2120
} from './selectors';
@@ -24,6 +23,8 @@ import { INSERTER_PATTERN_TYPES } from '../components/inserter/block-patterns-ta
2423
import { store } from './';
2524
import { unlock } from '../lock-unlock';
2625

26+
export { getSelectedBlockClientIdsUnmemoized } from './utils';
27+
2728
/**
2829
* Returns true if the block interface is hidden, or false otherwise.
2930
*
@@ -49,39 +50,6 @@ export function getBlockWithoutAttributes( state, clientId ) {
4950
return state.blocks.byClientId.get( clientId );
5051
}
5152

52-
const EMPTY_ARRAY = [];
53-
54-
export function getSelectedBlockClientIdsUnmemoized( state ) {
55-
const { selectionStart, selectionEnd } = state.selection;
56-
57-
if ( ! selectionStart.clientId || ! selectionEnd.clientId ) {
58-
return EMPTY_ARRAY;
59-
}
60-
61-
if ( selectionStart.clientId === selectionEnd.clientId ) {
62-
return [ selectionStart.clientId ];
63-
}
64-
65-
// Retrieve root client ID to aid in retrieving relevant nested block
66-
// order, being careful to allow the falsey empty string top-level root
67-
// by explicitly testing against null.
68-
const rootClientId = getBlockRootClientId( state, selectionStart.clientId );
69-
70-
if ( rootClientId === null ) {
71-
return EMPTY_ARRAY;
72-
}
73-
74-
const blockOrder = getBlockOrder( state, rootClientId );
75-
const startIndex = blockOrder.indexOf( selectionStart.clientId );
76-
const endIndex = blockOrder.indexOf( selectionEnd.clientId );
77-
78-
if ( startIndex > endIndex ) {
79-
return blockOrder.slice( endIndex, startIndex + 1 );
80-
}
81-
82-
return blockOrder.slice( startIndex, endIndex + 1 );
83-
}
84-
8553
/**
8654
* Returns true if all of the descendants of a block with the given client ID
8755
* have an editing mode of 'disabled', or false otherwise.

packages/block-editor/src/store/selectors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import {
3030
checkAllowListRecursive,
3131
checkAllowList,
3232
getAllPatternsDependants,
33+
getSelectedBlockClientIdsUnmemoized,
3334
} from './utils';
3435
import { orderBy } from '../utils/sorting';
3536
import { STORE_NAME } from './constants';
3637
import { unlock } from '../lock-unlock';
37-
import { getSelectedBlockClientIdsUnmemoized } from './private-selectors';
3838

3939
/**
4040
* A block selection object.

packages/block-editor/src/store/utils.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import { getBlockRootClientId, getBlockOrder } from './selectors';
5+
16
export const checkAllowList = ( list, item, defaultResult = null ) => {
27
if ( typeof list === 'boolean' ) {
38
return list;
@@ -49,3 +54,36 @@ export const getAllPatternsDependants = ( state ) => {
4954
state.blockPatterns,
5055
];
5156
};
57+
58+
const EMPTY_ARRAY = [];
59+
60+
export function getSelectedBlockClientIdsUnmemoized( state ) {
61+
const { selectionStart, selectionEnd } = state.selection;
62+
63+
if ( ! selectionStart.clientId || ! selectionEnd.clientId ) {
64+
return EMPTY_ARRAY;
65+
}
66+
67+
if ( selectionStart.clientId === selectionEnd.clientId ) {
68+
return [ selectionStart.clientId ];
69+
}
70+
71+
// Retrieve root client ID to aid in retrieving relevant nested block
72+
// order, being careful to allow the falsey empty string top-level root
73+
// by explicitly testing against null.
74+
const rootClientId = getBlockRootClientId( state, selectionStart.clientId );
75+
76+
if ( rootClientId === null ) {
77+
return EMPTY_ARRAY;
78+
}
79+
80+
const blockOrder = getBlockOrder( state, rootClientId );
81+
const startIndex = blockOrder.indexOf( selectionStart.clientId );
82+
const endIndex = blockOrder.indexOf( selectionEnd.clientId );
83+
84+
if ( startIndex > endIndex ) {
85+
return blockOrder.slice( endIndex, startIndex + 1 );
86+
}
87+
88+
return blockOrder.slice( startIndex, endIndex + 1 );
89+
}

0 commit comments

Comments
 (0)