File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import supportedEditors , { registerEditor } from './supportedEditors' ;
2+
3+ describe ( 'Pluggable Editors' , ( ) => {
4+ it ( 'should allow registering a new editor' , ( ) => {
5+ const MockEditor = ( ) => < div > Mock Editor</ div > ;
6+ const newBlockType = 'test-block-type' ;
7+
8+ expect ( supportedEditors [ newBlockType ] ) . toBeUndefined ( ) ;
9+
10+ registerEditor ( newBlockType , MockEditor ) ;
11+
12+ expect ( supportedEditors [ newBlockType ] ) . toBe ( MockEditor ) ;
13+ } ) ;
14+
15+ it ( 'should allow overwriting an existing editor' , ( ) => {
16+ const MockEditor = ( ) => < div > New Mock Editor</ div > ;
17+ const existingBlockType = 'html' ; // Assuming 'html' exists
18+
19+ const originalEditor = supportedEditors [ existingBlockType ] ;
20+ expect ( originalEditor ) . toBeDefined ( ) ;
21+
22+ registerEditor ( existingBlockType , MockEditor ) ;
23+
24+ expect ( supportedEditors [ existingBlockType ] ) . toBe ( MockEditor ) ;
25+
26+ // Restore original editor for other tests
27+ registerEditor ( existingBlockType , originalEditor ) ;
28+ } ) ;
29+ } ) ;
Original file line number Diff line number Diff line change @@ -8,13 +8,17 @@ import GameEditor from './containers/GameEditor';
88
99import { blockTypes } from './data/constants/app' ;
1010
11- const supportedEditors = {
11+ const supportedEditors : Record < string , any > = {
1212 [ blockTypes . html ] : TextEditor ,
1313 [ blockTypes . video ] : VideoEditor ,
1414 [ blockTypes . problem ] : ProblemEditor ,
1515 [ blockTypes . video_upload ] : VideoUploadEditor ,
1616 // ADDED_EDITORS GO BELOW
1717 [ blockTypes . game ] : GameEditor ,
18- } as const ;
18+ } ;
19+
20+ export const registerEditor = ( blockType : string , editorComponent : any ) => {
21+ supportedEditors [ blockType ] = editorComponent ;
22+ } ;
1923
2024export default supportedEditors ;
You can’t perform that action at this time.
0 commit comments