editor.js/test/cypress/fixtures/tools/ToolMock.ts
e11sy da4257a67f
Feat (Conversion-config): pass target tool config to the conversionConfig.import method (#2848)
* pass config to the conversionConfig.import method

- Now `convertStringToBlockData` method passes target tool config the import method
- Fixed types in convesion config file (somehow imprort could return function that returns string, but import should return method that would return ToolData) this caused just type error that never been reached because types were actually ignored
- Added test that checks, that import method actualy gets passed config

* update changelog

* eslint fix

* updated test description

* jsdoc improved

* typos in changelog
2024-10-17 19:38:02 +03:00

54 lines
1.1 KiB
TypeScript

import type { BlockTool, BlockToolConstructorOptions } from '../../../../types';
/**
* Simple structure for Tool data
*/
export interface MockToolData {
text: string;
}
/**
* Common class for Tool mocking.
* Extend this class to create a mock for your Tool with specific properties.
*/
export default class ToolMock implements BlockTool {
/**
* Tool data
*/
private data: MockToolData;
/**
* Creates new Tool instance
*
* @param options - tool constructor options
*/
constructor(options: BlockToolConstructorOptions<MockToolData>) {
this.data = options.data;
}
/**
* Renders a single content editable element as tools element
*/
public render(): HTMLElement {
const contenteditable = document.createElement('div');
if (this.data && this.data.text) {
contenteditable.innerHTML = this.data.text;
}
contenteditable.contentEditable = 'true';
return contenteditable;
}
/**
* Save method mock, returns block innerHTML
*
* @param block - element rendered by the render method
*/
public save(block: HTMLElement): MockToolData {
return {
text: block.innerHTML,
};
}
}