[ACA-3762] Task/Process filters not working with updatePagination (#5936)

* [ACA-3762] Task/Process filters not working with updatePagination

* Fixed in task list
* Added unit tests
* Refactored resetPagination
This commit is contained in:
Mercy Chrysolite
2020-08-05 19:36:38 +05:30
committed by GitHub
parent 5bd012deef
commit 486a1d2c9d
4 changed files with 140 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import { ProcessListCloudService } from '../services/process-list-cloud.service'
import { ProcessListCloudComponent } from './process-list-cloud.component';
import { fakeCustomSchema, fakeProcessCloudList, processListSchemaMock } from '../mock/process-list-service.mock';
import { of } from 'rxjs';
import { skip } from 'rxjs/operators';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { ProcessListCloudSortingModel } from '../models/process-list-sorting.model';
@@ -291,6 +292,58 @@ describe('ProcessListCloudComponent', () => {
expect(component.isListEmpty()).toBeFalsy();
expect(getProcessByRequestSpy).toHaveBeenCalled();
});
it('should reset pagination when resetPaginationValues is called', async (done) => {
spyOn(processListCloudService, 'getProcessByRequest').and.returnValue(of(fakeProcessCloudList));
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
component.ngOnChanges({ appName });
fixture.detectChanges();
const size = component.size;
const skipCount = component.skipCount;
component.pagination.pipe(skip(3))
.subscribe((updatedPagination) => {
fixture.detectChanges();
expect(component.size).toBe(size);
expect(component.skipCount).toBe(skipCount);
expect(updatedPagination.maxItems).toEqual(size);
expect(updatedPagination.skipCount).toEqual(skipCount);
done();
});
const pagination = {
maxItems: 250,
skipCount: 200
};
component.updatePagination(pagination);
await fixture.whenStable();
component.resetPagination();
});
it('should set pagination and reload when updatePagination is called', (done) => {
spyOn(processListCloudService, 'getProcessByRequest').and.returnValue(of(fakeProcessCloudList));
spyOn(component, 'reload').and.stub();
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
component.ngOnChanges({ appName });
fixture.detectChanges();
const pagination = {
maxItems: 250,
skipCount: 200
};
component.pagination.pipe(skip(1))
.subscribe((updatedPagination) => {
fixture.detectChanges();
expect(component.size).toBe(pagination.maxItems);
expect(component.skipCount).toBe(pagination.skipCount);
expect(updatedPagination.maxItems).toEqual(pagination.maxItems);
expect(updatedPagination.skipCount).toEqual(pagination.skipCount);
done();
});
component.updatePagination(pagination);
});
});
describe('Injecting custom colums for tasklist - CustomTaskListComponent', () => {

View File

@@ -237,6 +237,23 @@ export class ProcessListCloudComponent extends DataTableSchema implements OnChan
return !this.rows || this.rows.length === 0;
}
/**
* Resets the pagination values
*/
resetPagination() {
this.skipCount = 0;
this.size = this.userPreferences.paginationSize;
this.pagination.next({
skipCount: 0,
maxItems: this.size
});
}
/**
* Resets the pagination values and
* Reloads the process list
* @param pagination Pagination values to be set
*/
updatePagination(pagination: PaginationModel) {
this.size = pagination.maxItems;
this.skipCount = pagination.skipCount;

View File

@@ -27,6 +27,7 @@ import { ProcessServiceCloudTestingModule } from '../../../testing/process-servi
import { Person } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
import { skip } from 'rxjs/operators';
@Component({
template: `
@@ -329,6 +330,58 @@ describe('TaskListCloudComponent', () => {
expect(component.isListEmpty()).toBeFalsy();
expect(getTaskByRequestSpy).toHaveBeenCalled();
});
it('should reset pagination when resetPaginationValues is called', async (done) => {
spyOn(taskListCloudService, 'getTaskByRequest').and.returnValue(of(fakeGlobalTask));
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
component.ngOnChanges({ appName });
fixture.detectChanges();
const size = component.size;
const skipCount = component.skipCount;
component.pagination.pipe(skip(3))
.subscribe((updatedPagination) => {
fixture.detectChanges();
expect(component.size).toBe(size);
expect(component.skipCount).toBe(skipCount);
expect(updatedPagination.maxItems).toEqual(size);
expect(updatedPagination.skipCount).toEqual(skipCount);
done();
});
const pagination = {
maxItems: 250,
skipCount: 200
};
component.updatePagination(pagination);
await fixture.whenStable();
component.resetPagination();
});
it('should set pagination and reload when updatePagination is called', (done) => {
spyOn(taskListCloudService, 'getTaskByRequest').and.returnValue(of(fakeGlobalTask));
spyOn(component, 'reload').and.stub();
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
component.ngOnChanges({ appName });
fixture.detectChanges();
const pagination = {
maxItems: 250,
skipCount: 200
};
component.pagination.pipe(skip(1))
.subscribe((updatedPagination) => {
fixture.detectChanges();
expect(component.size).toBe(pagination.maxItems);
expect(component.skipCount).toBe(pagination.skipCount);
expect(updatedPagination.maxItems).toEqual(pagination.maxItems);
expect(updatedPagination.skipCount).toEqual(pagination.skipCount);
done();
});
component.updatePagination(pagination);
});
});
describe('Injecting custom colums for tasklist - CustomTaskListComponent', () => {

View File

@@ -265,6 +265,23 @@ export class TaskListCloudComponent extends DataTableSchema implements OnChanges
return !this.rows || this.rows.length === 0;
}
/**
* Resets the pagination values
*/
resetPagination() {
this.skipCount = 0;
this.size = this.userPreferences.paginationSize;
this.pagination.next({
skipCount: 0,
maxItems: this.size
});
}
/**
* Resets the pagination values and
* Reloads the task list
* @param pagination Pagination values to be set
*/
updatePagination(pagination: PaginationModel) {
this.size = pagination.maxItems;
this.skipCount = pagination.skipCount;