Test coverage added.

This commit is contained in:
Mateusz Zagórski 2022-03-10 16:15:22 +01:00
parent ea1b4d73af
commit 88d3d65c30
2 changed files with 32 additions and 2 deletions

View File

@ -69,7 +69,11 @@ export default class MermaidUI extends Plugin {
command.listenTo( buttonView, 'execute', () => {
const mermaidItem = editor.execute( 'insertMermaidCommand' );
const mermaidItemViewElement = editor.editing.mapper.toViewElement( mermaidItem );
const mermaidItemDomElement = view.domConverter.viewToDom( mermaidItemViewElement, document );
let mermaidItemDomElement;
if ( mermaidItemViewElement ) {
mermaidItemDomElement = view.domConverter.viewToDom( mermaidItemViewElement, document );
}
view.scrollToTheSelection();
view.focus();

View File

@ -1,4 +1,6 @@
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph';
import Mermaid from '../src/mermaid';
import MermaidUI from '../src/mermaidui';
@ -19,7 +21,8 @@ describe( 'MermaidUI', () => {
editor = await ClassicEditor.create( domElement, {
plugins: [
Mermaid
Mermaid,
Paragraph
]
} );
} );
@ -61,6 +64,29 @@ describe( 'MermaidUI', () => {
} );
}
} );
it( 'should set focus inside textarea of a newly created mermaid', () => {
const button = editor.ui.componentFactory.create( 'mermaid' );
button.fire( 'execute' );
expect( document.activeElement.tagName ).to.equal( 'TEXTAREA' );
} );
it( 'should not crash if the button is fired inside model.change()', () => {
const button = editor.ui.componentFactory.create( 'mermaid' );
setModelData( editor.model,
'<paragraph>[foo]</paragraph>'
);
editor.model.change( () => {
button.fire( 'execute' );
} );
// As the conversion is to be executed after the model.change(), we don't have access to the fully prepared view and
// despite that, we should still successfully add mermaid widget to the editor, not requiring the selection change
// to the inside of the nonexisting textarea element.
} );
} );
} );