/
board.component.spec.ts
114 lines (106 loc) · 4.45 KB
/
board.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
103
104
105
106
107
108
109
110
111
112
113
114
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatChipsModule } from '@angular/material/chips';
import { MatDialogModule } from '@angular/material/dialog';
import { MatDividerModule } from '@angular/material/divider';
import { MatIconModule } from '@angular/material/icon';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { AppInitService, DspActionModule } from '@dasch-swiss/dsp-ui';
import { of } from 'rxjs';
import { DspApiConfigToken, DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { ErrorComponent } from 'src/app/main/error/error.component';
import { TestConfig } from 'test.config';
import { AttributionTabViewComponent } from './attribution-tab-view/attribution-tab-view.component';
import { BoardComponent } from './board.component';
import { ContactsTabViewComponent } from './contacts-tab-view/contacts-tab-view.component';
import { DatasetTabViewComponent } from './dataset-tab-view/dataset-tab-view.component';
import { ProjectTabViewComponent } from './project-tab-view/project-tab-view.component';
import { TermsTabViewComponent } from './terms-tab-view/terms-tab-view.component';
describe('BoardComponent', () => {
let component: BoardComponent;
let fixture: ComponentFixture<BoardComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
BoardComponent,
DialogComponent,
ErrorComponent,
AttributionTabViewComponent,
ContactsTabViewComponent,
DatasetTabViewComponent,
ProjectTabViewComponent,
TermsTabViewComponent
],
imports: [
BrowserAnimationsModule,
DspActionModule,
MatChipsModule,
MatDialogModule,
MatDividerModule,
MatIconModule,
RouterTestingModule
],
providers: [
{
provide: ActivatedRoute,
useValue: {
parent: {
paramMap: of({
get: (param: string) => {
if (param === 'shortcode') {
return TestConfig.ProjectCode;
}
}
})
}
}
},
AppInitService,
{
provide: DspApiConfigToken,
useValue: TestConfig.ApiConfig
},
{
provide: DspApiConnectionToken,
useValue: new KnoraApiConnection(TestConfig.ApiConfig)
}
]
}).compileComponents();
}));
// mock localStorage
beforeEach(() => {
let store = {};
spyOn(localStorage, 'getItem').and.callFake(
(key: string): string => store[key] || null
);
spyOn(localStorage, 'removeItem').and.callFake(
(key: string): void => {
delete store[key];
}
);
spyOn(localStorage, 'setItem').and.callFake(
(key: string, value: string): string => (store[key] = <any>value)
);
spyOn(localStorage, 'clear').and.callFake(() => {
store = {};
});
});
beforeEach(() => {
localStorage.setItem('session', JSON.stringify(TestConfig.CurrentSession));
fixture = TestBed.createComponent(BoardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect<any>(localStorage.getItem('session')).toBe(
JSON.stringify(TestConfig.CurrentSession)
);
expect(component).toBeTruthy();
});
// todo: check the project name, if there is description and keywords, check if we can edit the project info if the user is project admin or system admin (edit btn displayed)
// check if you get the project by shortcode
// check if you get the project metadata
});