From 148269da115e2879b0d6d69a484d40c5c2798e4e Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Tue, 4 Aug 2026 08:39:10 +0200 Subject: [PATCH] fix: add error handling to CashboxExportSubscriptionDialog --- .../cashbox-export-subscription-dialog.html | 6 ++++ ...cashbox-export-subscription-dialog.spec.ts | 32 ++++++++++++++++++- .../cashbox-export-subscription-dialog.ts | 21 +++++++++--- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.html b/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.html index 0f470ff..9e076b5 100644 --- a/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.html +++ b/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.html @@ -1,5 +1,11 @@

Automatischen Versand einrichten

+ @if (loadError()) { +

{{ loadError() }}

+ } + @if (saveError()) { +

{{ saveError() }}

+ } E-Mail-Adresse hinzufügen diff --git a/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.spec.ts b/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.spec.ts index 45d7910..9580ea4 100644 --- a/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.spec.ts +++ b/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { of } from 'rxjs'; +import { of, throwError } from 'rxjs'; import { CashboxExportApi } from '../../../../core/team/cashbox-export-api'; import { CashboxExportSubscriptionDialog } from './cashbox-export-subscription-dialog'; @@ -59,4 +59,34 @@ describe('CashboxExportSubscriptionDialog', () => { fixture.componentInstance['removeRecipient']('a@example.com'); expect(fixture.componentInstance['recipients']()).toEqual([]); }); + + it('handles getSubscription error by setting loadError', async () => { + getSubscription.mockReturnValueOnce(throwError(() => new Error('API error'))); + + await TestBed.resetTestingModule(); + await TestBed.configureTestingModule({ + imports: [CashboxExportSubscriptionDialog], + providers: [ + { provide: MAT_DIALOG_DATA, useValue: { teamId: 5 } }, + { provide: MatDialogRef, useValue: dialogRef }, + { provide: CashboxExportApi, useValue: { getSubscription, updateSubscription } }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(CashboxExportSubscriptionDialog); + fixture.detectChanges(); + + expect(fixture.componentInstance['loadError']()).toBe('Einstellungen konnten nicht geladen werden.'); + }); + + it('handles updateSubscription error by setting saveError and not closing dialog', () => { + updateSubscription.mockReturnValueOnce(throwError(() => new Error('API error'))); + dialogRef.close.mockClear(); + + fixture.componentInstance['addRecipient']('b@example.com'); + fixture.componentInstance['save'](); + + expect(fixture.componentInstance['saveError']()).toBe('Speichern fehlgeschlagen.'); + expect(dialogRef.close).not.toHaveBeenCalled(); + }); }); diff --git a/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.ts b/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.ts index b052c07..904a062 100644 --- a/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.ts +++ b/myteamwallet_frontend_modern/src/app/features/team/cashbox/cashbox-export-subscription-dialog/cashbox-export-subscription-dialog.ts @@ -35,15 +35,22 @@ export class CashboxExportSubscriptionDialog { private readonly api = inject(CashboxExportApi); protected readonly recipients = signal([]); + protected readonly loadError = signal(null); + protected readonly saveError = signal(null); protected readonly form = this.formBuilder.nonNullable.group({ interval: ['monthly' as RecurringTransactionInterval, Validators.required], active: [false], }); constructor() { - this.api.getSubscription(this.data.teamId).subscribe((subscription) => { - this.recipients.set(subscription.recipients); - this.form.setValue({ interval: subscription.interval, active: subscription.active }); + this.api.getSubscription(this.data.teamId).subscribe({ + next: (subscription) => { + this.recipients.set(subscription.recipients); + this.form.setValue({ interval: subscription.interval, active: subscription.active }); + }, + error: () => { + this.loadError.set('Einstellungen konnten nicht geladen werden.'); + }, }); } @@ -59,9 +66,15 @@ export class CashboxExportSubscriptionDialog { protected save(): void { if (this.form.invalid) return; + this.saveError.set(null); const { interval, active } = this.form.getRawValue(); this.api .updateSubscription(this.data.teamId, { recipients: this.recipients(), interval, active }) - .subscribe(() => this.dialogRef.close()); + .subscribe({ + next: () => this.dialogRef.close(), + error: () => { + this.saveError.set('Speichern fehlgeschlagen.'); + }, + }); } }