Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('CollectionStatisticsPageComponent', () => {
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: DSONameService, useValue: nameService },
{ provide: AuthService, useValue: authService },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }) } },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }), clearPagination: () => undefined } },
],
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('CommunityStatisticsPageComponent', () => {
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: DSONameService, useValue: nameService },
{ provide: AuthService, useValue: authService },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }) } },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }), clearPagination: () => undefined } },
],
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('ItemStatisticsPageComponent', () => {
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: DSONameService, useValue: nameService },
{ provide: AuthService, useValue: authService },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }) } },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }), clearPagination: () => undefined } },
],
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('SiteStatisticsPageComponent', () => {
{ provide: DSONameService, useValue: nameService },
{ provide: SiteDataService, useValue: siteService },
{ provide: AuthService, useValue: authService },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }) } },
{ provide: PaginationService, useValue: { getCurrentPagination: () => observableOf({ currentPage: 1, pageSize: 10 }), clearPagination: () => undefined } },
],
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('StatisticsTableComponent', () => {

const paginationService = {
getCurrentPagination: (_id: string, _options: PaginationComponentOptions) => currentPagination$.asObservable(),
clearPagination: (_id: string) => undefined,
};

const setPage = (currentPage: number, pageSize = 10) => {
Expand Down Expand Up @@ -221,4 +222,25 @@ describe('StatisticsTableComponent', () => {
expect(de.query(By.css(`td.item_${numberOfPoints - 1}-views-data`))).toBeTruthy();
});
});

describe('on destroy', () => {

it('should clear its own pagination params so they do not leak to the next scope', () => {
component.report = Object.assign(new UsageReport(), {
id: 'uuid_TotalVisits',
points: [],
});
component.ngOnInit();
const spy = spyOn(paginationService, 'clearPagination');

fixture.destroy();

expect(spy).toHaveBeenCalledWith('stats-uuid_TotalVisits');
});
Comment thread
jr-rk marked this conversation as resolved.

it('should not throw when destroyed before initialisation', () => {
const uninitialised = TestBed.createComponent(StatisticsTableComponent).componentInstance;
expect(() => uninitialised.ngOnDestroy()).not.toThrow();
});
Comment thread
jr-rk marked this conversation as resolved.
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import {
Component,
Input,
OnDestroy,
OnInit,
} from '@angular/core';
import {
Expand Down Expand Up @@ -43,7 +44,7 @@ import { PaginationComponentOptions } from '../../shared/pagination/pagination-c
standalone: true,
imports: [NgIf, NgFor, AsyncPipe, TranslateModule, PaginationComponent],
})
export class StatisticsTableComponent implements OnInit {
export class StatisticsTableComponent implements OnInit, OnDestroy {

/**
* The usage report to display a statistics table for
Expand Down Expand Up @@ -110,6 +111,14 @@ export class StatisticsTableComponent implements OnInit {
);
}

ngOnDestroy() {
// Drop this table's page/rpp query params so they don't leak (via queryParamsHandling: 'merge') to the next
// scope's statistics page. Guarded in case the component is destroyed before ngOnInit ran.
if (this.paginationOptions) {
this.paginationService.clearPagination(this.paginationOptions.id);
}
Comment thread
jr-rk marked this conversation as resolved.
Outdated
}

/**
* Get the row label to display for a statistics point.
* @param point the statistics point to get the label for
Expand Down
Loading