// import { SpectatorDirective, createDirectiveFactory } from '@ngneat/spectator';
// import { IfRoleDirective } from './if-role.directive';
// import { AuthService } from './auth.service';
// import { TemplateRef, ViewContainerRef } from '@angular/core';

// describe('IfRoleDirective', () => {
//   let spectator: SpectatorDirective<IfRoleDirective>;
//   const createDirective = createDirectiveFactory({
//     directive: IfRoleDirective,
//     mocks: [AuthService],
//   });

//   it('should create an instance', () => {
//     spectator = createDirective(`<div *ifRole="'admin'"></div>`);
//     expect(spectator.directive).toBeTruthy();
//   });

//   it('should render template when user has the role', () => {
//     spectator = createDirective(`<div *ifRole="'admin'"></div>`);
//     const authService = spectator.inject(AuthService);
//     const viewContainerRef = spectator.inject(ViewContainerRef);
//     const templateRef = spectator.inject(TemplateRef);
//     authService.hasRole.and.returnValue(true);
//     spectator.directive.ngOnChanges();
//     expect(viewContainerRef.createEmbeddedView).toHaveBeenCalledWith(templateRef, spectator.directive.getContext());
//   });

//   it('should render else template when user does not have the role', () => {
//     authService.hasRole.and.returnValue(false);
//     const elseTemplateRef = {} as TemplateRef<any>;
//     spectator = createDirective(`<ng-template #elseTemplateRef></ng-template><div *ifRole="'admin'; else elseTemplateRef"></div>`, {
//       hostProps: {
//         elseTemplateRef,
//       },
//     });
//     spectator.directive.ngOnChanges();
//     expect(viewContainerRef.createEmbeddedView).toHaveBeenCalledWith(elseTemplateRef, spectator.directive.getContext());
//   });

//   it('should render else template when user does not have the role using ifNotRole input', () => {
//     authService.hasRole.and.returnValue(false);
//     const elseTemplateRef = {} as TemplateRef<any>;
//     spectator = createDirective(`<ng-template #elseTemplateRef></ng-template><div *ifNotRole="'admin'; else elseTemplateRef"></div>`, {
//       hostProps: {
//         elseTemplateRef,
//       },
//     });
//     spectator.directive.ngOnChanges();
//     expect(viewContainerRef.createEmbeddedView).toHaveBeenCalledWith(elseTemplateRef, spectator.directive.getContext());
//   });

//   it('should clear view when user does not have the role and elseTemplateRef is not defined', () => {
//     authService.hasRole.and.returnValue(false);
//     spectator = createDirective(`<div *ifRole="'admin'"></div>`);
//     spectator.directive.ngOnChanges();
//     expect(viewContainerRef.clear).toHaveBeenCalled();
//   });

//   it('should set $implicit to ifRole or ifNotRole input', () => {
//     spectator = createDirective(`<div *ifRole="'admin'"></div>`);
//     expect(spectator.directive.getContext().$implicit).toEqual('admin');
//     spectator.setInput('ifNotRole', 'user');
//     expect(spectator.directive.getContext().$implicit).toEqual('user');
//   });
// });
