import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { CommentsModalComponent } from './comments.modal'; import { AddCommentComponent } from './components/add-comment/add.comment.component'; import { ListCommentsComponent } from './components/list-comments/list.comments.component'; import { BsModalRef, ModalModule } from 'ngx-bootstrap/modal'; import { FormsModule } from '@angular/forms'; import { CommentModalState, CommentModalType } from '@esp/esp-common'; import { RouterTestingModule } from '@angular/router/testing'; import { ModalService } from '../../../../../esp-iop/src/app/modal.service'; describe('Comments Modal Component', () => { let component: CommentsModalComponent; let fixture: ComponentFixture; let bsModalRef: BsModalRef; let modalService: ModalService; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [CommentsModalComponent, AddCommentComponent, ListCommentsComponent], providers: [BsModalRef, ModalService], imports: [ModalModule.forRoot(), FormsModule, ApolloModule, RouterTestingModule.withRoutes([])], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(CommentsModalComponent); component = fixture.componentInstance; component.data = { id: undefined, date: undefined, typeOfModal: undefined, gridCommentCapability: undefined, headerCommentCapability: undefined, config: { title: 'modal-view-comment', modalType: 'Comments', date: '9/09', image: { icon: 'fa-times', action: 'close' }, assign: 'assign', resolved: 'mark-as-resolved', 'jump-to': 'jump-to', }, i18n: {}, routeId: '', descriptionId: '', locationId: '', state: CommentModalState.LIST, filter: null, onAdd: jest.fn(), type: CommentModalType.COMMENT, deleteAll: true, }; bsModalRef = TestBed.inject(BsModalRef); modalService = TestBed.inject(ModalService); component.bsModalRef.hide = jest.fn(); fixture.detectChanges(); }); it('should call onClose', () => { bsModalRef.hide = jest.fn(); component.onClose(); expect(bsModalRef.hide).toHaveBeenCalled(); }); it('should call onAddComment', () => { component.onAddComment('comment text'); expect(component.data.onAdd).toHaveBeenCalled(); component.data.onAdd = null; component.onAddComment('comment text'); expect(component.data.onAdd).toBeFalsy(); }); it('should call onCancelComment', () => { component.onCancelComment(); expect(component.data.state).toBe(CommentModalState.LIST); }); it('should create', () => { expect(component).toBeTruthy(); }); });