mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-1873] Remove all deprecated code from ADF (#4145)
* remove deprecated code part 1 * remove deprecation step 2 * fix spellcheck * fix * fix lint * fix not used import * remove deprecation * fix test first part after remove deprecation * fix test * fix sidebar demo shell
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<div *ngIf="pagination?.hasMoreItems || isLoading" class="adf-infinite-pagination">
|
||||
isLoading : {{isLoading}}
|
||||
<button mat-button
|
||||
*ngIf="!isLoading"
|
||||
class="adf-infinite-pagination-load-more"
|
||||
|
@@ -23,6 +23,33 @@ import { PaginatedComponent } from './paginated-component.interface';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { setupTestBed } from '../testing/setupTestBed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { Component } from '@angular/core';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
|
||||
@Component({
|
||||
template: ``
|
||||
})
|
||||
class TestPaginatedComponent implements PaginatedComponent {
|
||||
|
||||
private _pagination: BehaviorSubject<PaginationModel>;
|
||||
|
||||
get pagination(): BehaviorSubject<PaginationModel> {
|
||||
if (!this._pagination) {
|
||||
let defaultPagination = <PaginationModel> {
|
||||
maxItems: 10,
|
||||
skipCount: 0,
|
||||
totalItems: 0,
|
||||
hasMoreItems: false
|
||||
};
|
||||
this._pagination = new BehaviorSubject<PaginationModel>(defaultPagination);
|
||||
}
|
||||
return this._pagination;
|
||||
}
|
||||
|
||||
updatePagination(pagination: PaginationModel) {
|
||||
this.pagination.next(pagination);
|
||||
}
|
||||
}
|
||||
|
||||
describe('InfinitePaginationComponent', () => {
|
||||
|
||||
@@ -31,13 +58,17 @@ describe('InfinitePaginationComponent', () => {
|
||||
let pagination: Pagination;
|
||||
|
||||
setupTestBed({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [
|
||||
TestPaginatedComponent
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(InfinitePaginationComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
component.target = TestBed.createComponent(TestPaginatedComponent).componentInstance;
|
||||
pagination = {
|
||||
skipCount: 0,
|
||||
hasMoreItems: false
|
||||
@@ -48,12 +79,12 @@ describe('InfinitePaginationComponent', () => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
describe('Standalone', () => {
|
||||
describe('View', () => {
|
||||
|
||||
it('should show the loading spinner if loading', () => {
|
||||
pagination.hasMoreItems = true;
|
||||
component.pagination = pagination;
|
||||
component.isLoading = true;
|
||||
component.target = null;
|
||||
fixture.detectChanges();
|
||||
|
||||
let loadingSpinner = fixture.debugElement.query(By.css('[data-automation-id="adf-infinite-pagination-spinner"]'));
|
||||
@@ -62,7 +93,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
|
||||
it('should NOT show the loading spinner if NOT loading', () => {
|
||||
pagination.hasMoreItems = true;
|
||||
component.pagination = pagination;
|
||||
component.target.updatePagination(pagination);
|
||||
component.isLoading = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -72,7 +103,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
|
||||
it('should show the load more button if NOT loading and has more items', () => {
|
||||
pagination.hasMoreItems = true;
|
||||
component.pagination = pagination;
|
||||
component.target.updatePagination(pagination);
|
||||
component.isLoading = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -82,7 +113,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
|
||||
it('should NOT show anything if pagination has NO more items', () => {
|
||||
pagination.hasMoreItems = false;
|
||||
component.pagination = pagination;
|
||||
component.target.updatePagination(pagination);
|
||||
fixture.detectChanges();
|
||||
|
||||
let loadMoreButton = fixture.debugElement.query(By.css('[data-automation-id="adf-infinite-pagination-button"]'));
|
||||
@@ -94,7 +125,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
it('should trigger the loadMore event with the proper pagination object', (done) => {
|
||||
pagination.hasMoreItems = true;
|
||||
pagination.skipCount = 5;
|
||||
component.pagination = pagination;
|
||||
component.target.updatePagination(pagination);
|
||||
component.isLoading = false;
|
||||
component.pageSize = 5;
|
||||
fixture.detectChanges();
|
||||
@@ -111,22 +142,16 @@ describe('InfinitePaginationComponent', () => {
|
||||
|
||||
describe('Target', () => {
|
||||
|
||||
let testTarget: PaginatedComponent;
|
||||
let spyTarget;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
pagination = { maxItems: 444, skipCount: 0, totalItems: 888, hasMoreItems: true };
|
||||
testTarget = {
|
||||
pagination: new BehaviorSubject<Pagination>(pagination),
|
||||
supportedPageSizes: [],
|
||||
updatePagination() {}
|
||||
};
|
||||
|
||||
spyOn(testTarget, 'updatePagination');
|
||||
spyTarget = spyOn(component.target, 'updatePagination').and.callThrough();
|
||||
});
|
||||
|
||||
it('should subscribe to target\'s pagination observable to update pagination and pagesize correctly', () => {
|
||||
component.target = testTarget;
|
||||
component.target.updatePagination(pagination);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.pagination).toBe(pagination);
|
||||
@@ -134,32 +159,44 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should call the target\'s updatePagination on invoking the onLoadMore', () => {
|
||||
component.target = testTarget;
|
||||
component.target.updatePagination(pagination);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onLoadMore();
|
||||
|
||||
expect(testTarget.updatePagination).toHaveBeenCalledWith({ maxItems: 444 + 25, skipCount: 0, totalItems: 888, hasMoreItems: true, merge: true });
|
||||
expect(spyTarget).toHaveBeenCalledWith({
|
||||
maxItems: 444 + 25,
|
||||
skipCount: 0,
|
||||
totalItems: 888,
|
||||
hasMoreItems: true,
|
||||
merge: true
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the target\'s updatePagination on invoking the onLoadMore with a specific pageSize', () => {
|
||||
component.target = testTarget;
|
||||
component.pageSize = 7;
|
||||
component.target.updatePagination(pagination);
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onLoadMore();
|
||||
|
||||
expect(testTarget.updatePagination).toHaveBeenCalledWith({ maxItems: 444 + component.pageSize, skipCount: 0, totalItems: 888, hasMoreItems: true, merge: true });
|
||||
expect(spyTarget).toHaveBeenCalledWith({
|
||||
maxItems: 444 + component.pageSize,
|
||||
skipCount: 0,
|
||||
totalItems: 888,
|
||||
hasMoreItems: true,
|
||||
merge: true
|
||||
});
|
||||
});
|
||||
|
||||
it('should unsubscribe from the target\'s pagination on onDestroy', () => {
|
||||
component.target = testTarget;
|
||||
fixture.detectChanges();
|
||||
fixture.destroy();
|
||||
|
||||
const emitNewPaginationEvent = () => {
|
||||
let newPagination = { maxItems: 1, skipCount: 0, totalItems: 2, hasMoreItems: true };
|
||||
testTarget.pagination.next(newPagination);
|
||||
component.target.pagination.next(newPagination);
|
||||
};
|
||||
|
||||
expect(emitNewPaginationEvent).not.toThrow();
|
||||
|
@@ -39,24 +39,12 @@ import { UserPreferencesService } from '../services/user-preferences.service';
|
||||
})
|
||||
export class InfinitePaginationComponent implements OnInit, OnDestroy, PaginationComponentInterface {
|
||||
|
||||
/**
|
||||
* @deprecated 3.0.0 - uses paginationSize's default in UserPreferencesService
|
||||
*/
|
||||
static DEFAULT_PAGE_SIZE: number = 25;
|
||||
|
||||
static DEFAULT_PAGINATION: PaginationModel = {
|
||||
skipCount: 0,
|
||||
hasMoreItems: false,
|
||||
merge: true
|
||||
};
|
||||
|
||||
/**
|
||||
* Pagination object.
|
||||
* @deprecated 2.3.0
|
||||
*/
|
||||
@Input()
|
||||
pagination: PaginationModel;
|
||||
|
||||
/** Component that provides custom pagination support. */
|
||||
@Input()
|
||||
target: PaginatedComponent;
|
||||
@@ -73,6 +61,8 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
|
||||
@Output()
|
||||
loadMore: EventEmitter<PaginationModel> = new EventEmitter<PaginationModel>();
|
||||
|
||||
pagination: PaginationModel;
|
||||
|
||||
private paginationSubscription: Subscription;
|
||||
|
||||
constructor(private cdr: ChangeDetectorRef, private userPreferencesService: UserPreferencesService) {
|
||||
|
@@ -20,10 +20,5 @@ import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
export interface PaginatedComponent {
|
||||
pagination: BehaviorSubject<PaginationModel>;
|
||||
/**
|
||||
* @deprecated 2.3.0 : the supported page size should be retrieved via the user preferences
|
||||
* and given to the pagination component, and not retrieved by the paginated object
|
||||
*/
|
||||
supportedPageSizes?: number[];
|
||||
updatePagination(pagination: PaginationModel);
|
||||
}
|
||||
|
Reference in New Issue
Block a user