From 7868852719d00aa614a15d1644586b94e135625b Mon Sep 17 00:00:00 2001 From: Quentin Date: Tue, 28 May 2024 21:18:18 +0200 Subject: [PATCH] [Angular] Use viewChild signal for HasAnyAuthorityDirective directive --- .../auth/has-any-authority.directive.spec.ts.ejs | 16 ++++++++-------- .../auth/has-any-authority.directive.ts.ejs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.spec.ts.ejs b/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.spec.ts.ejs index 7f5a4737774..b0fa9271313 100644 --- a/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.spec.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.spec.ts.ejs @@ -18,9 +18,10 @@ -%> jest.mock('app/core/auth/account.service'); -import { Component, ElementRef, Signal, ViewChild, WritableSignal, signal } from '@angular/core'; +import { Component, ElementRef, WritableSignal, signal, viewChild } from '@angular/core'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { TestBed, waitForAsync } from '@angular/core/testing'; -import { Subject } from 'rxjs'; +import { TranslateModule } from '@ngx-translate/core'; import { AccountService } from 'app/core/auth/account.service'; import { Account } from 'app/core/auth/account.model'; @@ -31,8 +32,7 @@ import HasAnyAuthorityDirective from './has-any-authority.directive'; template: `
HasAnyAuthority="'ROLE_ADMIN'" #content>
`, }) class TestHasAnyAuthorityDirectiveComponent { - @ViewChild('content', { static: false }) - content?: ElementRef; + content = viewChild('content'); } describe('HasAnyAuthorityDirective tests', () => { @@ -41,7 +41,7 @@ describe('HasAnyAuthorityDirective tests', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - imports: [HasAnyAuthorityDirective], + imports: [HasAnyAuthorityDirective, HttpClientTestingModule, TranslateModule.forRoot()], declarations: [TestHasAnyAuthorityDirectiveComponent], providers: [AccountService], }); @@ -79,7 +79,7 @@ describe('HasAnyAuthorityDirective tests', () => { fixture.detectChanges(); // THEN - expect(comp.content).toBeUndefined(); + expect(comp.content()).toBeUndefined(); }); }); @@ -95,7 +95,7 @@ describe('HasAnyAuthorityDirective tests', () => { fixture.detectChanges(); // THEN - expect(comp.content).toBeDefined(); + expect(comp.content()).toBeDefined(); // GIVEN currentAccount.set(null); @@ -104,7 +104,7 @@ describe('HasAnyAuthorityDirective tests', () => { fixture.detectChanges(); // THEN - expect(comp.content).toBeUndefined(); + expect(comp.content()).toBeUndefined(); // WHEN currentAccount.set({ activated: true, authorities: ['foo'] } as any); diff --git a/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.ts.ejs b/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.ts.ejs index 68b54f1e48f..3b57985c6a9 100644 --- a/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/shared/auth/has-any-authority.directive.ts.ejs @@ -52,7 +52,7 @@ export default class HasAnyAuthorityDirective { } else { this.viewContainerRef.clear(); } - }); + }, { allowSignalWrites: true }); } @Input()