1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
import { MatTableModule } from '@angular/material/table';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatSortModule } from '@angular/material/sort';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { NgbModule, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { MenusComponent } from './menus.component';
import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
import { AdminService } from '../admin.service';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('MenusComponent', () => {
let component: MenusComponent;
let fixture: ComponentFixture<MenusComponent>;
let modalService: any;
let modalRef: any;
beforeEach(async(() => {
TestBed.configureTestingModule({
schemas:[CUSTOM_ELEMENTS_SCHEMA],
declarations: [ MenusComponent,
InformationModalComponent ],
imports: [ MatTableModule,
MatPaginatorModule,
MatSortModule,
HttpClientTestingModule,
NoopAnimationsModule,
NgbModule.forRoot() ]
}).
overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [InformationModalComponent] } });;
}));
beforeEach(async() => {
fixture = TestBed.createComponent(MenusComponent);
component = fixture.componentInstance;
fixture.detectChanges();
modalService = TestBed.get(NgbModal);
modalRef = modalService.open(InformationModalComponent);
spyOn(modalService, "open").and.returnValue(modalRef);
spyOn(modalRef, "result").and.returnValue('Ok');
});
it('should create', () => {
expect(component).toBeTruthy();
});
// it('should test getDismissReason function to call NgbModal.open function', () => {
// component.removeMenuItem({'label': 'abc'});
// expect(modalService.open).toHaveBeenCalled();
// });
// it('should test getDismissReason function', inject([AdminService],(adminservice) => {
// let spy = spyOn(adminservice, 'getFnMenuItems');
// component.getMenus();
// expect(spy).toHaveBeenCalled();
// }));
});
|