Skip to content

Commit

Permalink
[#12588] Added unit tests for CommentTableModalComponent (#12609)
Browse files Browse the repository at this point in the history
* Added unit tests to CommentTableModal Component

* Fixed test for CommentTableModalComponent

* Fixed test for CommentTableModalComponent

* fix import on comment-table-modal-compenent tests

* Made changes to CommentTableModalComponent tests

* Delete space on comment-table-modal.component tests

* Added Unit test for sessionEditFormComponent

* reverted sessionEditFormComponent tests

* fixed issues on session-edit-form-component tests

* fixed spacing on sessioneditformcomponent tests

* fixed spacing on sessioneditformcomponent tests

---------

Co-authored-by: Cedric Ong <[email protected]>
  • Loading branch information
kenneySiu and cedricongjh authored Dec 2, 2023
1 parent f2edb0a commit 752272e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import SpyInstance = jest.SpyInstance;
import { RichTextEditorModule } from '../../rich-text-editor/rich-text-editor.module';
import { TeammatesCommonModule } from '../../teammates-common/teammates-common.module';
import { CommentEditFormComponent } from '../comment-edit-form/comment-edit-form.component';
import { CommentRowComponent } from '../comment-row/comment-row.component';
import { CommentTableComponent } from '../comment-table/comment-table.component';
import { CommentTableComponent, CommentTableModel } from '../comment-table/comment-table.component';
import {
CommentVisibilityControlNamePipe,
CommentVisibilityTypeDescriptionPipe, CommentVisibilityTypeNamePipe, CommentVisibilityTypesJointNamePipe,
Expand All @@ -17,6 +18,20 @@ import { CommentTableModalComponent } from './comment-table-modal.component';
describe('CommentTableModalComponent', () => {
let component: CommentTableModalComponent;
let fixture: ComponentFixture<CommentTableModalComponent>;
const testModel: CommentTableModel = {
commentRows: [],
newCommentRow: {
commentEditFormModel: {
commentText: '',
isUsingCustomVisibilities: false,
showCommentTo: [],
showGiverNameTo: [],
},
isEditing: true,
},
isAddingNewComment: false,
isReadOnly: false,
};

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -52,4 +67,40 @@ describe('CommentTableModalComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should set isAddingNewComment to true in the model', () => {
const ngOnChangesSpy: SpyInstance = jest.spyOn(component.modelChange, 'emit');
component.model = testModel;
component.ngOnChanges();
expect(ngOnChangesSpy).toHaveBeenCalledWith({
...testModel,
isAddingNewComment: true,
});
});

it('should emit a DeleteCommentEvent with the correct index when triggerDeleteCommentEvent is called', () => {
const deleteCommentEventSpy: SpyInstance = jest.spyOn(component.deleteCommentEvent, 'emit');
const testIndex = 1;
component.triggerDeleteCommentEvent(testIndex);
expect(deleteCommentEventSpy).toHaveBeenCalledWith(testIndex);
});

it('should emit an UpdateCommentEvent with the correct index when triggerUpdateCommentEvent is called', () => {
const updateCommentEventSpy: SpyInstance = jest.spyOn(component.updateCommentEvent, 'emit');
const testIndex = 0;
component.triggerUpdateCommentEvent(testIndex);
expect(updateCommentEventSpy).toHaveBeenCalledWith(testIndex);
});

it('should emit a SaveNewCommentEvent when triggerSaveNewCommentEvent is called', () => {
const saveNewCommentEventSpy: SpyInstance = jest.spyOn(component.saveNewCommentEvent, 'emit');
component.triggerSaveNewCommentEvent();
expect(saveNewCommentEventSpy).toHaveBeenCalled();
});

it('should emit a ChangeFormModelEvent when triggerChangeFormModelEvent is called', () => {
const changeFormModelEventSpy = jest.spyOn(component.modelChange, 'emit');
component.triggerModelChange(testModel);
expect(changeFormModelEventSpy).toHaveBeenCalledWith(testModel);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ describe('SessionEditFormComponent', () => {
expect(time.hour).toEqual(21);
expect(time.minute).toEqual(0);
});

});

0 comments on commit 752272e

Please sign in to comment.