From 3f7db97d075a474720272c5227378544519612f3 Mon Sep 17 00:00:00 2001 From: Rafael Velazco Date: Fri, 2 Aug 2024 12:31:38 -0400 Subject: [PATCH] fix(UVE): Automatic page refresh after saving content changes (#29439) ### Proposed Changes * Automatic page refresh after saving content changes ### Videos #### **Publish** https://github.com/user-attachments/assets/4285ffa4-4a3b-4df2-81d7-bcc9293e047d #### **Save** https://github.com/user-attachments/assets/3149c501-cfe6-4ae7-bedf-f46d2ed8f108 --- .../dot-editable-text.component.spec.ts | 18 +++++++++++++++++- .../dot-editable-text.component.ts | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) 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 }); + } } /**