Skip to content
Snippets Groups Projects
Select Git revision
  • 41d0df88b0facb7b478ee49cf13fc836cd9b7fd0
  • main default protected
  • release
  • OZG-7856_schadcode_scanner
  • ci-pipeline
  • OZG-7526-signatur-nicht-uebernommen
  • OZG-6223-zip-download-bug
  • OZG-7367-tooltip-extension
  • OZG-7023-OZG-6956-E2E-externe-Stellen
  • OZG-6238-npm-durch-pnpm-ersetzen
  • release-admin
  • release-info
  • OZG-6700-admin-feature-toggle
  • E2E-Updates
  • OZG-7047-tooltips
  • OZG-6957-e2e-fachstellen-oe-daten
  • OZG-7006-ZuarbeitAnfragen
  • temp_OZG-7027
  • unit-tests-hotfix
  • OZG-6731-POC-keycloakResourceService-with-multiple-stateResources
  • e2e-add-zufi-version
  • 2.26.0
  • 2.25.0
  • 2.24.2
  • 2.24.1
  • 2.24.0
  • 2.23.0
  • 2.22.0
  • 2.21.0
  • 2.20.0
  • 2.21.0-SNAPSHOT
  • 2.19.0
  • 2.18.0
  • 2.17.1
  • 1.3.0
  • release-admin-1.3.0
  • release-info-1.3.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
  • release-admin-1.1.0
41 results

user-profile-button-container.component.spec.ts

Blame
  • user-profile-button-container.component.spec.ts 2.52 KiB
    import {
      dispatchEventFromFixture,
      getElementFromFixture,
      mock,
      Mock,
    } from '@alfa-client/test-utils';
    import { ComponentFixture, TestBed } from '@angular/core/testing';
    import { RouterTestingModule } from '@angular/router/testing';
    import { LogoutIconComponent, PopupComponent, PopupListItemComponent } from '@ods/system';
    import { AuthenticationService } from 'authentication';
    import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
    import { MockComponent } from 'ng-mocks';
    import { UserProfileButtonContainerComponent } from './user-profile.button-container.component';
    
    describe('UserProfileButtonContainerComponent', () => {
      let component: UserProfileButtonContainerComponent;
      let fixture: ComponentFixture<UserProfileButtonContainerComponent>;
    
      const authenticationService: Mock<AuthenticationService> = mock(AuthenticationService);
    
      const popupButtonContent: string = getDataTestIdOf('popup-button-content');
      const popupLogoutButton: string = getDataTestIdOf('popup-logout-button');
    
      beforeEach(async () => {
        await TestBed.configureTestingModule({
          declarations: [UserProfileButtonContainerComponent],
          imports: [
            RouterTestingModule,
            MockComponent(PopupComponent),
            MockComponent(PopupListItemComponent),
            MockComponent(LogoutIconComponent),
          ],
          providers: [
            {
              provide: AuthenticationService,
              useValue: authenticationService,
            },
          ],
        }).compileComponents();
      });
    
      beforeEach(() => {
        fixture = TestBed.createComponent(UserProfileButtonContainerComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
      });
    
      it('should create', () => {
        expect(component).toBeTruthy();
      });
    
      describe('ngOnInit', () => {
        it('should call authService to get current user initials', () => {
          component.ngOnInit();
    
          expect(authenticationService.getCurrentUserInitials).toHaveBeenCalled();
        });
      });
    
      describe('popup button', () => {
        it('should show initials', () => {
          component.currentUserInitials = 'AV';
          fixture.detectChanges();
    
          const popupButtonContentElement: HTMLElement = getElementFromFixture(
            fixture,
            popupButtonContent,
          );
    
          expect(popupButtonContentElement.textContent.trim()).toEqual('AV');