Skip to content

Commit 5d32f5b

Browse files
committed
angular: update snapshot
1 parent f3a626c commit 5d32f5b

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

generators/angular/__snapshots__/generator.spec.ts.snap

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,30 @@ describe('UserManagement Management Component', () => {
524524
await vitest.runAllTimersAsync();
525525
526526
// THEN
527-
expect(service.userManagementsResource.isLoading()).toEqual(false);
527+
expect(comp.isLoading()).toEqual(false);
528+
expect(comp.userManagements()[0]).toEqual(expect.objectContaining({login: 'Pattie.Kertzmann'}));
529+
});
530+
531+
532+
it('old requests should be cancelled', async () => {
533+
// WHEN
534+
TestBed.tick();
535+
const req = httpMock.expectOne({ method: 'GET' });
536+
await vitest.runAllTimersAsync();
537+
538+
comp.page.set(3);
539+
comp.load();
540+
await vitest.runAllTimersAsync();
541+
const req2 = httpMock.expectOne({ method: 'GET' });
542+
req2.flush(
543+
[{login: 'Pattie.Kertzmann'}],
544+
{ headers: { link: '<http://localhost/api/foo?page=1&size=20>; rel="next"' } },
545+
);
546+
await vitest.runAllTimersAsync();
547+
548+
// THEN
549+
expect(req.cancelled).toBeTruthy();
550+
expect(comp.isLoading()).toEqual(false);
528551
expect(comp.userManagements()[0]).toEqual(expect.objectContaining({login: 'Pattie.Kertzmann'}));
529552
});
530553
@@ -611,10 +634,11 @@ describe('UserManagement Management Component', () => {
611634
"stateCleared": "modified",
612635
},
613636
"src/main/webapp/app/entities/admin/user-management/list/user-management.ts": {
614-
"contents": "import { Component, computed, effect, inject, OnInit, signal, WritableSignal } from '@angular/core';
637+
"contents": "import { Component, computed, effect, inject, signal, WritableSignal, untracked } from '@angular/core';
638+
import { toSignal } from '@angular/core/rxjs-interop';
615639
import { HttpHeaders } from '@angular/common/http';
616640
import { ActivatedRoute, Data, ParamMap, Router, RouterLink } from '@angular/router';
617-
import { combineLatest, filter, finalize, Observable, Subscription, tap } from 'rxjs';
641+
import { combineLatest, filter, map, tap } from 'rxjs';
618642
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
619643
620644
import { AlertError } from 'app/shared/alert/alert-error';
@@ -656,9 +680,8 @@ import { UserManagementDeleteDialog } from '../delete/user-management-delete-dia
656680
ItemCount,
657681
],
658682
})
659-
export class UserManagement implements OnInit {
683+
export class UserManagement {
660684
661-
subscription: Subscription | null = null;
662685
readonly userManagements = signal<IUserManagement[]>([]);
663686
664687
sortState = sortStateSignal({});
@@ -672,6 +695,11 @@ export class UserManagement implements OnInit {
672695
// eslint-disable-next-line @typescript-eslint/member-ordering
673696
readonly isLoading = this.userManagementService.userManagementsResource.isLoading;
674697
protected readonly activatedRoute = inject(ActivatedRoute);
698+
protected readonly activatedRouteState = toSignal(
699+
combineLatest([this.activatedRoute.queryParamMap, this.activatedRoute.data]).pipe(
700+
map(([queryParamMap, data]) => ({ queryParamMap, data })),
701+
),
702+
);
675703
protected readonly sortService = inject(SortService);
676704
protected modalService = inject(NgbModal);
677705
@@ -685,18 +713,20 @@ export class UserManagement implements OnInit {
685713
effect(() => {
686714
this.userManagements.set(this.fillComponentAttributesFromResponseBody([...this.userManagementService.userManagements()]));
687715
});
716+
effect(() => {
717+
const activatedRouteState = this.activatedRouteState();
718+
if (activatedRouteState) {
719+
// Only watch for route changes. Other signals should be ignored.
720+
untracked(() => {
721+
this.fillComponentAttributeFromRoute(activatedRouteState.queryParamMap, activatedRouteState.data);
722+
this.load();
723+
});
724+
}
725+
});
688726
}
689727
690728
trackLogin = (item: IUserManagement): string => this.userManagementService.getUserManagementIdentifier(item);
691729
692-
ngOnInit(): void {
693-
this.subscription = combineLatest([this.activatedRoute.queryParamMap, this.activatedRoute.data]).pipe(
694-
tap(([params, data]) => this.fillComponentAttributeFromRoute(params, data)),
695-
tap(() => this.load()),
696-
).subscribe();
697-
698-
}
699-
700730
701731
delete(userManagement: IUserManagement): void {
702732
const modalRef = this.modalService.open(UserManagementDeleteDialog, { size: 'lg', backdrop: 'static' });

0 commit comments

Comments
 (0)