Skip to content

Commit 461ac24

Browse files
committed
something
1 parent 25b6ebf commit 461ac24

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
});

src/editors/supportedEditors.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import GameEditor from './containers/GameEditor';
88

99
import { 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

2024
export default supportedEditors;

0 commit comments

Comments
 (0)