Skip to content

Commit 8c4dead

Browse files
author
Mykhaylo Boychuk
committed
[DSC-2607] fix test
1 parent b08a3ed commit 8c4dead

2 files changed

Lines changed: 139 additions & 126 deletions

File tree

Lines changed: 135 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,161 @@
11
import { of as observableOf } from 'rxjs';
22

3+
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
4+
35
export class UsageReportServiceStub {
46

7+
findById(id: string, ...args: any[]) {
8+
const allReports = this._getReports();
9+
const report = allReports.find(r => r.id === id) || allReports[0];
10+
return createSuccessfulRemoteDataObject$(report);
11+
}
12+
513
searchStatistics(uri: string, page: number, size: number, categoryId?: string, startDate?: string, endDate?: string) {
6-
return observableOf(
7-
[
8-
{
9-
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
10-
'type': 'usagereport',
11-
'reportType': 'TotalVisits',
12-
'viewMode': 'chart.bar',
13-
'points': [
14-
{
15-
'label': '1911e8a4-6939-490c-b58b-a5d70f8d91fb',
16-
'type': 'item',
17-
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb',
18-
'values': {
19-
'views': 3,
20-
},
21-
},
22-
],
23-
'_links' : {
24-
'self' : {
25-
'href' : 'https://{dspace.url}/server/api/statistics/usagereports/1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
14+
return observableOf(this._getReports());
15+
}
16+
17+
_getReports() {
18+
return [
19+
{
20+
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
21+
'type': 'usagereport',
22+
'reportType': 'TotalVisits',
23+
'viewMode': 'chart.bar',
24+
'points': [
25+
{
26+
'label': '1911e8a4-6939-490c-b58b-a5d70f8d91fb',
27+
'type': 'item',
28+
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb',
29+
'values': {
30+
'views': 3,
2631
},
2732
},
33+
],
34+
'_links' : {
35+
'self' : {
36+
'href' : 'https://{dspace.url}/server/api/statistics/usagereports/1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
37+
},
2838
},
29-
{
30-
'id': '0aa1fe0c-e173-4a36-a526-5c157dedfc07_TotalVisitsPerMonth',
31-
'points': [
32-
{
33-
'id': 'September 2020',
34-
'label': 'September 2020',
35-
'values': {
36-
'views': 0,
37-
},
38-
'type': 'date',
39-
},
40-
{
41-
'id': 'October 2020',
42-
'label': 'October 2020',
43-
'values': {
44-
'views': 0,
45-
},
46-
'type': 'date',
39+
},
40+
{
41+
'id': '0aa1fe0c-e173-4a36-a526-5c157dedfc07_TotalVisitsPerMonth',
42+
'points': [
43+
{
44+
'id': 'September 2020',
45+
'label': 'September 2020',
46+
'values': {
47+
'views': 0,
4748
},
48-
{
49-
'id': 'November 2020',
50-
'label': 'November 2020',
51-
'values': {
52-
'views': 0,
53-
},
54-
'type': 'date',
49+
'type': 'date',
50+
},
51+
{
52+
'id': 'October 2020',
53+
'label': 'October 2020',
54+
'values': {
55+
'views': 0,
5556
},
56-
{
57-
'id': 'December 2020',
58-
'label': 'December 2020',
59-
'values': {
60-
'views': 0,
61-
},
62-
'type': 'date',
57+
'type': 'date',
58+
},
59+
{
60+
'id': 'November 2020',
61+
'label': 'November 2020',
62+
'values': {
63+
'views': 0,
6364
},
64-
{
65-
'id': 'January 2021',
66-
'label': 'January 2021',
67-
'values': {
68-
'views': 0,
69-
},
70-
'type': 'date',
65+
'type': 'date',
66+
},
67+
{
68+
'id': 'December 2020',
69+
'label': 'December 2020',
70+
'values': {
71+
'views': 0,
7172
},
72-
{
73-
'id': 'February 2021',
74-
'label': 'February 2021',
75-
'values': {
76-
'views': 67,
77-
},
78-
'type': 'date',
73+
'type': 'date',
74+
},
75+
{
76+
'id': 'January 2021',
77+
'label': 'January 2021',
78+
'values': {
79+
'views': 0,
7980
},
80-
{
81-
'id': 'March 2021',
82-
'label': 'March 2021',
83-
'values': {
84-
'views': 234,
85-
},
86-
'type': 'date',
81+
'type': 'date',
82+
},
83+
{
84+
'id': 'February 2021',
85+
'label': 'February 2021',
86+
'values': {
87+
'views': 67,
8788
},
88-
],
89-
'type': 'usagereport',
90-
'reportType': 'TotalVisitsPerMonth',
91-
'viewMode': 'chart.line',
92-
'_links': {
93-
'self': {
94-
'href': 'https://dspacecris7.4science.cloud/server/api/statistics/usagereports/0aa1fe0c-e173-4a36-a526-5c157dedfc07_TotalVisitsPerMonth',
89+
'type': 'date',
90+
},
91+
{
92+
'id': 'March 2021',
93+
'label': 'March 2021',
94+
'values': {
95+
'views': 234,
9596
},
97+
'type': 'date',
98+
},
99+
],
100+
'type': 'usagereport',
101+
'reportType': 'TotalVisitsPerMonth',
102+
'viewMode': 'chart.line',
103+
'_links': {
104+
'self': {
105+
'href': 'https://dspacecris7.4science.cloud/server/api/statistics/usagereports/0aa1fe0c-e173-4a36-a526-5c157dedfc07_TotalVisitsPerMonth',
96106
},
97107
},
98-
{
99-
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalDownloads',
100-
'type': 'usagereport',
101-
'reportType': 'TotalDownloads',
102-
'viewMode': 'chart.pie',
103-
'points': [
104-
{
105-
'label': '8d33bdfb-e7ba-43e6-a93a-f445b7e8a1e2',
106-
'type': 'bitstream',
107-
'id': '8d33bdfb-e7ba-43e6-a93a-f445b7e8a1e2',
108-
'values': {
109-
'downloads': 8,
110-
},
111-
},
112-
],
113-
'_links' : {
114-
'self' : {
115-
'href' : 'https://{dspace.url}/server/api/statistics/usagereports/1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
108+
},
109+
{
110+
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalDownloads',
111+
'type': 'usagereport',
112+
'reportType': 'TotalDownloads',
113+
'viewMode': 'chart.pie',
114+
'points': [
115+
{
116+
'label': '8d33bdfb-e7ba-43e6-a93a-f445b7e8a1e2',
117+
'type': 'bitstream',
118+
'id': '8d33bdfb-e7ba-43e6-a93a-f445b7e8a1e2',
119+
'values': {
120+
'downloads': 8,
116121
},
117122
},
123+
],
124+
'_links' : {
125+
'self' : {
126+
'href' : 'https://{dspace.url}/server/api/statistics/usagereports/1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
127+
},
118128
},
119-
{
120-
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb_TopCountries',
121-
'type': 'usagereport',
122-
'reportType': 'TopCountries',
123-
'viewMode': 'map',
124-
'points': [
125-
{
126-
'label': 'United States',
127-
'type': 'country',
128-
'id': 'US',
129-
'values': {
130-
'views': 2,
131-
},
132-
},
133-
{
134-
'label': 'China',
135-
'type': 'country',
136-
'id': 'CN',
137-
'values': {
138-
'views': 1,
139-
},
129+
},
130+
{
131+
'id': '1911e8a4-6939-490c-b58b-a5d70f8d91fb_TopCountries',
132+
'type': 'usagereport',
133+
'reportType': 'TopCountries',
134+
'viewMode': 'map',
135+
'points': [
136+
{
137+
'label': 'United States',
138+
'type': 'country',
139+
'id': 'US',
140+
'values': {
141+
'views': 2,
140142
},
141-
],
142-
'_links' : {
143-
'self' : {
144-
'href' : 'https://{dspace.url}/server/api/statistics/usagereports/1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
143+
},
144+
{
145+
'label': 'China',
146+
'type': 'country',
147+
'id': 'CN',
148+
'values': {
149+
'views': 1,
145150
},
146151
},
152+
],
153+
'_links' : {
154+
'self' : {
155+
'href' : 'https://{dspace.url}/server/api/statistics/usagereports/1911e8a4-6939-490c-b58b-a5d70f8d91fb_TotalVisits',
156+
},
147157
},
148-
],
149-
);
158+
},
159+
];
150160
}
151161
}

src/app/statistics-page/cris-statistics-page/statistics-map/statistics-map.component.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import { GoogleChartInterface } from 'ng2-google-charts';
99
import { ExportService } from '../../../core/export-service/export.service';
1010
import { UsageReport } from '../../../core/statistics/models/usage-report.model';
1111
import { USAGE_REPORT } from '../../../core/statistics/models/usage-report.resource-type';
12+
import { UsageReportDataService } from '../../../core/statistics/usage-report-data.service';
13+
import { UsageReportServiceStub } from '../../../shared/testing/usage-report-service.stub';
1214
import { StatisticsType } from '../statistics-type.model';
1315
import { StatisticsMapComponent } from './statistics-map.component';
1416

1517
describe('StatisticsMapComponent', () => {
18+
const usageReportServiceStub = new UsageReportServiceStub();
1619
let component: StatisticsMapComponent;
1720
let fixture: ComponentFixture<StatisticsMapComponent>;
1821
const report: UsageReport = {
@@ -66,7 +69,7 @@ describe('StatisticsMapComponent', () => {
6669
await TestBed.configureTestingModule({
6770
imports: [TranslateModule.forRoot(), StatisticsMapComponent],
6871
providers: [
69-
// { provide: ExportService, useValue: exportServiceMock }
72+
{ provide: UsageReportDataService, useValue: usageReportServiceStub },
7073
],
7174
})
7275
.compileComponents();

0 commit comments

Comments
 (0)