[ADF-5580] emit commentAdded event from adf-comments component (#10966)

* [ADF-5580] emit commentAdded event from adf-comments component

* [ADF-5580] Emit commentAdded event from adf-comments and expose it in adf-node-comments

* [ADF-5580] Emit commentAdded event from NodeCommentsComponent, add unit test, and update docs

* [ADF-5580] Add unit test for commentAdded output in NodeCommentsComponent, update docs and create testing utils

* [ADF-5580] Mark debugElement as readOnly

* [ADF-5580] Add mock services and fix unit test setup

* [ADF-5580] Reuse shared comment mocks across multiple test files

* [ADF-5580] Align comments component documentation

* [ADF-5580] Remove redundant setup and use ContentTestingModule in comment components tests
This commit is contained in:
Shivangi Shree
2025-07-01 13:54:07 +05:30
committed by GitHub
parent 5d043e6987
commit 6dafcb4447
7 changed files with 126 additions and 15 deletions

View File

@@ -26,6 +26,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NoopTranslateModule } from '../testing/noop-translate.module';
import { UnitTestingUtils } from '../testing/unit-testing-utils';
import { MatError } from '@angular/material/form-field';
import { CommentModel } from '../models';
describe('CommentsComponent', () => {
let component: CommentsComponent;
@@ -122,6 +123,32 @@ describe('CommentsComponent', () => {
expect(testingUtils.getByCSS('#comment-input')).not.toBeNull();
});
it('should emit commentAdded when a new comment is added successfully', () => {
const emitSpy = spyOn(component.commentAdded, 'emit');
const mockComment: CommentModel = {
id: 'comment-123',
message: 'New test comment',
created: new Date(),
createdBy: {
id: 'user-1',
displayName: 'John Doe',
avatarId: 'avatar-001'
},
isSelected: false,
hasAvatarPicture: false,
userDisplayName: 'John Doe',
userInitials: 'JD'
};
component.id = '123';
component.commentControl.setValue('New test comment');
addCommentSpy.and.returnValue(of(mockComment));
component.addComment();
expect(emitSpy).toHaveBeenCalledWith(mockComment);
});
it('should not display comments input when the entity is readonly', async () => {
component.readOnly = true;

View File

@@ -57,6 +57,10 @@ export class CommentsComponent implements OnChanges {
@Output()
error = new EventEmitter<any>();
/** Emits when a new comment is added */
@Output()
commentAdded = new EventEmitter<CommentModel>();
comments: CommentModel[] = [];
beingAdded: boolean = false;
@@ -113,6 +117,7 @@ export class CommentsComponent implements OnChanges {
next: (res) => {
this.addToComments(res);
this.commentControl.reset();
this.commentAdded.emit(res);
},
error: (err) => {
this.error.emit(err);