From 9246ea486636a8a37afe14d2dfe7f1405d2fcb05 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Wed, 4 Dec 2024 17:36:15 +0100
Subject: [PATCH] OZG-6700 feature toggle in pages

---
 ...sationseinheit-form-page.component.spec.ts |  9 ++---
 .../organisationseinheit-page.component.html  |  6 +++-
 ...rganisationseinheit-page.component.spec.ts | 34 +++++++++++++++++++
 .../organisationseinheit-page.component.ts    | 16 +++++++--
 .../postfach-page.component.html              |  4 ++-
 .../postfach-page.component.spec.ts           | 26 +++++++++++++-
 .../postfach-page/postfach-page.component.ts  |  5 ++-
 .../user-add-page.component.spec.ts           | 20 ++++++-----
 .../user-roles-page.component.spec.ts         | 20 ++++++-----
 9 files changed, 112 insertions(+), 28 deletions(-)

diff --git a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.spec.ts b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.spec.ts
index e27ea055d1..eb70d91232 100644
--- a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.spec.ts
+++ b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.spec.ts
@@ -13,7 +13,7 @@ describe('OrganisationsEinheitFormPageComponent', () => {
   let component: OrganisationsEinheitFormPageComponent;
   let fixture: ComponentFixture<OrganisationsEinheitFormPageComponent>;
 
-  const organisationsEinheiteFormSelector: string = getDataTestIdOf('organisations-einheit-form');
+  const organisationsEinheitFormSelector: string = getDataTestIdOf('organisations-einheit-form');
 
   const apiRootStateResource$ = of(createStateResource(createApiRootResource()));
   const apiRootService: Mock<ApiRootService> = {
@@ -51,18 +51,19 @@ describe('OrganisationsEinheitFormPageComponent', () => {
   });
 
   describe('template', () => {
-    // todo: fix me
     describe('admin-organisationseinheit-form-container', () => {
       it('should be rendered if apiRootState has link', () => {
         component.apiRootStateResource$ = of(createStateResource(createApiRootResource([ApiRootLinkRel.ORGANISATIONS_EINHEIT])));
+        fixture.detectChanges();
 
-        existsAsHtmlElement(fixture, organisationsEinheiteFormSelector);
+        existsAsHtmlElement(fixture, organisationsEinheitFormSelector);
       });
 
       it('should not be rendered if apiRootState has no link', () => {
         component.apiRootStateResource$ = of(createStateResource(createApiRootResource()));
+        fixture.detectChanges();
 
-        notExistsAsHtmlElement(fixture, organisationsEinheiteFormSelector);
+        notExistsAsHtmlElement(fixture, organisationsEinheitFormSelector);
       });
     });
   });
diff --git a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.html b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.html
index 7929301587..d57d0eb794 100644
--- a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.html
+++ b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.html
@@ -1 +1,5 @@
-<admin-organisationseinheit-container/>
+<ng-container *ngIf="(apiRootStateResource$ | async)?.resource as apiRoot">
+  @if(apiRoot | hasLink: ApiRootLinkRel.ORGANISATIONS_EINHEIT){
+    <admin-organisationseinheit-container data-test-id="organisations-einheit-container"/>
+  }
+</ng-container>
\ No newline at end of file
diff --git a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.spec.ts b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.spec.ts
index 59ddda81ab..17a5736eae 100644
--- a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.spec.ts
+++ b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.spec.ts
@@ -1,15 +1,31 @@
 import { OrganisationsEinheitContainerComponent } from '@admin-client/admin-settings';
+import { ApiRootLinkRel, ApiRootService } from '@alfa-client/api-root-shared';
+import { createStateResource, TechSharedModule } from '@alfa-client/tech-shared';
+import { existsAsHtmlElement, mock, Mock, notExistsAsHtmlElement } from '@alfa-client/test-utils';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { MockComponent } from 'ng-mocks';
+import { of } from 'rxjs';
+import { createApiRootResource } from '../../../../../../libs/api-root-shared/test/api-root';
+import { getDataTestIdOf } from '../../../../../../libs/tech-shared/test/data-test';
 import { OrganisationsEinheitPageComponent } from './organisationseinheit-page.component';
 
 describe('OrganisationsEinheitPageComponent', () => {
   let component: OrganisationsEinheitPageComponent;
   let fixture: ComponentFixture<OrganisationsEinheitPageComponent>;
 
+  const organisationsEinheitContainerSelector: string = getDataTestIdOf('organisations-einheit-container');
+
+  const apiRootStateResource$ = of(createStateResource(createApiRootResource()));
+  const apiRootService: Mock<ApiRootService> = {
+    ...mock(ApiRootService),
+    getApiRoot: jest.fn().mockReturnValue(apiRootStateResource$),
+  };
+
   beforeEach(async () => {
     await TestBed.configureTestingModule({
+      imports: [TechSharedModule],
       declarations: [OrganisationsEinheitPageComponent, MockComponent(OrganisationsEinheitContainerComponent)],
+      providers: [{ provide: ApiRootService, useValue: apiRootService }],
     }).compileComponents();
   });
 
@@ -23,4 +39,22 @@ describe('OrganisationsEinheitPageComponent', () => {
   it('should create', () => {
     expect(component).toBeTruthy();
   });
+
+  describe('template', () => {
+    describe('admin-organisationseinheit-container', () => {
+      it('should be rendered if apiRootState has link', () => {
+        component.apiRootStateResource$ = of(createStateResource(createApiRootResource([ApiRootLinkRel.ORGANISATIONS_EINHEIT])));
+        fixture.detectChanges();
+
+        existsAsHtmlElement(fixture, organisationsEinheitContainerSelector);
+      });
+
+      it('should not be rendered if apiRootState has no link', () => {
+        component.apiRootStateResource$ = of(createStateResource(createApiRootResource()));
+        fixture.detectChanges();
+
+        notExistsAsHtmlElement(fixture, organisationsEinheitContainerSelector);
+      });
+    });
+  });
 });
diff --git a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.ts b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.ts
index 4d653b6ed7..08fdbd714d 100644
--- a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.ts
+++ b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component.ts
@@ -1,7 +1,19 @@
-import { Component } from '@angular/core';
+import { ApiRootLinkRel, ApiRootResource, ApiRootService } from '@alfa-client/api-root-shared';
+import { createEmptyStateResource, StateResource } from '@alfa-client/tech-shared';
+import { Component, inject } from '@angular/core';
+import { Observable, of } from 'rxjs';
 
 @Component({
   selector: 'organisationseinheit-page',
   templateUrl: './organisationseinheit-page.component.html',
 })
-export class OrganisationsEinheitPageComponent {}
+export class OrganisationsEinheitPageComponent {
+  private apiRootService = inject(ApiRootService);
+
+  public apiRootStateResource$: Observable<StateResource<ApiRootResource>> = of(createEmptyStateResource<ApiRootResource>());
+
+  ngOnInit(): void {
+    this.apiRootStateResource$ = this.apiRootService.getApiRoot();
+  }
+  protected readonly ApiRootLinkRel = ApiRootLinkRel;
+}
diff --git a/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.html b/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.html
index 35312d3a6f..6d30a459ec 100644
--- a/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.html
+++ b/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.html
@@ -1 +1,3 @@
-<admin-postfach-container></admin-postfach-container>
+@if(environment.features.postfach){
+  <admin-postfach-container data-test-id="postfach-container"/>
+}
\ No newline at end of file
diff --git a/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.spec.ts b/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.spec.ts
index 5ebec9f21a..49c04dc617 100644
--- a/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.spec.ts
+++ b/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.spec.ts
@@ -1,12 +1,18 @@
 import { PostfachContainerComponent } from '@admin-client/admin-settings';
+import { existsAsHtmlElement, notExistsAsHtmlElement } from '@alfa-client/test-utils';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { MockComponent } from 'ng-mocks';
+import { createEnvironment } from '../../../../../../libs/environment-shared/test/environment';
+import { getDataTestIdOf } from '../../../../../../libs/tech-shared/test/data-test';
 import { PostfachPageComponent } from './postfach-page.component';
 
 describe('PostfachPageComponent', () => {
   let component: PostfachPageComponent;
   let fixture: ComponentFixture<PostfachPageComponent>;
 
+  const postfachContainerSelector: string = getDataTestIdOf('postfach-container');
+  const environment = createEnvironment();
+
   beforeEach(async () => {
     await TestBed.configureTestingModule({
       declarations: [PostfachPageComponent, MockComponent(PostfachContainerComponent)],
@@ -16,11 +22,29 @@ describe('PostfachPageComponent', () => {
   beforeEach(() => {
     fixture = TestBed.createComponent(PostfachPageComponent);
     component = fixture.componentInstance;
-
+    component.environment = environment;
     fixture.detectChanges();
   });
 
   it('should create', () => {
     expect(component).toBeTruthy();
   });
+
+  describe('template', () => {
+    describe('admin-postfach-container', () => {
+      it('should be rendered if feature toggle postfach is true', () => {
+        environment.features.postfach = true;
+        fixture.detectChanges();
+
+        existsAsHtmlElement(fixture, postfachContainerSelector);
+      });
+
+      it('should not be rendered if feature toggle postfach is false', () => {
+        environment.features.postfach = false;
+        fixture.detectChanges();
+
+        notExistsAsHtmlElement(fixture, postfachContainerSelector);
+      });
+    });
+  });
 });
diff --git a/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.ts b/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.ts
index 1d9a54cedd..e517dd361f 100644
--- a/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.ts
+++ b/alfa-client/apps/admin/src/pages/postfach/postfach-page/postfach-page.component.ts
@@ -1,7 +1,10 @@
+import { Environment, getEnvironmentFactory } from '@alfa-client/environment-shared';
 import { Component } from '@angular/core';
 
 @Component({
   selector: 'postfach-page',
   templateUrl: './postfach-page.component.html',
 })
-export class PostfachPageComponent {}
+export class PostfachPageComponent {
+  public environment: Environment = getEnvironmentFactory();
+}
diff --git a/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.spec.ts b/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.spec.ts
index 49c6e7a84d..4a3016f2eb 100644
--- a/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.spec.ts
+++ b/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.spec.ts
@@ -29,18 +29,20 @@ describe('UserAddPageComponent', () => {
   });
 
   describe('template', () => {
-    it('should render the users roles component if feature toggle is true', () => {
-      environment.features.benutzerRollen = true;
-      fixture.detectChanges();
+    describe('admin-user-add-form', () => {
+      it('should be rendered if feature toggle for benutzerRollen is true', () => {
+        environment.features.benutzerRollen = true;
+        fixture.detectChanges();
 
-      existsAsHtmlElement(fixture, userAddFormSelector);
-    });
+        existsAsHtmlElement(fixture, userAddFormSelector);
+      });
 
-    it('should not render the users roles component if feature toggle is false', () => {
-      environment.features.benutzerRollen = false;
-      fixture.detectChanges();
+      it('should not be rendered if feature toggle for benutzerRollen is false', () => {
+        environment.features.benutzerRollen = false;
+        fixture.detectChanges();
 
-      notExistsAsHtmlElement(fixture, userAddFormSelector);
+        notExistsAsHtmlElement(fixture, userAddFormSelector);
+      });
     });
   });
 });
diff --git a/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.spec.ts b/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.spec.ts
index a25520507f..0819e2bec0 100644
--- a/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.spec.ts
+++ b/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.spec.ts
@@ -30,18 +30,20 @@ describe('UserRolesPageComponent', () => {
   });
 
   describe('template', () => {
-    it('should render the users roles component if feature toggle is true', () => {
-      environment.features.benutzerRollen = true;
-      fixture.detectChanges();
+    describe('admin-users-roles', () => {
+      it('should be rendered if feature toggle benutzerRollen is true', () => {
+        environment.features.benutzerRollen = true;
+        fixture.detectChanges();
 
-      existsAsHtmlElement(fixture, usersRolesSelector);
-    });
+        existsAsHtmlElement(fixture, usersRolesSelector);
+      });
 
-    it('should not render the users roles component if feature toggle is false', () => {
-      environment.features.benutzerRollen = false;
-      fixture.detectChanges();
+      it('should not be rendered component if feature toggle benutzerRollen is false', () => {
+        environment.features.benutzerRollen = false;
+        fixture.detectChanges();
 
-      notExistsAsHtmlElement(fixture, usersRolesSelector);
+        notExistsAsHtmlElement(fixture, usersRolesSelector);
+      });
     });
   });
 });
-- 
GitLab