Skip to content

Commit

Permalink
[Angular] Use viewChild signal for HasAnyAuthorityDirective directive
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert committed May 28, 2024
1 parent 1671c93 commit 7868852
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,8 +32,7 @@ import HasAnyAuthorityDirective from './has-any-authority.directive';
template: ` <div *<%= jhiPrefix %>HasAnyAuthority="'ROLE_ADMIN'" #content></div> `,
})
class TestHasAnyAuthorityDirectiveComponent {
@ViewChild('content', { static: false })
content?: ElementRef;
content = viewChild<ElementRef>('content');
}

describe('HasAnyAuthorityDirective tests', () => {
Expand All @@ -41,7 +41,7 @@ describe('HasAnyAuthorityDirective tests', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [HasAnyAuthorityDirective],
imports: [HasAnyAuthorityDirective, HttpClientTestingModule, TranslateModule.forRoot()],
declarations: [TestHasAnyAuthorityDirectiveComponent],
providers: [AccountService],
});
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('HasAnyAuthorityDirective tests', () => {
fixture.detectChanges();

// THEN
expect(comp.content).toBeUndefined();
expect(comp.content()).toBeUndefined();
});
});

Expand All @@ -95,7 +95,7 @@ describe('HasAnyAuthorityDirective tests', () => {
fixture.detectChanges();

// THEN
expect(comp.content).toBeDefined();
expect(comp.content()).toBeDefined();

// GIVEN
currentAccount.set(null);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class HasAnyAuthorityDirective {
} else {
this.viewContainerRef.clear();
}
});
}, { allowSignalWrites: true });
}

@Input()
Expand Down

0 comments on commit 7868852

Please sign in to comment.