diff --git a/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.spec.ts b/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.spec.ts index f9f3eff813db..940a8f860d83 100644 --- a/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.spec.ts +++ b/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.spec.ts @@ -32,7 +32,8 @@ const TINYMCE_EDITOR_MOCK: unknown = { focus: jest.fn(), getContent: (_data: unknown) => '', isDirty: () => false, - hasFocus: () => false + hasFocus: () => false, + setContent: jest.fn() }; const TINYMCE_EDITOR_PROPERTY_MOCK = { @@ -134,6 +135,21 @@ describe('DotEditableTextComponent', () => { jest.spyOn(mockedDotcmsClient, 'isInsideEditor').mockReturnValue(true); }); + it('should set content with the right format when the contentlet changes', () => { + spectator.detectChanges(); + mockEditorFn(spectator); + + const editorComponent = spectator.query(EditorComponent) as EditorComponent; + const spySetContent = jest.spyOn(editorComponent.editor, 'setContent'); + + spectator.setInput('contentlet', { + ...dotcmsContentletMock, + title: 'New title' + }); + spectator.detectChanges(); + expect(spySetContent).toHaveBeenCalledWith('New title', { format: 'text' }); + }); + describe('Configuration', () => { describe('Editor Configuration', () => { it('should set a plain mode by default', () => { diff --git a/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.ts b/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.ts index c51d414c1347..67bdc3d2db94 100644 --- a/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.ts +++ b/core-web/libs/sdk/angular/src/lib/components/dot-editable-text/dot-editable-text.component.ts @@ -116,7 +116,7 @@ export class DotEditableTextComponent implements OnInit, OnChanges { * @memberof DotEditableTextComponent */ get editor() { - return this.editorComponent.editor; + return this.editorComponent?.editor; } /** @@ -170,6 +170,9 @@ export class DotEditableTextComponent implements OnInit, OnChanges { ngOnChanges() { this.content = this.contentlet[this.fieldName] || ''; + if (this.editor) { + this.editor.setContent(this.content, { format: this.format }); + } } /**