forked from UoEMainLibrary/dspace-datashare-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection-statistics-page.component.spec.ts
More file actions
118 lines (103 loc) · 3.95 KB
/
Copy pathcollection-statistics-page.component.spec.ts
File metadata and controls
118 lines (103 loc) · 3.95 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
107
108
109
110
111
112
113
114
115
116
117
118
import { CommonModule } from '@angular/common';
import { DebugElement } from '@angular/core';
import {
ComponentFixture,
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import {
ActivatedRoute,
Router,
} from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';
import { AuthService } from '../../core/auth/auth.service';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
import { PaginationService } from '../../core/pagination/pagination.service';
import { Collection } from '../../core/shared/collection.model';
import { UsageReport } from '../../core/statistics/models/usage-report.model';
import { UsageReportDataService } from '../../core/statistics/usage-report-data.service';
import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
import { StatisticsTableComponent } from '../statistics-table/statistics-table.component';
import { CollectionStatisticsPageComponent } from './collection-statistics-page.component';
describe('CollectionStatisticsPageComponent', () => {
let component: CollectionStatisticsPageComponent;
let de: DebugElement;
let fixture: ComponentFixture<CollectionStatisticsPageComponent>;
beforeEach(waitForAsync(() => {
const activatedRoute = {
data: observableOf({
scope: createSuccessfulRemoteDataObject(
Object.assign(new Collection(), {
id: 'collection_id',
}),
),
}),
};
const router = {
};
const usageReportService = {
getStatistic: (scope, type) => undefined,
};
spyOn(usageReportService, 'getStatistic').and.callFake(
(scope, type) => observableOf(
Object.assign(
new UsageReport(), {
id: `${scope}-${type}-report`,
points: [],
},
),
),
);
const nameService = {
getName: () => observableOf('test dso name'),
};
const authService = jasmine.createSpyObj('authService', {
isAuthenticated: observableOf(true),
setRedirectUrl: {},
});
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CommonModule,
CollectionStatisticsPageComponent,
StatisticsTableComponent,
],
providers: [
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: Router, useValue: router },
{ provide: UsageReportDataService, useValue: usageReportService },
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: DSONameService, useValue: nameService },
{ provide: AuthService, useValue: authService },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }), clearPagination: () => undefined } },
],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CollectionStatisticsPageComponent);
component = fixture.componentInstance;
de = fixture.debugElement;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should resolve to the correct collection', () => {
expect(de.query(By.css('.header')).nativeElement.id)
.toEqual('collection_id');
});
it('should show a statistics table for each usage report', () => {
expect(de.query(By.css('ds-statistics-table.collection_id-TotalVisits-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.collection_id-TotalVisitsPerMonth-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.collection_id-TopCountries-report')).nativeElement)
.toBeTruthy();
expect(de.query(By.css('ds-statistics-table.collection_id-TopCities-report')).nativeElement)
.toBeTruthy();
});
});