/
viewer-playground.component.spec.ts
102 lines (87 loc) · 3.05 KB
/
viewer-playground.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';
import {
MockProjects,
MockResource,
MockUsers,
ProjectsEndpointAdmin,
ReadResource,
ResourcesEndpointV2
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, DspViewerModule, UserService } from '@dasch-swiss/dsp-ui';
import { ViewerPlaygroundComponent } from './viewer-playground.component';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
describe('ViewerPlaygroundComponent', () => {
let component: ViewerPlaygroundComponent;
let fixture: ComponentFixture<ViewerPlaygroundComponent>;
beforeEach(async(() => {
const apiSpyObj = {
admin: {
projectsEndpoint: jasmine.createSpyObj('projectsEndpoint', ['getProjectByIri'])
},
v2: {
res: jasmine.createSpyObj('res', ['getResource'])
}
};
const userServiceSpy = jasmine.createSpyObj('UserService', ['getUser']);
TestBed.configureTestingModule({
declarations: [
ViewerPlaygroundComponent
],
imports: [
DspViewerModule,
MatIconModule,
MatTooltipModule
],
providers: [
{
provide: DspApiConnectionToken,
useValue: apiSpyObj
},
{
provide: UserService,
useValue: userServiceSpy
},
]
})
.compileComponents();
}));
beforeEach(() => {
const resSpy = TestBed.inject(DspApiConnectionToken);
(resSpy.v2.res as jasmine.SpyObj<ResourcesEndpointV2>).getResource.and.callFake(
(id: string) => {
return MockResource.getTestThing().pipe(
map(
(res: ReadResource) => {
res.id = id;
return res;
}
));
}
);
const adminSpy = TestBed.inject(DspApiConnectionToken);
// mock getProjectByIri response
(adminSpy.admin.projectsEndpoint as jasmine.SpyObj<ProjectsEndpointAdmin>).getProjectByIri.and.callFake(
() => {
const project = MockProjects.mockProject();
return of(project);
}
);
const userSpy = TestBed.inject(UserService);
// mock getUserByIri response
(userSpy as jasmine.SpyObj<UserService>).getUser.and.callFake(
() => {
const user = MockUsers.mockUser();
return of(user.body);
}
);
fixture = TestBed.createComponent(ViewerPlaygroundComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});