From 2e3871da19d9733f49129bdc94ff4c033f4e1fef Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Sat, 7 Dec 2024 10:50:51 +0100 Subject: [PATCH] OZG-6477 7306 listResource bug, missing debounce --- .../src/lib/resource/list-resource.service.spec.ts | 12 ++++++------ .../src/lib/resource/list-resource.service.ts | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.spec.ts b/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.spec.ts index 5238a23c74..fd9d99e060 100644 --- a/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.spec.ts +++ b/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.spec.ts @@ -85,23 +85,23 @@ describe('ListResourceService', () => { isInvalidResourceCombinationSpy = jest.spyOn(ResourceUtil, 'isInvalidResourceCombination').mockReturnValue(true); }); - it('should handle config resource changed', fakeAsync(() => { + it('should handle config resource changed after debounce time', fakeAsync(() => { service.getList().subscribe(); - tick(); + tick(300); expect(service.handleChanges).toHaveBeenCalledWith(listStateResource, baseResource); })); - it('should handle null configresource', fakeAsync(() => { + it('should handle null configresource after debounce time', fakeAsync(() => { service.getList().subscribe(); - tick(); + tick(300); expect(service.handleNullConfigResource).toHaveBeenCalledWith(baseResource); })); - it('should call isInvalidResourceCombinationSpy', fakeAsync(() => { + it('should call isInvalidResourceCombinationSpy after debounce time', fakeAsync(() => { service.getList().subscribe(); - tick(); + tick(300); expect(isInvalidResourceCombinationSpy).toHaveBeenCalled(); })); diff --git a/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.ts b/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.ts index 8dba0ba679..52668215e4 100644 --- a/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.ts +++ b/alfa-client/libs/tech-shared/src/lib/resource/list-resource.service.ts @@ -23,7 +23,7 @@ */ import { Resource, ResourceUri, getUrl, hasLink } from '@ngxp/rest'; import { isEqual, isNil, isNull } from 'lodash-es'; -import { BehaviorSubject, Observable, combineLatest, filter, first, map, startWith, tap } from 'rxjs'; +import { BehaviorSubject, Observable, combineLatest, debounce, filter, first, interval, map, startWith, tap } from 'rxjs'; import { isNotNull, isNotUndefined } from '../tech.util'; import { CreateResourceData, ListItemResource, ListResourceServiceConfig } from './resource.model'; import { ResourceRepository } from './resource.repository'; @@ -64,6 +64,7 @@ export class ResourceListService<B extends Resource, T extends ListResource, I e public getList(): Observable<StateResource<T>> { return combineLatest([this.listResource.asObservable(), this.getConfigResource()]).pipe( + debounce(() => interval(300)), tap(([stateResource, configResource]) => { this.handleChanges(stateResource, configResource); }), -- GitLab