@@ -1,4 +1,6 @@
/* eslint-disable check-file/filename-naming-convention */
import { JSX } from 'react' ;
import { ContentManagerPlugin , DocumentActionComponent , PanelComponent } from '../content-manager' ;
jest . mock ( '../pages/EditView/components/Panels' , ( ) => ( {
Expand Down
Expand Up
@@ -41,10 +43,12 @@ describe('content-manager', () => {
"addDocumentAction": [Function],
"addDocumentHeaderAction": [Function],
"addEditViewSidePanel": [Function],
"addRichTextBlocks": [Function],
"getBulkActions": [Function],
"getDocumentActions": [Function],
"getEditViewSidePanels": [Function],
"getHeaderActions": [Function],
"getRichTextBlocks": [Function],
},
"id": "content-manager",
"injectionZones": {
Expand Down
Expand Up
@@ -77,10 +81,12 @@ describe('content-manager', () => {
"addDocumentAction",
"addDocumentHeaderAction",
"addEditViewSidePanel",
"addRichTextBlocks",
"getBulkActions",
"getDocumentActions",
"getEditViewSidePanels",
"getHeaderActions",
"getRichTextBlocks",
]
` ) ;
} ) ;
Expand Down
Expand Up
@@ -261,4 +267,110 @@ describe('content-manager', () => {
) ;
} ) ;
} ) ;
describe ( 'addRichTextBlocks' , ( ) => {
it ( 'should let users add a new block with objects keys' , ( ) => {
const plugin = new ContentManagerPlugin ( ) ;
plugin . addRichTextBlocks ( {
customBlock : {
isInBlocksSelector : true ,
renderElement : ( ) => null as unknown as JSX . Element ,
matchNode : ( node ) => node . type === 'customBlock' ,
label : { defaultMessage : 'Custom Block' } ,
} ,
} ) ;
expect ( plugin . richTextBlocksStore ) . toHaveProperty ( 'customBlock' ) ;
} ) ;
it ( 'should let users add a new block with a function' , ( ) => {
const plugin = new ContentManagerPlugin ( ) ;
plugin . addRichTextBlocks ( ( prev ) => ( {
...prev ,
customBlock : {
isInBlocksSelector : true ,
renderElement : ( ) => null as unknown as JSX . Element ,
matchNode : ( node ) => node . type === 'customBlock' ,
label : { defaultMessage : 'Custom Block' } ,
} ,
} ) ) ;
expect ( plugin . richTextBlocksStore ) . toHaveProperty ( 'customBlock' ) ;
} ) ;
it ( 'should let users remove a block with a function' , ( ) => {
const plugin = new ContentManagerPlugin ( ) ;
plugin . addRichTextBlocks ( {
customBlock : {
isInBlocksSelector : true ,
renderElement : ( ) => null as unknown as JSX . Element ,
matchNode : ( node ) => node . type === 'customBlock' ,
label : { defaultMessage : 'Custom Block' } ,
} ,
} ) ;
expect ( plugin . richTextBlocksStore ) . toHaveProperty ( 'customBlock' ) ;
plugin . addRichTextBlocks ( ( prev ) => {
delete prev . customBlock ;
return prev ;
} ) ;
expect ( plugin . richTextBlocksStore ) . not . toHaveProperty ( 'customBlock' ) ;
} ) ;
it ( 'should let users change an existing block' , ( ) => {
const plugin = new ContentManagerPlugin ( ) ;
plugin . addRichTextBlocks ( {
customBlock : {
isInBlocksSelector : true ,
renderElement : ( ) => null as unknown as JSX . Element ,
matchNode : ( node ) => node . type === 'customBlock' ,
label : { defaultMessage : 'Custom Block' } ,
} ,
} ) ;
expect ( plugin . richTextBlocksStore . customBlock ) . toHaveProperty ( 'label' , {
defaultMessage : 'Custom Block' ,
} ) ;
plugin . addRichTextBlocks ( ( prev ) => ( {
...prev ,
customBlock : {
...prev . customBlock ,
label : { defaultMessage : 'New Custom Block' } ,
} ,
} ) ) ;
expect ( plugin . richTextBlocksStore . customBlock ) . toHaveProperty ( 'label' , {
defaultMessage : 'New Custom Block' ,
} ) ;
} ) ;
it ( 'should throw an error if you pass an invalid object' , ( ) => {
const plugin = new ContentManagerPlugin ( ) ;
expect ( ( ) =>
// @ts -expect-error – testing it fails.
plugin . addRichTextBlocks ( 'I will break' )
) . toThrowErrorMatchingInlineSnapshot (
`"Expected the \`blocks\` passed to \`addRichTextBlocks\` to be an object or a function, but received string"`
) ;
} ) ;
it ( 'should throw an error if you pass an invalid function' , ( ) => {
const plugin = new ContentManagerPlugin ( ) ;
expect ( ( ) =>
// @ts -expect-error – testing it fails.
plugin . addRichTextBlocks ( ( ) => 'I will break' )
) . toThrowErrorMatchingInlineSnapshot (
`"Expected the \`blocks\` passed to \`addRichTextBlocks\` to be an object or a function, but received string"`
) ;
} ) ;
} ) ;
} ) ;