Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12588] Added unit tests for CommentTableModalComponent #12609

Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ 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 @@ -18,6 +20,21 @@ 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({
declarations: [
Expand Down Expand Up @@ -52,4 +69,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);
});
});
Loading