import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; import { BsModalRef } from 'ngx-bootstrap/modal'; import { ShareModalComponent } from './share.modal.component'; import { CommentModule } from 'projects/esp-common/src/lib/components/functional/comment-component/comment.module'; import { SimpleTabsModule } from 'projects/esp-common/src/lib/components/functional/simple-tabs/simple.tabs.module'; import { FormsModule } from '@angular/forms'; import { MultiselectDropdownModule } from 'projects/esp-common/src/lib/components/generic/multiselect-dropdown/multiselect-dropdown.module'; import { SHARE_MODAL, SHARE_MODAL_USERS_DROPDOWN } from 'projects/esp-common/src/lib/mockup'; import { ApolloModule } from 'apollo-angular'; import { of } from 'rxjs'; import { GraphQLService } from 'projects/esp-common/src/lib/utils/graphql.service'; import { LoaderService } from 'projects/esp-common/src/lib/components/generic/loader/loader.service'; const getUsersResponse = { data: { getUsers: { users: SHARE_MODAL_USERS_DROPDOWN } }, }; describe('ShareModalComponent', () => { let component: ShareModalComponent; let fixture: ComponentFixture; let modelRef: BsModalRef; let loader: LoaderService; const graphQLMockService = { query: () => of(getUsersResponse) }; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [ShareModalComponent], imports: [CommentModule, SimpleTabsModule, FormsModule, MultiselectDropdownModule, ApolloModule], providers: [BsModalRef, { provide: GraphQLService, useValue: graphQLMockService }], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(ShareModalComponent); component = fixture.componentInstance; modelRef = TestBed.inject(BsModalRef); loader = TestBed.inject(LoaderService); component.config = SHARE_MODAL; component.selectedTab = null; component.message = null; component.users = null; component.problems = null; component.subject = ''; }); it('should call ngOnInit', () => { component.ngOnInit(); expect(component.problems).toBeTruthy(); }); it('should call onCommentUpdates', () => { const event = 'some event'; component.onCommentUpdates(event); expect(component.message).toBeTruthy(); }); it('should call onTabSelection', () => { const event = 'some tab'; component.onTabSelection(event); expect(component.selectedTab).toBe(event); }); it('should call onApply', () => { component.onClose = jest.fn(); // scenario 1 component.selectedTab = SHARE_MODAL.tabs[0]; component.onApply(); // scenario 2 component.selectedTab = SHARE_MODAL.tabs[1]; component.onApply(); expect(component.onClose).toHaveBeenCalled(); }); it('should call onClose', () => { modelRef.hide = jest.fn(); component.onClose(); expect(modelRef.hide).toHaveBeenCalled(); }); it('should create', () => { expect(component).toBeTruthy(); }); });