diff --git a/myteamwallet_frontend_modern/src/app/models/cashbox-export.model.ts b/myteamwallet_frontend_modern/src/app/models/cashbox-export.model.ts new file mode 100644 index 0000000..8ab1800 --- /dev/null +++ b/myteamwallet_frontend_modern/src/app/models/cashbox-export.model.ts @@ -0,0 +1,16 @@ +import { RecurringTransactionInterval } from './recurring-transaction.model'; + +export type CashboxExportFormat = 'csv' | 'pdf'; + +export interface CashboxExportSubscription { + recipients: string[]; + interval: RecurringTransactionInterval; + active: boolean; + nextRunDate: string | null; +} + +export interface UpdateCashboxExportSubscription { + recipients: string[]; + interval: RecurringTransactionInterval; + active: boolean; +} diff --git a/myteamwallet_frontend_modern/src/app/shared/file-download/file-download.service.spec.ts b/myteamwallet_frontend_modern/src/app/shared/file-download/file-download.service.spec.ts new file mode 100644 index 0000000..d3ad24a --- /dev/null +++ b/myteamwallet_frontend_modern/src/app/shared/file-download/file-download.service.spec.ts @@ -0,0 +1,29 @@ +import { TestBed } from '@angular/core/testing'; +import { FileDownloadService } from './file-download.service'; + +describe('FileDownloadService', () => { + let service: FileDownloadService; + let clickSpy: ReturnType; + let createObjectURLSpy: ReturnType; + let revokeObjectURLSpy: ReturnType; + + beforeEach(() => { + service = TestBed.inject(FileDownloadService); + clickSpy = vi.fn(); + createObjectURLSpy = vi.fn(() => 'blob:mock-url'); + revokeObjectURLSpy = vi.fn(); + vi.spyOn(URL, 'createObjectURL').mockImplementation(createObjectURLSpy as (obj: Blob | MediaSource) => string); + vi.spyOn(URL, 'revokeObjectURL').mockImplementation(revokeObjectURLSpy as (url: string) => void); + vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(clickSpy as () => void); + }); + + it('creates an object URL, clicks a temporary anchor with the given filename, and revokes the URL', () => { + const blob = new Blob(['content'], { type: 'text/csv' }); + + service.save(blob, 'kassenbuch.csv'); + + expect(createObjectURLSpy).toHaveBeenCalledWith(blob); + expect(clickSpy).toHaveBeenCalledTimes(1); + expect(revokeObjectURLSpy).toHaveBeenCalledWith('blob:mock-url'); + }); +}); diff --git a/myteamwallet_frontend_modern/src/app/shared/file-download/file-download.service.ts b/myteamwallet_frontend_modern/src/app/shared/file-download/file-download.service.ts new file mode 100644 index 0000000..e72d13b --- /dev/null +++ b/myteamwallet_frontend_modern/src/app/shared/file-download/file-download.service.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ providedIn: 'root' }) +export class FileDownloadService { + save(blob: Blob, filename: string): void { + const url = URL.createObjectURL(blob); + const anchor = document.createElement('a'); + anchor.href = url; + anchor.download = filename; + anchor.click(); + URL.revokeObjectURL(url); + } +}