From f3f3c760e429036c5e447ce4de9e6271f8d2b943 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Wed, 4 Dec 2024 15:53:20 +0100 Subject: [PATCH] OZG-6700 feature toggle in pages --- .../apps/admin/src/app/app.component.html | 2 +- .../apps/admin/src/app/app.component.spec.ts | 6 +-- ...anisationseinheit-form-page.component.html | 6 ++- ...sationseinheit-form-page.component.spec.ts | 43 +++++++++++++++++++ ...rganisationseinheit-form-page.component.ts | 17 +++++++- .../user-add-page.component.html | 4 +- .../user-add-page.component.spec.ts | 23 ++++++++++ .../user-add-page/user-add-page.component.ts | 5 ++- .../user-roles-page.component.html | 4 +- .../user-roles-page.component.spec.ts | 23 ++++++++++ .../user-roles-page.component.ts | 5 ++- 11 files changed, 127 insertions(+), 11 deletions(-) diff --git a/alfa-client/apps/admin/src/app/app.component.html b/alfa-client/apps/admin/src/app/app.component.html index 9dd7a6ab0f..b8a2a57f09 100644 --- a/alfa-client/apps/admin/src/app/app.component.html +++ b/alfa-client/apps/admin/src/app/app.component.html @@ -17,7 +17,7 @@ <ods-navbar data-test-id="navigation"> <ng-container *ngIf="apiRoot | hasLink: ApiRootLinkRel.CONFIGURATION"> <ng-container *ngIf="environment.features.benutzerRollen"> - <ods-nav-item data-test-id="benutzer-und-rollen-navigation" caption="Benutzer & Rollen" path="/benutzer_und_rollen"> + <ods-nav-item data-test-id="users-roles-navigation" caption="Benutzer & Rollen" path="/benutzer_und_rollen"> <ods-users-icon class="stroke-text" icon /> </ods-nav-item> <hr /> diff --git a/alfa-client/apps/admin/src/app/app.component.spec.ts b/alfa-client/apps/admin/src/app/app.component.spec.ts index 15f471fb15..212128e52b 100644 --- a/alfa-client/apps/admin/src/app/app.component.spec.ts +++ b/alfa-client/apps/admin/src/app/app.component.spec.ts @@ -38,7 +38,7 @@ describe('AppComponent', () => { const buildInfoSelector: string = getDataTestIdOf('build-info'); const userProfileButtonSelector: string = getDataTestIdOf('user-profile-button'); const navigationSelector: string = getDataTestIdOf('navigation'); - const benutzerUndRollenNavigationSelector: string = getDataTestIdOf('benutzer-und-rollen-navigation'); + const usersRolesNavigationSelector: string = getDataTestIdOf('users-roles-navigation'); const postfachNavigationSelector: string = getDataTestIdOf('postfach-navigation'); const organisationsEinheitenNavigationSelector: string = getDataTestIdOf('organisations-einheiten-navigation'); const logoLink: string = getDataTestIdOf('logo-link'); @@ -234,14 +234,14 @@ describe('AppComponent', () => { component.environment.features.benutzerRollen = true; fixture.detectChanges(); - existsAsHtmlElement(fixture, benutzerUndRollenNavigationSelector); + existsAsHtmlElement(fixture, usersRolesNavigationSelector); }); it('should not show benutzer & rollen if benutzerRollen feature toggle is false', () => { component.environment.features.benutzerRollen = false; fixture.detectChanges(); - notExistsAsHtmlElement(fixture, benutzerUndRollenNavigationSelector); + notExistsAsHtmlElement(fixture, usersRolesNavigationSelector); }); it('should show organisationsEinheiten if link in apiRoot exists', () => { diff --git a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.html b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.html index 2449a303b1..71a2c7edd3 100644 --- a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.html +++ b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.html @@ -1 +1,5 @@ -<admin-organisationseinheit-form-container/> \ No newline at end of file +<ng-container *ngIf="(apiRootStateResource$ | async)?.resource as apiRoot"> + @if(apiRoot | hasLink: ApiRootLinkRel.ORGANISATIONS_EINHEIT){ + <admin-organisationseinheit-form-container data-test-id="organisations-einheit-form"/> + } +</ng-container> 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 4ad49ca459..e27ea055d1 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 @@ -1,15 +1,31 @@ import { OrganisationsEinheitFormContainerComponent } 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 { createApiRootResource } from 'libs/api-root-shared/test/api-root'; +import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { MockComponent } from 'ng-mocks'; +import { of } from 'rxjs'; import { OrganisationsEinheitFormPageComponent } from './organisationseinheit-form-page.component'; describe('OrganisationsEinheitFormPageComponent', () => { let component: OrganisationsEinheitFormPageComponent; let fixture: ComponentFixture<OrganisationsEinheitFormPageComponent>; + const organisationsEinheiteFormSelector: string = getDataTestIdOf('organisations-einheit-form'); + + const apiRootStateResource$ = of(createStateResource(createApiRootResource())); + const apiRootService: Mock<ApiRootService> = { + ...mock(ApiRootService), + getApiRoot: jest.fn().mockReturnValue(apiRootStateResource$), + }; + beforeEach(async () => { await TestBed.configureTestingModule({ + imports: [TechSharedModule], declarations: [OrganisationsEinheitFormPageComponent, MockComponent(OrganisationsEinheitFormContainerComponent)], + providers: [{ provide: ApiRootService, useValue: apiRootService }], }).compileComponents(); }); @@ -23,4 +39,31 @@ describe('OrganisationsEinheitFormPageComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + describe('component', () => { + describe('ngOnInit', () => { + it('should get apiRoot', () => { + component.ngOnInit(); + + expect(component.apiRootStateResource$).toBe(apiRootStateResource$); + }); + }); + }); + + 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]))); + + existsAsHtmlElement(fixture, organisationsEinheiteFormSelector); + }); + + it('should not be rendered if apiRootState has no link', () => { + component.apiRootStateResource$ = of(createStateResource(createApiRootResource())); + + notExistsAsHtmlElement(fixture, organisationsEinheiteFormSelector); + }); + }); + }); }); diff --git a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.ts b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.ts index b7c9e0ea72..6a14ce6da4 100644 --- a/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.ts +++ b/alfa-client/apps/admin/src/pages/organisationseinheit/organisationseinheit-form-page/organisationseinheit-form-page.component.ts @@ -1,7 +1,20 @@ -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, OnInit } from '@angular/core'; +import { Observable, of } from 'rxjs'; @Component({ selector: 'organisationseinheit-form-page', templateUrl: './organisationseinheit-form-page.component.html', }) -export class OrganisationsEinheitFormPageComponent {} +export class OrganisationsEinheitFormPageComponent implements OnInit { + 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/users-roles/user-add-page/user-add-page.component.html b/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.html index dad58a8662..b6866e0ee5 100644 --- a/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.html +++ b/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.html @@ -1 +1,3 @@ -<admin-user-add-form /> +@if(environment.features.benutzerRollen){ + <admin-user-add-form data-test-id="user-add-form"/> +} \ No newline at end of file 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 eecaa8e5c0..49c6e7a84d 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 @@ -1,5 +1,8 @@ import { UserAddFormComponent } from '@admin-client/admin-settings'; +import { existsAsHtmlElement, notExistsAsHtmlElement } from '@alfa-client/test-utils'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { createEnvironment } from 'libs/environment-shared/test/environment'; +import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { MockComponent } from 'ng-mocks'; import { UserAddPageComponent } from './user-add-page.component'; @@ -7,6 +10,9 @@ describe('UserAddPageComponent', () => { let component: UserAddPageComponent; let fixture: ComponentFixture<UserAddPageComponent>; + const userAddFormSelector: string = getDataTestIdOf('user-add-form'); + const environment = createEnvironment(); + beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [UserAddPageComponent, MockComponent(UserAddFormComponent)], @@ -14,10 +20,27 @@ describe('UserAddPageComponent', () => { fixture = TestBed.createComponent(UserAddPageComponent); component = fixture.componentInstance; + component.environment = environment; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); + + describe('template', () => { + it('should render the users roles component if feature toggle is true', () => { + environment.features.benutzerRollen = true; + fixture.detectChanges(); + + existsAsHtmlElement(fixture, userAddFormSelector); + }); + + it('should not render the users roles component if feature toggle is false', () => { + environment.features.benutzerRollen = false; + fixture.detectChanges(); + + notExistsAsHtmlElement(fixture, userAddFormSelector); + }); + }); }); diff --git a/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.ts b/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.ts index f3bcc1eaf5..e52105d82b 100644 --- a/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.ts +++ b/alfa-client/apps/admin/src/pages/users-roles/user-add-page/user-add-page.component.ts @@ -1,7 +1,10 @@ +import { Environment, getEnvironmentFactory } from '@alfa-client/environment-shared'; import { Component } from '@angular/core'; @Component({ selector: 'user-add-page', templateUrl: './user-add-page.component.html', }) -export class UserAddPageComponent {} +export class UserAddPageComponent { + public environment: Environment = getEnvironmentFactory(); +} diff --git a/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.html b/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.html index 3000e0ffba..dc2545d652 100644 --- a/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.html +++ b/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.html @@ -1 +1,3 @@ -<admin-users-roles /> \ No newline at end of file +@if(environment.features.benutzerRollen){ + <admin-users-roles data-test-id="users-roles"/> +} 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 1285eda740..a25520507f 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 @@ -1,5 +1,8 @@ import { UsersRolesComponent } from '@admin-client/admin-settings'; +import { existsAsHtmlElement, notExistsAsHtmlElement } from '@alfa-client/test-utils'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { createEnvironment } from 'libs/environment-shared/test/environment'; +import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { MockComponent } from 'ng-mocks'; import { UserRolesPageComponent } from './user-roles-page.component'; @@ -7,6 +10,9 @@ describe('UserRolesPageComponent', () => { let component: UserRolesPageComponent; let fixture: ComponentFixture<UserRolesPageComponent>; + const usersRolesSelector: string = getDataTestIdOf('users-roles'); + const environment = createEnvironment(); + beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [UserRolesPageComponent], @@ -15,10 +21,27 @@ describe('UserRolesPageComponent', () => { fixture = TestBed.createComponent(UserRolesPageComponent); component = fixture.componentInstance; + component.environment = environment; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); + + describe('template', () => { + it('should render the users roles component if feature toggle is true', () => { + environment.features.benutzerRollen = true; + fixture.detectChanges(); + + existsAsHtmlElement(fixture, usersRolesSelector); + }); + + it('should not render the users roles component if feature toggle is false', () => { + environment.features.benutzerRollen = false; + fixture.detectChanges(); + + notExistsAsHtmlElement(fixture, usersRolesSelector); + }); + }); }); diff --git a/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.ts b/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.ts index 6b3576a76e..eacc7b424e 100644 --- a/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.ts +++ b/alfa-client/apps/admin/src/pages/users-roles/user-roles-page/user-roles-page.component.ts @@ -1,7 +1,10 @@ +import { Environment, getEnvironmentFactory } from '@alfa-client/environment-shared'; import { Component } from '@angular/core'; @Component({ selector: 'app-user-roles-page', templateUrl: './user-roles-page.component.html', }) -export class UserRolesPageComponent {} +export class UserRolesPageComponent { + public environment: Environment = getEnvironmentFactory(); +} -- GitLab