forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathassociate-item-page.component.spec.ts
More file actions
106 lines (96 loc) · 3.62 KB
/
associate-item-page.component.spec.ts
File metadata and controls
106 lines (96 loc) · 3.62 KB
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
/* eslint-disable max-classes-per-file */
import { ComponentFixture, fakeAsync, TestBed, waitForAsync } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock';
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { ActivatedRoute, ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { AssociateItemPageComponent } from './associate-item-page.component';
import { Observable, of as observableOf } from 'rxjs';
import { By } from '@angular/platform-browser';
import { createSuccessfulRemoteDataObject } from '../shared/remote-data.utils';
import { Item } from '../core/shared/item.model';
describe('AssociateItemPageComponent', () => {
let comp: AssociateItemPageComponent;
let fixture: ComponentFixture<AssociateItemPageComponent>;
class AcceptAllGuard implements CanActivate {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return observableOf(true);
}
}
class AcceptNoneGuard implements CanActivate {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return observableOf(false);
}
}
const accesiblePages = ['accessible'];
const inaccesiblePages = ['inaccessible', 'inaccessibleDoubleGuard'];
const mockRoute = {
snapshot: {
firstChild: {
routeConfig: {
path: accesiblePages[0]
}
},
routerState: {
snapshot: undefined
}
},
routeConfig: {
children: [
{
path: accesiblePages[0],
canActivate: [AcceptAllGuard]
}, {
path: inaccesiblePages[0],
canActivate: [AcceptNoneGuard]
}, {
path: inaccesiblePages[1],
canActivate: [AcceptAllGuard, AcceptNoneGuard]
},
]
},
data: observableOf({dso: createSuccessfulRemoteDataObject(new Item())})
};
const mockRouter = {
routerState: {
snapshot: undefined
},
events: observableOf(undefined)
};
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderMock
}
})],
declarations: [AssociateItemPageComponent],
providers: [
{ provide: ActivatedRoute, useValue: mockRoute },
{ provide: Router, useValue: mockRouter },
AcceptAllGuard,
AcceptNoneGuard,
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(AssociateItemPageComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(AssociateItemPageComponent);
comp = fixture.componentInstance;
spyOn((comp as any).injector, 'get').and.callFake((a) => new a());
fixture.detectChanges();
}));
describe('ngOnInit', () => {
it('should enable tabs that the user can activate', fakeAsync(() => {
const enabledItems = fixture.debugElement.queryAll(By.css('a.nav-link'));
expect(enabledItems.length).toBe(accesiblePages.length);
}));
it('should disable tabs that the user can not activate', () => {
const disabledItems = fixture.debugElement.queryAll(By.css('button.nav-link.disabled'));
expect(disabledItems.length).toBe(inaccesiblePages.length);
});
});
});