Skip to content
Snippets Groups Projects
Commit 3c837842 authored by Albert Bruns's avatar Albert Bruns
Browse files

OZG-7620 delete user

parent fceb6a33
No related branches found
No related tags found
1 merge request!72OZG-7620-user-delete
Showing
with 152 additions and 6 deletions
...@@ -75,6 +75,10 @@ export abstract class KeycloakFormService<T> { ...@@ -75,6 +75,10 @@ export abstract class KeycloakFormService<T> {
abstract _doSubmit(): Observable<StateResource<T>>; abstract _doSubmit(): Observable<StateResource<T>>;
public delete(): Observable<StateResource<T>> {
return null;
}
_patch(valueToPatch: T): void { _patch(valueToPatch: T): void {
this.form.reset(); this.form.reset();
......
<ods-button-with-spinner
(clickEmitter)="delete()"
variant="outline"
text="Löschen"
dataTestId="delete-button"
/>
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { dispatchEventFromFixture, existsAsHtmlElement, Mock, mock } from '@alfa-client/test-utils';
import { DialogService } from '@alfa-client/ui';
import { ButtonWithSpinnerComponent } from '@ods/component';
import { MockComponent } from 'ng-mocks';
import { getDataTestIdAttributeOf } from '../../../../../../tech-shared/test/data-test';
import { UserFormDeleteDialogComponent } from '../user-form-delete-dialog/user-form-delete-dialog.component';
import { UserFormDeleteButtonComponent } from './user-form-delete-button.component';
describe('UserFormDeleteButtonComponent', () => {
let component: UserFormDeleteButtonComponent;
let fixture: ComponentFixture<UserFormDeleteButtonComponent>;
const deleteButton: string = getDataTestIdAttributeOf('delete-button');
let dialogService: Mock<DialogService>;
beforeEach(async () => {
dialogService = mock(DialogService);
await TestBed.configureTestingModule({
imports: [UserFormDeleteButtonComponent],
declarations: [MockComponent(ButtonWithSpinnerComponent)],
providers: [{ provide: DialogService, useValue: dialogService }],
}).compileComponents();
fixture = TestBed.createComponent(UserFormDeleteButtonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('component', () => {
describe('delete', () => {
it('should open dialog', () => {
component.delete();
expect(dialogService.open).toHaveBeenCalledWith(UserFormDeleteDialogComponent);
});
});
});
describe('template', () => {
describe('button with spinner', () => {
it('should exist', () => {
existsAsHtmlElement(fixture, deleteButton);
});
it('should call delete on click', () => {
component.delete = jest.fn();
dispatchEventFromFixture(fixture, deleteButton, 'clickEmitter');
expect(component.delete).toHaveBeenCalled();
});
});
});
});
import { DialogService } from '@alfa-client/ui';
import { Component, inject } from '@angular/core';
import { ButtonWithSpinnerComponent } from '@ods/component';
import { UserFormDeleteDialogComponent } from '../user-form-delete-dialog/user-form-delete-dialog.component';
@Component({
selector: 'admin-user-form-delete-button',
standalone: true,
imports: [ButtonWithSpinnerComponent],
templateUrl: './user-form-delete-button.component.html',
})
export class UserFormDeleteButtonComponent {
private readonly dialogService = inject(DialogService);
public delete(): void {
this.dialogService.openWidely(UserFormDeleteDialogComponent);
}
}
<p>user-form-delete-dialog works!</p>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UserFormDeleteDialogComponent } from './user-form-delete-dialog.component';
describe('UserFormDeleteDialogComponent', () => {
let component: UserFormDeleteDialogComponent;
let fixture: ComponentFixture<UserFormDeleteDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [UserFormDeleteDialogComponent]
})
.compileComponents();
fixture = TestBed.createComponent(UserFormDeleteDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component } from '@angular/core';
@Component({
selector: 'admin-user-form-delete-dialog',
standalone: true,
imports: [],
templateUrl: './user-form-delete-dialog.component.html',
})
export class UserFormDeleteDialogComponent {}
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
[formGroupParent]="formService.form" [formGroupParent]="formService.form"
[formGroupOrganisationsEinheiten]="formService.getOrganisationsEinheitenGroup()" [formGroupOrganisationsEinheiten]="formService.getOrganisationsEinheitenGroup()"
/> />
<div class="flex justify-between">
<admin-user-form-save-button /> <admin-user-form-save-button />
@if(formService.isPatch()){
<admin-user-form-delete-button data-test-id="delete-button-host"/>
}
</div>
</div> </div>
</ods-spinner> </ods-spinner>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
*/ */
import { User } from '@admin-client/user-shared'; import { User } from '@admin-client/user-shared';
import { createEmptyStateResource, createStateResource, StateResource } from '@alfa-client/tech-shared'; import { createEmptyStateResource, createStateResource, StateResource } from '@alfa-client/tech-shared';
import { getMockComponent, mock, Mock, notExistsAsHtmlElement } from '@alfa-client/test-utils'; import { existsAsHtmlElement, getMockComponent, mock, Mock, notExistsAsHtmlElement } from '@alfa-client/test-utils';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormGroup, ReactiveFormsModule } from '@angular/forms'; import { FormGroup, ReactiveFormsModule } from '@angular/forms';
...@@ -34,6 +34,7 @@ import { MockComponent } from 'ng-mocks'; ...@@ -34,6 +34,7 @@ import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { getDataTestIdOf } from '../../../../../tech-shared/test/data-test'; import { getDataTestIdOf } from '../../../../../tech-shared/test/data-test';
import { UserFormDataComponent } from './user-form-data/user-form-data.component'; import { UserFormDataComponent } from './user-form-data/user-form-data.component';
import { UserFormDeleteButtonComponent } from './user-form-delete-button/user-form-delete-button.component';
import { UserFormHeadlineComponent } from './user-form-headline/user-form-headline.component'; import { UserFormHeadlineComponent } from './user-form-headline/user-form-headline.component';
import { UserFormOrganisationsEinheitListComponent } from './user-form-organisations-einheit-list/user-form-organisations-einheit-list.component'; import { UserFormOrganisationsEinheitListComponent } from './user-form-organisations-einheit-list/user-form-organisations-einheit-list.component';
import { UserFormRolesComponent } from './user-form-roles/user-form-roles.component'; import { UserFormRolesComponent } from './user-form-roles/user-form-roles.component';
...@@ -47,6 +48,7 @@ describe('UserFormComponent', () => { ...@@ -47,6 +48,7 @@ describe('UserFormComponent', () => {
let formService: Mock<UserFormService>; let formService: Mock<UserFormService>;
const userContent: string = getDataTestIdOf('user-content'); const userContent: string = getDataTestIdOf('user-content');
const deleteButton: string = getDataTestIdOf('delete-button-host');
beforeEach(async () => { beforeEach(async () => {
formService = <any>{ formService = <any>{
...@@ -66,8 +68,8 @@ describe('UserFormComponent', () => { ...@@ -66,8 +68,8 @@ describe('UserFormComponent', () => {
MockComponent(UserFormOrganisationsEinheitListComponent), MockComponent(UserFormOrganisationsEinheitListComponent),
MockComponent(UserFormRolesComponent), MockComponent(UserFormRolesComponent),
MockComponent(UserFormHeadlineComponent), MockComponent(UserFormHeadlineComponent),
MockComponent(UserFormDeleteButtonComponent),
], ],
providers: [{ provide: UserFormService, useValue: formService }],
}) })
.overrideComponent(UserFormComponent, { .overrideComponent(UserFormComponent, {
set: { set: {
...@@ -130,7 +132,6 @@ describe('UserFormComponent', () => { ...@@ -130,7 +132,6 @@ describe('UserFormComponent', () => {
it('should exist with input', () => { it('should exist with input', () => {
const formDataComponent: UserFormDataComponent = getMockComponent(fixture, UserFormDataComponent); const formDataComponent: UserFormDataComponent = getMockComponent(fixture, UserFormDataComponent);
expect(formDataComponent).toBeTruthy();
expect(formDataComponent.formGroupParent).toBe(component.formService.form); expect(formDataComponent.formGroupParent).toBe(component.formService.form);
}); });
}); });
...@@ -151,7 +152,6 @@ describe('UserFormComponent', () => { ...@@ -151,7 +152,6 @@ describe('UserFormComponent', () => {
UserFormOrganisationsEinheitListComponent, UserFormOrganisationsEinheitListComponent,
); );
expect(organisationsEinheitListComponent).toBeTruthy();
expect(organisationsEinheitListComponent.formGroupParent).toBe(component.formService.form); expect(organisationsEinheitListComponent.formGroupParent).toBe(component.formService.form);
expect(organisationsEinheitListComponent.formGroupOrganisationsEinheiten).toBe( expect(organisationsEinheitListComponent.formGroupOrganisationsEinheiten).toBe(
component.formService.getOrganisationsEinheitenGroup(), component.formService.getOrganisationsEinheitenGroup(),
...@@ -167,4 +167,20 @@ describe('UserFormComponent', () => { ...@@ -167,4 +167,20 @@ describe('UserFormComponent', () => {
notExistsAsHtmlElement(fixture, userContent); notExistsAsHtmlElement(fixture, userContent);
}); });
}); });
describe('admin delete button', () => {
it('should exist', () => {
formService.isPatch.mockReturnValue(true);
fixture.detectChanges();
existsAsHtmlElement(fixture, deleteButton);
});
it('should not exist', () => {
formService.isPatch.mockReturnValue(false);
fixture.detectChanges();
notExistsAsHtmlElement(fixture, deleteButton);
});
});
}); });
...@@ -29,6 +29,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; ...@@ -29,6 +29,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { SpinnerComponent } from '@ods/component'; import { SpinnerComponent } from '@ods/component';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { UserFormDataComponent } from './user-form-data/user-form-data.component'; import { UserFormDataComponent } from './user-form-data/user-form-data.component';
import { UserFormDeleteButtonComponent } from './user-form-delete-button/user-form-delete-button.component';
import { UserFormHeadlineComponent } from './user-form-headline/user-form-headline.component'; import { UserFormHeadlineComponent } from './user-form-headline/user-form-headline.component';
import { UserFormOrganisationsEinheitListComponent } from './user-form-organisations-einheit-list/user-form-organisations-einheit-list.component'; import { UserFormOrganisationsEinheitListComponent } from './user-form-organisations-einheit-list/user-form-organisations-einheit-list.component';
import { UserFormRolesComponent } from './user-form-roles/user-form-roles.component'; import { UserFormRolesComponent } from './user-form-roles/user-form-roles.component';
...@@ -44,12 +45,13 @@ import { UserFormService } from './user.formservice'; ...@@ -44,12 +45,13 @@ import { UserFormService } from './user.formservice';
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
AsyncPipe, AsyncPipe,
SpinnerComponent,
UserFormDataComponent, UserFormDataComponent,
UserFormRolesComponent, UserFormRolesComponent,
UserFormOrganisationsEinheitListComponent, UserFormOrganisationsEinheitListComponent,
UserFormHeadlineComponent, UserFormHeadlineComponent,
UserFormSaveButtonComponent, UserFormSaveButtonComponent,
SpinnerComponent, UserFormDeleteButtonComponent,
], ],
}) })
export class UserFormComponent implements OnInit { export class UserFormComponent implements OnInit {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment