mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
This reverts commit 946fe889e1
.
This commit is contained in:
@@ -16,8 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, fakeAsync, flush, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { first, of, throwError } from 'rxjs';
|
import { of, throwError } from 'rxjs';
|
||||||
import { ProcessFilterCloudService } from '../../services/process-filter-cloud.service';
|
import { ProcessFilterCloudService } from '../../services/process-filter-cloud.service';
|
||||||
import { ProcessFiltersCloudComponent } from './process-filters-cloud.component';
|
import { ProcessFiltersCloudComponent } from './process-filters-cloud.component';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
@@ -578,60 +578,67 @@ describe('ProcessFiltersCloudComponent', () => {
|
|||||||
expect(getProcessNotificationSubscriptionSpy).toHaveBeenCalled();
|
expect(getProcessNotificationSubscriptionSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit filter key when filter counter is set for first time', () => {
|
it('should not emit filter key when filter counter is set for first time', () => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
expect(updatedFilterSpy).toHaveBeenCalled();
|
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('should not emit filter key when filter counter has not changed', fakeAsync(() => {
|
|
||||||
|
it('should not emit filter key when filter counter has not changd', () => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
|
|
||||||
component.updatedFilter.pipe(first()).subscribe(() => {
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fail('Should not have been called if the filterKey value is already there');
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
|
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
it('should emit filter key when filter counter is increased', () => {
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
|
||||||
flush();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should emit filter key when filter counter is increased', (done) => {
|
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
fixture.detectChanges();
|
||||||
expect(updatedFilter).toBe(fakeFilterKey);
|
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey);
|
||||||
done();
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(10);
|
||||||
});
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(updatedFilterSpy).toHaveBeenCalledWith(fakeFilterKey);
|
||||||
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
||||||
});
|
});
|
||||||
it('should emit filter key when filter counter is decreased', (done) => {
|
|
||||||
|
it('should emit filter key when filter counter is decreased', () => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
fixture.detectChanges();
|
||||||
expect(updatedFilter).toBe(fakeFilterKey);
|
|
||||||
done();
|
expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey);
|
||||||
});
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(10);
|
||||||
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(updatedFilterSpy).toHaveBeenCalledWith(fakeFilterKey);
|
||||||
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -293,7 +293,11 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number): void {
|
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number): void {
|
||||||
if (this.currentFiltersValues[filterKey] === undefined || this.currentFiltersValues[filterKey] !== filterValue) {
|
if (!this.currentFiltersValues[filterKey]) {
|
||||||
|
this.currentFiltersValues[filterKey] = filterValue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.currentFiltersValues[filterKey] !== filterValue) {
|
||||||
this.currentFiltersValues[filterKey] = filterValue;
|
this.currentFiltersValues[filterKey] = filterValue;
|
||||||
this.updatedFilter.emit(filterKey);
|
this.updatedFilter.emit(filterKey);
|
||||||
this.updatedFiltersSet.add(filterKey);
|
this.updatedFiltersSet.add(filterKey);
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { AppConfigService } from '@alfresco/adf-core';
|
import { AppConfigService } from '@alfresco/adf-core';
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, fakeAsync, flush } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { first, of, throwError } from 'rxjs';
|
import { first, of, throwError } from 'rxjs';
|
||||||
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../../services/cloud-token.service';
|
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../../services/cloud-token.service';
|
||||||
@@ -468,42 +468,40 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
expect(component.getFilters).toHaveBeenCalledWith(appName);
|
expect(component.getFilters).toHaveBeenCalledWith(appName);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit filter key when filter counter is set for first time', () => {
|
it('should not emit filter key when filter counter is set for first time', () => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
expect(updatedFilterSpy).toHaveBeenCalled();
|
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('should not emit filter key when filter counter has not changed', fakeAsync(() => {
|
|
||||||
|
it('should not emit filter key when filter counter has not changd', () => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
|
|
||||||
component.updatedFilter.pipe(first()).subscribe(() => {
|
|
||||||
fail('Should not have been called if the filterKey value is already there');
|
|
||||||
});
|
|
||||||
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
flush();
|
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should emit filter key when filter counter is increased', (done) => {
|
it('should emit filter key when filter counter is increased', (done) => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
|
|
||||||
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
||||||
expect(updatedFilter).toBe(fakeFilterKey);
|
expect(updatedFilter).toBe(fakeFilterKey);
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
||||||
@@ -512,14 +510,17 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit filter key when filter counter is decreased', (done) => {
|
it('should emit filter key when filter counter is decreased', (done) => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
|
|
||||||
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
||||||
expect(updatedFilter).toBe(fakeFilterKey);
|
expect(updatedFilter).toBe(fakeFilterKey);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
@@ -261,7 +261,11 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number) {
|
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number) {
|
||||||
if (this.currentFiltersValues[filterKey] == undefined || this.currentFiltersValues[filterKey] !== filterValue) {
|
if (!this.currentFiltersValues[filterKey]) {
|
||||||
|
this.currentFiltersValues[filterKey] = filterValue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.currentFiltersValues[filterKey] !== filterValue) {
|
||||||
this.currentFiltersValues[filterKey] = filterValue;
|
this.currentFiltersValues[filterKey] = filterValue;
|
||||||
this.updatedFilter.emit(filterKey);
|
this.updatedFilter.emit(filterKey);
|
||||||
this.updatedCountersSet.add(filterKey);
|
this.updatedCountersSet.add(filterKey);
|
||||||
|
Reference in New Issue
Block a user