-
Notifications
You must be signed in to change notification settings - Fork 2
/
emp-details.component.spec.ts
63 lines (53 loc) · 2.29 KB
/
emp-details.component.spec.ts
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
62
63
import { HttpEvent, HttpResponse, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { Emp, EmpService, SalService } from 'build/openapi';
import { of } from 'rxjs';
import { UsedMaterialModule } from 'src/material.modules';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { FormsModule } from '@angular/forms';
import { SalChangerComponent } from '../sal-changer/sal-changer.component';
import { EmpDetailsComponent } from './emp-details.component';
describe('EmpDetailsComponent', () => {
let component: EmpDetailsComponent;
let fixture: ComponentFixture<EmpDetailsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [EmpDetailsComponent, SalChangerComponent],
imports: [RouterTestingModule,
FormsModule,
UsedMaterialModule,
BrowserAnimationsModule],
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
})
.compileComponents();
fixture = TestBed.createComponent(EmpDetailsComponent);
component = fixture.componentInstance;
//component.emp = data;
fixture.detectChanges();
// given empService
const empService = TestBed.inject(EmpService);
const data: Emp = {
firstName: "first",
lastName: "last",
empId: 2,
mgrId: 1,
status: Emp.StatusEnum.Active,
type: Emp.TypeEnum.Manager,
userName: "man1"
};
const httpEventEmp: HttpEvent<Emp> = new HttpResponse<Emp>({ body: data });
spyOn(empService, 'getEmpById').and.returnValue(of(httpEventEmp));
// given mgrList
const httpEventMgrList: HttpEvent<Array<Emp>> = new HttpResponse<Array<Emp>>({ body: [data] });
spyOn(empService, 'findEmpsByType').and.returnValue(of(httpEventMgrList));
// given salService
const salService = TestBed.inject(SalService);
const httpEventSal: HttpEvent<string> = new HttpResponse<string>({ body: "123" });
spyOn(salService, 'getSalByEmpId').and.returnValue(of(httpEventSal));
});
it('should create', () => {
expect(component).toBeTruthy();
});
});