Skip to content

Commit c9d6cab

Browse files
committed
Merged ux-plus-cris-2024_02_x into task/ux-plus-cris-2024_02_x/UXP-253
2 parents b2b3754 + cc2361e commit c9d6cab

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/app/shared/markdown-editor/markdown-editor.component.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,27 @@ describe('MarkdownEditorComponent', () => {
4646

4747
});
4848

49+
describe('editValue setter', () => {
50+
it('should set _editValue when value is provided and _editValue is empty', () => {
51+
component.editValue = 'Initial Value';
52+
expect(component.editValue).toBe('Initial Value');
53+
});
54+
55+
it('should not overwrite _editValue if it is already set', () => {
56+
component.editValue = 'Existing Value';
57+
component.editValue = 'New Value';
58+
expect(component.editValue).toBe('Existing Value');
59+
});
60+
61+
it('should handle null value gracefully', () => {
62+
component.editValue = null;
63+
expect(component.editValue).toBe('');
64+
});
65+
66+
it('should handle empty string value gracefully', () => {
67+
component.editValue = '';
68+
expect(component.editValue).toBe('');
69+
});
70+
});
71+
4972
});

src/app/shared/markdown-editor/markdown-editor.component.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ import {
2323
QuillEditorComponent,
2424
],
2525
})
26-
export class MarkdownEditorComponent {
26+
export class MarkdownEditorComponent {
2727
/**
2828
* Markdown Editor String value
2929
*/
30-
@Input() editValue = '';
30+
@Input() set editValue(value: string) {
31+
if (value && !this._editValue) {
32+
this._editValue = value;
33+
}
34+
}
35+
36+
get editValue(): string {
37+
return this._editValue;
38+
}
39+
40+
private _editValue = '';
3141
/**
3242
* Indicates whether the markdown editor is required.
3343
*/
@@ -43,7 +53,7 @@ export class MarkdownEditorComponent {
4353
*/
4454
modules: QuillModules = {
4555
'toolbar': {
46-
container: [
56+
container: [
4757
['bold', 'italic', 'underline', 'strike'],
4858
[{ 'header': 1 }, { 'header': 2 }],
4959
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
@@ -69,6 +79,7 @@ export class MarkdownEditorComponent {
6979
*/
7080
updateContent(content: ContentChange) {
7181
const sanitizedContent = this.sanitizer.sanitize(SecurityContext.HTML, content.html);
72-
this.editValueChange.emit(sanitizedContent);
82+
const normalizedContent = sanitizedContent?.replace(/ /g, ' ');
83+
this.editValueChange.emit(normalizedContent);
7384
}
7485
}

0 commit comments

Comments
 (0)