-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/fix-assessments' into 16…
…22-ai-assessment-lock-icon
- Loading branch information
Showing
6 changed files
with
82 additions
and
6 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
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 @@ | ||
/** | ||
* Returns all Gutenberg blocks given the (current) top-level blocks. | ||
* @param {object[]} blocks The (current) top-level blocks. | ||
* @returns {object[]} All blocks. | ||
*/ | ||
export const getAllBlocks = ( blocks ) => { | ||
let allBlocks = [ ...blocks ]; | ||
|
||
blocks.forEach( block => { | ||
if ( block.innerBlocks && block.innerBlocks.length > 0 ) { | ||
allBlocks = [ ...allBlocks, ...getAllBlocks( block.innerBlocks ) ]; | ||
} | ||
} ); | ||
|
||
return allBlocks; | ||
}; |
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
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,18 @@ | ||
import { getAllBlocks } from "../../src/helpers/getAllBlocks"; | ||
|
||
describe( "getAllBlocks", () => { | ||
it( "should return the same blocks when no inner blocks are defined", () => { | ||
const blocks = [ { clientId: 1 }, { clientId: 2 }, { clientId: 3 } ]; | ||
const expected = [ 1, 2, 3 ]; | ||
expect( expected ).toEqual( getAllBlocks( blocks ).map( ( { clientId } ) => clientId ) ); | ||
} ); | ||
|
||
it( "should return all blocks when inner blocks are defined", () => { | ||
const blocks = [ | ||
{ clientId: 1, innerBlocks: [ { clientId: 2 }, { clientId: 3, innerBlocks: [ { clientId: 4 } ] } ] }, | ||
{ clientId: 5, innerBlocks: [] }, | ||
]; | ||
const expected = [ 1, 2, 3, 4, 5 ]; | ||
expect( expected ).toEqual( getAllBlocks( blocks ).map( ( { clientId } ) => clientId ).sort() ); | ||
} ); | ||
} ); |
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
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