92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import {
|
|
HttpTestingController,
|
|
provideHttpClientTesting,
|
|
} from '@angular/common/http/testing';
|
|
import { provideHttpClient } from '@angular/common/http';
|
|
|
|
import { DashboardStatisticsService } from './dashboard-statistics.service';
|
|
|
|
describe('DashboardStatisticsService', () => {
|
|
let service: DashboardStatisticsService;
|
|
let httpMock: HttpTestingController;
|
|
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({
|
|
providers: [
|
|
DashboardStatisticsService,
|
|
provideHttpClient(),
|
|
provideHttpClientTesting(),
|
|
],
|
|
});
|
|
|
|
service = TestBed.inject(DashboardStatisticsService);
|
|
httpMock = TestBed.inject(HttpTestingController);
|
|
});
|
|
|
|
afterEach(() => {
|
|
httpMock.verify();
|
|
});
|
|
|
|
it('sends the selected institution and period for lower project status requests', () => {
|
|
service
|
|
.getEuProjectStatuses({ fromYear: 2024, toYear: 2026 }, 'I456')
|
|
.subscribe();
|
|
|
|
const request = httpMock.expectOne((req) => {
|
|
return req.url === '/api/dashboard/projects/eu/status';
|
|
});
|
|
|
|
expect(request.request.params.get('institution_id')).toBe('I456');
|
|
expect(request.request.params.get('from_year')).toBe('2024');
|
|
expect(request.request.params.get('to_year')).toBe('2026');
|
|
|
|
request.flush({
|
|
institution_id: 'https://openalex.org/I456',
|
|
organization_name: 'Selected institution',
|
|
ongoing: 1,
|
|
upcoming: 0,
|
|
completed: 2,
|
|
});
|
|
});
|
|
|
|
it('sends only the active institution for a topic treemap request', () => {
|
|
service.getTopicTreemap(2024, 2026, 'I789').subscribe();
|
|
|
|
const request = httpMock.expectOne((req) => {
|
|
return req.url === '/api/dashboard/topic-heatmap';
|
|
});
|
|
|
|
expect(request.request.params.get('institution_id')).toBe('I789');
|
|
expect(request.request.params.get('from_year')).toBe('2024');
|
|
expect(request.request.params.get('to_year')).toBe('2026');
|
|
|
|
request.flush({
|
|
institution_id: 'https://openalex.org/I789',
|
|
organization_name: 'Selected institution',
|
|
years: [],
|
|
fields: [],
|
|
});
|
|
});
|
|
|
|
it('keeps all as the default lower-dashboard institution scope', () => {
|
|
service.getBundProjectTopics().subscribe();
|
|
|
|
const request = httpMock.expectOne((req) => {
|
|
return req.url === '/api/dashboard/projects/bund/topics';
|
|
});
|
|
|
|
expect(request.request.params.get('institution_id')).toBe('all');
|
|
expect(request.request.params.has('from_year')).toBeFalse();
|
|
expect(request.request.params.has('to_year')).toBeFalse();
|
|
|
|
request.flush({
|
|
institution_id: 'https://openalex.org/I123',
|
|
organization_name: 'Root organization',
|
|
project_count: 0,
|
|
matched_project_count: 0,
|
|
topics: [],
|
|
});
|
|
});
|
|
});
|