Introduce multi-format book support, including audiobooks (#2486)

* fix: support reading alternative book formats using bookType query param

* feat: add streaming reader support for alternative EPUB formats

* refactor: extract tabs section into MetadataTabsComponent

* feat: implement per-file reading progress tracking

* feat: add configurable format priority with cascading fallback

* refactor: redesign library creator with single-page layout

* refactor: unify reading progress into ReadingProgressService

* refactor: improve delete options with clearer file format and book deletion

* refactor: improve book format matching with normalization and fuzzy fallback

* feat: add folder-based audiobook support with ZIP downloads and preparing state

* fix: display unique format types in metadata viewer

* refactor: auto-attach files to single book in folder during rescan

* feat: implement folder-centric book file grouping with fuzzy matching

* refactor: consolidate book grouping with organization mode support

* fix: use folder hash for folder-based audiobooks in auto-attach

* fix: delete only BookFileEntity on file removal, not entire book

* fix: set folderBased flag and correct file size for auto-attached audiobook folders

* fix: use count query to avoid lazy initialization in file delete handler

* fix: preserve book metadata when file is moved by detecting hash match

* fix: skip books with no files in restoration to avoid NPE

* fix: round all progress percentages to one decimal place before sending to UI

* style: improve library creator dialog spacing and layout

* fix: migrate FOLDER_AS_BOOK to BOOK_PER_FOLDER for backwards compatibility

* fix: FileMoveService now handles multi-file BookEntity properly

* style: redesign metadata-picker and file-mover UI components

* style: redesign file-naming-pattern UI and improve theme contrast

* style: relax spacing in library-creator component

* style: tighten directory-picker layout for consistency

* fix: PathPatternResolver now respects folderBased flag for audiobooks

* style: move checkmark column to left side and add pending status in file-mover

* refactor: consolidate BookFileType into BookType and add audiobook styling

* feat: show 'Continue Reading' button for in-progress books

* fix: preserve dots in folder names during grouping and prevent duplicate attachments

* style: reduce gap between download-all button and primary file section

* style: shorten 'Continue Reading' button to 'Read' on mobile

* feat: add DISK_TYPE config to disable file moves on network storage

* style: standardize settings pages with shared styles and consistent spacing

* style: revamp settings pages with modern card-based layouts

* style: revamp OPDS, auth, and task management settings layouts

* fix: update FileMoveService tests to include AppProperties parameter

* fix: derive BookFileType from extension when uploading additional book files

* feat: show format type and size in download button with dropdown for alternatives

* feat: add audiobook streaming player with HTTP Range support

* feat: add M4B chapter extraction and chapter navigation

* feat: add audiobook bookmarks and sleep timer

* refactor: split AudiobookReaderService into focused services

* feat: add Media Session API for background audio playback

* feat: display file extensions in format tags with distinct colors and add audiobook upload support

* feat: require bookFileId for viewer settings API

* fix: show split button for audiobooks with readable alternatives

* feat: improve reading sessions table with book type badges and better formatting

* feat: add audiobook play button in files tab

* feat: use file extension for format display and meaningful tab values

* feat: add extension field to BookFile DTO

* feat: use extension field for book card format pill

* fix: use mixed orientation for format priority drag-drop to support multi-line layout

* feat: add attach book files feature to consolidate single-file books

* fix: increase drag handle size for format priority chips

* fix: add missing BookFileRepository mock to BookServiceDeleteTests

* feat: add delete buttons to files tab and move shelf to other items menu

* feat: add physical books support for cataloging books without digital files

* refactor: redesign icon-picker component with improved styling

* refactor: redesign metadata-picker component with improved layout and alignment

* refactor: move Add Physical Book to top of library menu

* refactor: use p-autoComplete for authors/categories in add-physical-book dialog

* feat: add square cover search and display support for audiobooks

* fix: navigate to first page when opening unread ebooks

* fix: exclude API requests from service worker interception

* feat: support fileless books with automatic file attachment

* fix: bypass service worker for audiobook streaming requests

* refactor: remove alphabetical filter sorting, default to count, limit filters to 100

---------

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2026-01-27 10:12:50 -07:00
committed by GitHub
co-authored by acx10
parent c23e38b5a5
commit 3f334202b6
340 changed files with 23225 additions and 20727 deletions
@@ -1,18 +1,18 @@
<div class="main-container enclosing-container">
<div class="settings-header">
<div class="section-title-group">
<div>
<h2 class="settings-title">
<div class="settings-card">
<div class="section-header">
<div class="section-header-row">
<div class="section-header-text">
<h3 class="section-title">
<i class="pi pi-server"></i>
Email Providers
</h2>
<p class="settings-description">
Configure email-sending services like Gmail, Outlook, or custom SMTP servers for sending books via email. The default email provider will be used for 'Quick Book Send' located in the Book Card menu.
</h3>
<p class="section-description">
Configure email-sending services like Gmail, Outlook, or custom SMTP servers. The default provider is used for 'Quick Book Send' in the Book Card menu.
</p>
</div>
<p-button
icon="pi pi-plus"
label="Create Provider"
label="Add Provider"
severity="success"
size="small"
[outlined]="true"
@@ -21,179 +21,42 @@
</div>
</div>
<div class="settings-content">
<div class="preferences-section">
<div class="table-card">
<p-table [value]="emailProviders" [scrollable]="true" scrollHeight="flex">
<ng-template pTemplate="header">
<tr>
<th style="width: 5%;">
<div class="header-content">
<i class="pi pi-star"></i>
<span>Default</span>
<div class="section-body">
@if (emailProviders.length === 0) {
<div class="empty-state">
<i class="pi pi-envelope"></i>
<p class="empty-title">No email providers configured</p>
<p class="empty-subtitle">Create your first email provider to start sending books</p>
</div>
} @else {
<div class="providers-list">
@for (provider of emailProviders; track provider.id) {
<div class="provider-item" [class.is-default]="provider.id === defaultProviderId">
<div class="provider-header">
<div class="provider-info">
<div class="provider-name-row">
<p-radioButton
name="defaultProvider"
[value]="provider.id"
[(ngModel)]="defaultProviderId"
(onClick)="setDefaultProvider(provider)">
</p-radioButton>
@if (provider.isEditing) {
<input type="text" pInputText [(ngModel)]="provider.name" placeholder="Provider name" class="name-input"/>
} @else {
<span class="provider-name">{{ provider.name }}</span>
@if (provider.shared) {
<span class="shared-badge" pTooltip="Shared with all users">
<i class="pi pi-share-alt"></i>
</span>
}
@if (provider.id === defaultProviderId) {
<span class="default-badge">Default</span>
}
}
</div>
</th>
<th style="width: 20%;">
<div class="header-content">
<i class="pi pi-tag"></i>
<span>Name</span>
</div>
</th>
<th style="width: 14%;">
<div class="header-content">
<i class="pi pi-server"></i>
<span>Host</span>
</div>
</th>
<th style="width: 5%;">
<div class="header-content">
<i class="pi pi-link"></i>
<span>Port</span>
</div>
</th>
<th style="width: 13%;">
<div class="header-content">
<i class="pi pi-user"></i>
<span>Username</span>
</div>
</th>
<th style="width: 11%;">
<div class="header-content">
<i class="pi pi-lock"></i>
<span>Password</span>
</div>
</th>
<th style="width: 11%;">
<div class="header-content">
<i class="pi pi-envelope"></i>
<span>From Address</span>
</div>
</th>
<th style="width: 4%;" class="permission-header">Auth</th>
<th style="width: 5%;" class="permission-header">StartTLS</th>
@if (isAdmin) {
<th style="width: 5%;" class="permission-header">
<div class="header-content">
<i class="pi pi-share-alt"></i>
<span>Shared</span>
</div>
</th>
}
<th style="width: 7%;" class="actions-header">
<div class="header-content">
<i class="pi pi-pencil"></i>
<span>Edit</span>
</div>
</th>
<th style="width: 8%;" class="actions-header">
<div class="header-content">
<i class="pi pi-trash"></i>
<span>Delete</span>
</div>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-provider>
<tr>
<td class="cell-center">
<p-radioButton
name="defaultProvider"
[value]="provider.id"
[(ngModel)]="defaultProviderId"
(onClick)="setDefaultProvider(provider)">
</p-radioButton>
</td>
<td>
@if (provider.isEditing) {
<input type="text" [(ngModel)]="provider.name" class="p-inputtext input-full-width" size="small"/>
}
@if (!provider.isEditing) {
<div class="provider-name-cell">
<span>
{{ provider.name }}
@if (provider.shared) {
<span class="shared-badge" pTooltip="Shared provider">S</span>
}
</span>
</div>
}
</td>
<td>
@if (provider.isEditing) {
<input type="text" [(ngModel)]="provider.host" class="p-inputtext input-full-width" size="small"/>
}
@if (!provider.isEditing) {
<span>{{ provider.host }}</span>
}
</td>
<td>
@if (provider.isEditing) {
<input type="number" [(ngModel)]="provider.port" class="p-inputtext input-full-width" size="small"/>
}
@if (!provider.isEditing) {
<span>{{ provider.port }}</span>
}
</td>
<td>
@if (provider.isEditing) {
<input type="text" [(ngModel)]="provider.username" class="p-inputtext input-full-width" size="small"/>
}
@if (!provider.isEditing) {
<span>{{ provider.username }}</span>
}
</td>
<td>
@if (provider.isEditing) {
<input [(ngModel)]="provider.password" class="p-inputtext input-full-width" size="small"/>
}
@if (!provider.isEditing) {
<span class="password-hidden">Hidden</span>
}
</td>
<td>
@if (provider.isEditing) {
<input type="text" [(ngModel)]="provider.fromAddress" class="p-inputtext input-full-width" size="small"/>
}
@if (!provider.isEditing) {
<span>{{ provider.fromAddress }}</span>
}
</td>
<td class="cell-center">
<p-checkbox
[(ngModel)]="provider.auth"
[binary]="true"
[disabled]="!provider.isEditing">
</p-checkbox>
</td>
<td class="cell-center">
<p-checkbox
[(ngModel)]="provider.startTls"
[binary]="true"
[disabled]="!provider.isEditing">
</p-checkbox>
</td>
@if (isAdmin) {
<td class="cell-center">
<p-checkbox
[(ngModel)]="provider.shared"
[binary]="true"
(onChange)="toggleShared(provider)"
pTooltip="Share this provider with all users">
</p-checkbox>
</td>
}
<td class="actions-cell">
</div>
<div class="provider-actions">
@if (!provider.isEditing) {
<p-button
[icon]="canModifyProvider(provider) ? 'pi pi-pencil' : 'pi pi-lock'"
@@ -203,63 +66,144 @@
[rounded]="true"
[disabled]="!canModifyProvider(provider)"
(onClick)="canModifyProvider(provider) && toggleEdit(provider)"
[pTooltip]="canModifyProvider(provider) ? 'Edit provider' : 'Cannot edit shared provider from another user'"
[pTooltip]="canModifyProvider(provider) ? 'Edit provider' : 'Cannot edit shared provider'"
tooltipPosition="left">
</p-button>
<p-button
[icon]="canModifyProvider(provider) ? 'pi pi-trash' : 'pi pi-lock'"
[severity]="canModifyProvider(provider) ? 'danger' : 'secondary'"
size="small"
[outlined]="true"
[rounded]="true"
[disabled]="!canModifyProvider(provider)"
(onClick)="canModifyProvider(provider) && deleteProvider(provider)"
[pTooltip]="canModifyProvider(provider) ? 'Delete provider' : 'Cannot delete shared provider'"
tooltipPosition="left">
</p-button>
} @else {
<p-button
icon="pi pi-check"
severity="success"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="saveProvider(provider)"
pTooltip="Save changes">
</p-button>
<p-button
icon="pi pi-times"
severity="secondary"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="toggleEdit(provider)"
pTooltip="Cancel">
</p-button>
}
@if (provider.isEditing) {
<div class="edit-actions">
<p-button
icon="pi pi-check"
severity="success"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="saveProvider(provider)"
pTooltip="Save changes">
</p-button>
<p-button
icon="pi pi-times"
severity="danger"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="toggleEdit(provider)"
pTooltip="Cancel">
</p-button>
</div>
</div>
<div class="provider-details">
<div class="detail-grid">
<div class="detail-item">
<label class="detail-label">
<i class="pi pi-server"></i>
Host
</label>
@if (provider.isEditing) {
<input type="text" pInputText [(ngModel)]="provider.host" placeholder="smtp.example.com"/>
} @else {
<span class="detail-value">{{ provider.host }}</span>
}
</div>
<div class="detail-item">
<label class="detail-label">
<i class="pi pi-link"></i>
Port
</label>
@if (provider.isEditing) {
<input type="number" pInputText [(ngModel)]="provider.port" placeholder="587"/>
} @else {
<span class="detail-value">{{ provider.port }}</span>
}
</div>
<div class="detail-item">
<label class="detail-label">
<i class="pi pi-user"></i>
Username
</label>
@if (provider.isEditing) {
<input type="text" pInputText [(ngModel)]="provider.username" placeholder="user@example.com"/>
} @else {
<span class="detail-value">{{ provider.username }}</span>
}
</div>
<div class="detail-item">
<label class="detail-label">
<i class="pi pi-lock"></i>
Password
</label>
@if (provider.isEditing) {
<input type="password" pInputText [(ngModel)]="provider.password" placeholder="Enter password"/>
} @else {
<span class="detail-value password-hidden">********</span>
}
</div>
<div class="detail-item detail-item-wide">
<label class="detail-label">
<i class="pi pi-envelope"></i>
From Address
</label>
@if (provider.isEditing) {
<input type="email" pInputText [(ngModel)]="provider.fromAddress" placeholder="noreply@example.com"/>
} @else {
<span class="detail-value">{{ provider.fromAddress }}</span>
}
</div>
</div>
<div class="toggle-options">
<div class="toggle-item">
<p-checkbox
[(ngModel)]="provider.auth"
[binary]="true"
[disabled]="!provider.isEditing"
inputId="auth-{{provider.id}}">
</p-checkbox>
<label [for]="'auth-' + provider.id" class="toggle-label">Authentication</label>
</div>
<div class="toggle-item">
<p-checkbox
[(ngModel)]="provider.startTls"
[binary]="true"
[disabled]="!provider.isEditing"
inputId="starttls-{{provider.id}}">
</p-checkbox>
<label [for]="'starttls-' + provider.id" class="toggle-label">StartTLS</label>
</div>
@if (isAdmin) {
<div class="toggle-item">
<p-checkbox
[(ngModel)]="provider.shared"
[binary]="true"
(onChange)="toggleShared(provider)"
inputId="shared-{{provider.id}}"
pTooltip="Share this provider with all users">
</p-checkbox>
<label [for]="'shared-' + provider.id" class="toggle-label">Shared</label>
</div>
}
</td>
<td class="actions-cell">
<p-button
[icon]="canModifyProvider(provider) ? 'pi pi-trash' : 'pi pi-lock'"
[severity]="canModifyProvider(provider) ? 'danger' : 'secondary'"
size="small"
[outlined]="true"
[rounded]="true"
[disabled]="!canModifyProvider(provider)"
(onClick)="canModifyProvider(provider) && deleteProvider(provider)"
[pTooltip]="canModifyProvider(provider) ? 'Delete provider' : 'Cannot delete shared provider from another user'"
tooltipPosition="left">
</p-button>
</td>
</tr>
</ng-template>
<ng-template pTemplate="emptymessage">
<tr>
<td [attr.colspan]="isAdmin ? 12 : 11">
<div class="empty-message">
<i class="pi pi-envelope"></i>
<p class="empty-title">No email providers found</p>
<p class="empty-subtitle">Create your first email provider to start sending books</p>
</div>
</td>
</tr>
</ng-template>
</p-table>
</div>
</div>
</div>
}
</div>
</div>
}
</div>
</div>
@@ -1,223 +1,256 @@
.enclosing-container {
border-color: var(--p-content-border-color);
background: var(--p-content-background);
}
@use '../../../../shared/styles/settings-shared' as settings;
.settings-header {
margin-top: 2.5rem;
padding: 0 1rem;
.section-title-group {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
@media (max-width: 767px) {
flex-direction: column;
align-items: stretch;
p-button {
align-self: flex-end;
}
}
}
}
.settings-title {
display: flex;
align-items: center;
gap: 0.75rem;
font-size: 1.125rem;
font-weight: 600;
color: var(--p-text-color);
margin: 0 0 0.75rem 0;
.pi {
color: var(--p-primary-color);
font-size: 1.25rem;
}
}
.settings-description {
color: var(--p-text-muted-color);
font-size: 0.875rem;
line-height: 1.5;
margin-bottom: 1rem;
}
.settings-content {
display: flex;
flex-direction: column;
gap: 2rem;
}
.preferences-section {
@media (min-width: 768px) {
padding: 0 1rem;
}
.settings-card {
@include settings.settings-card;
}
.section-header {
margin-bottom: 1rem;
@include settings.settings-section-header;
}
.section-title-group {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
.section-header-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
@media (max-width: 767px) {
flex-direction: column;
align-items: flex-start;
gap: 0.75rem;
@media (max-width: 767px) {
flex-direction: column;
align-items: stretch;
p-button {
align-self: flex-end;
}
p-button {
align-self: flex-end;
}
}
}
.section-header-text {
flex: 1;
}
.section-title {
@include settings.settings-section-title;
}
.section-description {
@include settings.settings-section-description;
}
.section-body {
display: flex;
flex-direction: column;
gap: 1rem;
}
// Empty state
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
font-size: 1.125rem;
font-weight: 600;
color: var(--p-text-color);
justify-content: center;
padding: 3rem 2rem;
text-align: center;
color: var(--p-text-muted-color);
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
border-radius: 6px;
.pi {
color: var(--p-primary-color);
}
}
.table-card {
border: 1px solid var(--p-content-border-color);
border-radius: 8px;
overflow: hidden;
background: var(--p-content-background);
}
.p-datatable {
.p-datatable-table {
border-collapse: separate;
border-spacing: 0;
}
.p-datatable-thead > tr > th {
background: var(--p-surface-100);
border-bottom: 2px solid var(--p-content-border-color);
padding: 1rem;
font-weight: 600;
color: var(--p-text-color);
white-space: nowrap;
}
.p-datatable-tbody > tr {
transition: background-color 0.2s;
&:hover {
background: var(--p-surface-50);
}
&:last-child {
border-bottom: none;
}
}
.p-datatable-tbody > tr > td {
padding: 1rem;
border: none;
}
}
.p-datatable th .header-content {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 0.5rem;
}
.permission-header {
text-align: center;
font-size: 0.875rem;
padding: 0.75rem 0.5rem !important;
min-width: 80px;
width: 80px;
.header-content {
justify-content: center;
}
}
.actions-header {
text-align: center;
min-width: 80px;
}
.actions-cell {
text-align: center;
}
.password-hidden {
color: var(--p-text-muted-color);
font-style: italic;
}
.empty-message {
text-align: center;
padding: 2rem 1rem;
color: var(--p-text-muted-color);
.pi {
font-size: 2rem;
font-size: 2.5rem;
margin-bottom: 1rem;
color: var(--p-surface-400);
opacity: 0.5;
}
.empty-title {
font-size: 1.125rem;
font-size: 1rem;
font-weight: 600;
margin-bottom: 0.5rem;
margin: 0 0 0.5rem 0;
color: var(--p-text-color);
}
.empty-subtitle {
font-size: 0.875rem;
font-size: settings.$settings-section-description-size;
margin: 0;
}
}
// Provider list
.providers-list {
display: flex;
flex-direction: column;
gap: 1rem;
}
.provider-item {
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
border: 1px solid var(--p-content-border-color);
border-left: 3px solid var(--p-content-border-color);
border-radius: 6px;
padding: 1rem;
transition: border-color 0.2s ease, background 0.2s ease;
&:hover {
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
}
&.is-default {
border-left-color: var(--p-primary-color);
}
}
.provider-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
padding-bottom: 0.75rem;
border-bottom: 1px dashed var(--p-content-border-color);
@media (max-width: 767px) {
flex-direction: column;
align-items: stretch;
gap: 0.75rem;
}
}
.provider-info {
flex: 1;
min-width: 0;
}
.provider-name-row {
display: flex;
align-items: center;
gap: 0.75rem;
flex-wrap: wrap;
}
.provider-name {
font-weight: 600;
font-size: 1rem;
color: var(--p-text-color);
}
.name-input {
width: 200px;
max-width: 100%;
}
.shared-badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 1.1rem;
height: 1.1rem;
background-color: var(--p-green-600);
color: white;
border-radius: 0.25rem;
width: 1.5rem;
height: 1.5rem;
background: color-mix(in srgb, var(--p-green-600) 20%, transparent);
color: var(--p-green-400);
border-radius: 4px;
font-size: 0.75rem;
font-weight: 700;
cursor: default;
vertical-align: text-bottom;
margin-left: 0.25rem;
.pi {
font-size: 0.75rem;
}
}
.cell-center {
text-align: center;
.default-badge {
display: inline-flex;
align-items: center;
padding: 0.125rem 0.5rem;
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
color: var(--p-primary-color);
border-radius: 4px;
font-size: 0.75rem;
font-weight: 600;
}
.input-full-width {
width: 100%;
.provider-actions {
display: flex;
gap: 0.5rem;
flex-shrink: 0;
@media (max-width: 767px) {
justify-content: flex-end;
}
}
.provider-name-cell {
// Provider details grid
.provider-details {
display: flex;
flex-direction: column;
gap: 1rem;
}
.detail-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 1rem;
@media (max-width: 767px) {
grid-template-columns: 1fr;
}
}
.detail-item {
display: flex;
flex-direction: column;
gap: 0.375rem;
&.detail-item-wide {
grid-column: span 2;
@media (max-width: 767px) {
grid-column: span 1;
}
}
input {
width: 100%;
}
}
.detail-label {
display: flex;
align-items: center;
gap: 0.375rem;
font-size: settings.$settings-description-size;
font-weight: 500;
color: var(--p-text-muted-color);
.pi {
font-size: 0.75rem;
color: var(--p-primary-color);
}
}
.detail-value {
font-size: settings.$settings-section-description-size;
color: var(--p-text-color);
word-break: break-word;
&.password-hidden {
color: var(--p-text-muted-color);
font-style: italic;
letter-spacing: 2px;
}
}
// Toggle options
.toggle-options {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
padding-top: 0.75rem;
border-top: 1px dashed var(--p-content-border-color);
}
.toggle-item {
display: flex;
align-items: center;
gap: 0.5rem;
}
.edit-actions {
display: flex;
gap: 0.25rem;
.toggle-label {
font-size: settings.$settings-description-size;
color: var(--p-text-color);
cursor: pointer;
}
@@ -1,7 +1,7 @@
import {Component, inject, OnInit} from '@angular/core';
import {Button} from 'primeng/button';
import {Checkbox} from 'primeng/checkbox';
import {MessageService, PrimeTemplate} from 'primeng/api';
import {MessageService} from 'primeng/api';
import {RadioButton} from 'primeng/radiobutton';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {TableModule} from 'primeng/table';
@@ -17,7 +17,6 @@ import {DialogLauncherService} from '../../../../shared/services/dialog-launcher
imports: [
Button,
Checkbox,
PrimeTemplate,
RadioButton,
ReactiveFormsModule,
TableModule,
@@ -1,271 +0,0 @@
import {beforeEach, describe, expect, it, vi} from 'vitest';
import {TestBed} from '@angular/core/testing';
import {HttpClient} from '@angular/common/http';
import {of, throwError} from 'rxjs';
import {EmailV2ProviderService} from './email-v2-provider.service';
import {EmailProvider} from '../email-provider.model';
describe('EmailV2ProviderService', () => {
let service: EmailV2ProviderService;
let httpClientMock: any;
const mockProvider: EmailProvider = {
isEditing: false,
id: 1,
userId: 2,
name: 'Provider1',
host: 'smtp.example.com',
port: 587,
username: 'user',
password: 'pass',
fromAddress: 'from@example.com',
auth: true,
startTls: true,
defaultProvider: false,
shared: false
};
beforeEach(() => {
httpClientMock = {
get: vi.fn(),
post: vi.fn(),
put: vi.fn(),
delete: vi.fn(),
patch: vi.fn()
};
TestBed.configureTestingModule({
providers: [
EmailV2ProviderService,
{provide: HttpClient, useValue: httpClientMock}
]
});
service = TestBed.inject(EmailV2ProviderService);
});
it('should get email providers', () => {
httpClientMock.get.mockReturnValue(of([mockProvider]));
service.getEmailProviders().subscribe(providers => {
expect(providers).toEqual([mockProvider]);
expect(httpClientMock.get).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/providers'));
});
});
it('should create email provider', () => {
httpClientMock.post.mockReturnValue(of(mockProvider));
service.createEmailProvider(mockProvider).subscribe(provider => {
expect(provider).toEqual(mockProvider);
expect(httpClientMock.post).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/providers'), mockProvider);
});
});
it('should update provider', () => {
httpClientMock.put.mockReturnValue(of(mockProvider));
service.updateProvider(mockProvider).subscribe(provider => {
expect(provider).toEqual(mockProvider);
expect(httpClientMock.put).toHaveBeenCalledWith(expect.stringContaining(`/api/v2/email/providers/${mockProvider.id}`), mockProvider);
});
});
it('should delete provider', () => {
httpClientMock.delete.mockReturnValue(of(void 0));
service.deleteProvider(1).subscribe(result => {
expect(result).toBeUndefined();
expect(httpClientMock.delete).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/providers/1'));
});
});
it('should set default provider', () => {
httpClientMock.patch.mockReturnValue(of(void 0));
service.setDefaultProvider(1).subscribe(result => {
expect(result).toBeUndefined();
expect(httpClientMock.patch).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/providers/1/set-default'), {});
});
});
it('should handle getEmailProviders error', () => {
httpClientMock.get.mockReturnValue(throwError(() => new Error('fail')));
service.getEmailProviders().subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle createEmailProvider error', () => {
httpClientMock.post.mockReturnValue(throwError(() => new Error('fail')));
service.createEmailProvider(mockProvider).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle updateProvider error', () => {
httpClientMock.put.mockReturnValue(throwError(() => new Error('fail')));
service.updateProvider(mockProvider).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle deleteProvider error', () => {
httpClientMock.delete.mockReturnValue(throwError(() => new Error('fail')));
service.deleteProvider(1).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle setDefaultProvider error', () => {
httpClientMock.patch.mockReturnValue(throwError(() => new Error('fail')));
service.setDefaultProvider(1).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
});
describe('EmailV2ProviderService - API Contract Tests', () => {
let service: EmailV2ProviderService;
let httpClientMock: any;
beforeEach(() => {
httpClientMock = {
get: vi.fn(),
post: vi.fn(),
put: vi.fn(),
delete: vi.fn(),
patch: vi.fn()
};
TestBed.configureTestingModule({
providers: [
EmailV2ProviderService,
{provide: HttpClient, useValue: httpClientMock}
]
});
service = TestBed.inject(EmailV2ProviderService);
});
it('should validate all required EmailProvider fields exist', () => {
const requiredFields: (keyof EmailProvider)[] = [
'isEditing', 'id', 'userId', 'name', 'host', 'port', 'username', 'password',
'fromAddress', 'auth', 'startTls', 'defaultProvider', 'shared'
];
const mockResponse: EmailProvider = {
isEditing: false,
id: 1,
userId: 2,
name: 'Provider1',
host: 'smtp.example.com',
port: 587,
username: 'user',
password: 'pass',
fromAddress: 'from@example.com',
auth: true,
startTls: true,
defaultProvider: false,
shared: false
};
httpClientMock.get.mockReturnValue(of([mockResponse]));
service.getEmailProviders().subscribe(providers => {
requiredFields.forEach(field => {
expect(providers[0]).toHaveProperty(field);
expect(providers[0][field]).toBeDefined();
});
});
});
it('should fail if API returns EmailProvider without required id field', () => {
const invalidResponse = [{
isEditing: false,
userId: 2,
name: 'Provider1',
host: 'smtp.example.com',
port: 587,
username: 'user',
password: 'pass',
fromAddress: 'from@example.com',
auth: true,
startTls: true,
defaultProvider: false,
shared: false
}];
httpClientMock.get.mockReturnValue(of(invalidResponse));
service.getEmailProviders().subscribe(providers => {
expect(providers[0]).not.toHaveProperty('id');
});
});
it('should call correct endpoint for getEmailProviders', () => {
httpClientMock.get.mockReturnValue(of([]));
service.getEmailProviders().subscribe();
expect(httpClientMock.get).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/providers$/));
});
it('should call correct endpoint for createEmailProvider', () => {
httpClientMock.post.mockReturnValue(of({}));
const provider = {
isEditing: false,
id: 1,
userId: 2,
name: 'Provider1',
host: 'smtp.example.com',
port: 587,
username: 'user',
password: 'pass',
fromAddress: 'from@example.com',
auth: true,
startTls: true,
defaultProvider: false,
shared: false
};
service.createEmailProvider(provider).subscribe();
expect(httpClientMock.post).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/providers$/), provider);
});
it('should call correct endpoint for updateProvider', () => {
httpClientMock.put.mockReturnValue(of({}));
const provider = {
isEditing: false,
id: 1,
userId: 2,
name: 'Provider1',
host: 'smtp.example.com',
port: 587,
username: 'user',
password: 'pass',
fromAddress: 'from@example.com',
auth: true,
startTls: true,
defaultProvider: false,
shared: false
};
service.updateProvider(provider).subscribe();
expect(httpClientMock.put).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/providers\/1$/), provider);
});
it('should call correct endpoint for deleteProvider', () => {
httpClientMock.delete.mockReturnValue(of(void 0));
service.deleteProvider(1).subscribe();
expect(httpClientMock.delete).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/providers\/1$/));
});
it('should call correct endpoint for setDefaultProvider', () => {
httpClientMock.patch.mockReturnValue(of(void 0));
service.setDefaultProvider(1).subscribe();
expect(httpClientMock.patch).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/providers\/1\/set-default$/), {});
});
});
@@ -1,18 +1,18 @@
<div class="main-container enclosing-container">
<div class="settings-header">
<div class="section-title-group">
<div>
<h2 class="settings-title">
<div class="settings-card">
<div class="section-header">
<div class="section-header-row">
<div class="section-header-text">
<h3 class="section-title">
<i class="pi pi-users"></i>
Recipient Emails
</h2>
<p class="settings-description">
Manage the list of recipients who will receive books via email. The 'Default' recipient will be used for 'Quick Book Send,' located in the Book Card menu.
</h3>
<p class="section-description">
Manage recipient email addresses for sending books. The default recipient is used for 'Quick Book Send' in the Book Card menu.
</p>
</div>
<p-button
icon="pi pi-plus"
label="Create Recipient"
label="Add Recipient"
severity="success"
size="small"
[outlined]="true"
@@ -21,75 +21,65 @@
</div>
</div>
<div class="settings-content">
<div class="preferences-section">
<div class="table-card">
<p-table [value]="recipientEmails" [scrollable]="true" scrollHeight="flex">
<ng-template pTemplate="header">
<tr>
<th style="width: 10%;">
<div class="header-content">
<i class="pi pi-star"></i>
<span>Default</span>
</div>
</th>
<th style="width: 45%;">
<div class="header-content">
<i class="pi pi-envelope"></i>
<span>Email Address</span>
</div>
</th>
<th style="width: 30%;">
<div class="header-content">
<i class="pi pi-user"></i>
<span>Name</span>
</div>
</th>
<th style="width: 8%;" class="actions-header">
<div class="header-content">
<i class="pi pi-pencil"></i>
<span>Edit</span>
</div>
</th>
<th style="width: 7%;" class="actions-header">
<div class="header-content">
<i class="pi pi-trash"></i>
<span>Delete</span>
</div>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-recipient>
<tr>
<td class="text-center">
<div class="section-body">
@if (recipientEmails.length === 0) {
<div class="empty-state">
<i class="pi pi-users"></i>
<p class="empty-title">No recipients configured</p>
<p class="empty-subtitle">Add your first email recipient to start sending books</p>
</div>
} @else {
<div class="recipients-list">
@for (recipient of recipientEmails; track recipient.id) {
<div class="recipient-item" [class.is-default]="recipient.id === defaultRecipientId">
<div class="recipient-content">
<div class="recipient-select">
<p-radioButton
name="defaultRecipient"
[value]="recipient.id"
[(ngModel)]="defaultRecipientId"
(onClick)="setDefaultRecipient(recipient)">
</p-radioButton>
</td>
</div>
<td>
<div class="recipient-info">
@if (recipient.isEditing) {
<input type="email" [(ngModel)]="recipient.email" class="p-inputtext full-width" size="small"/>
<div class="edit-form">
<div class="form-field">
<label class="field-label">
<i class="pi pi-envelope"></i>
Email
</label>
<input type="email" pInputText [(ngModel)]="recipient.email" placeholder="recipient@example.com"/>
</div>
<div class="form-field">
<label class="field-label">
<i class="pi pi-user"></i>
Name
</label>
<input type="text" pInputText [(ngModel)]="recipient.name" placeholder="Recipient name"/>
</div>
</div>
} @else {
<div class="recipient-details">
<div class="recipient-email">
<i class="pi pi-envelope"></i>
<span>{{ recipient.email }}</span>
@if (recipient.id === defaultRecipientId) {
<span class="default-badge">Default</span>
}
</div>
@if (recipient.name) {
<div class="recipient-name">
<i class="pi pi-user"></i>
<span>{{ recipient.name }}</span>
</div>
}
</div>
}
@if (!recipient.isEditing) {
<span>{{ recipient.email }}</span>
}
</td>
</div>
<td>
@if (recipient.isEditing) {
<input type="text" [(ngModel)]="recipient.name" class="p-inputtext full-width" size="small"/>
}
@if (!recipient.isEditing) {
<span>{{ recipient.name }}</span>
}
</td>
<td class="actions-cell">
<div class="recipient-actions">
@if (!recipient.isEditing) {
<p-button
icon="pi pi-pencil"
@@ -100,58 +90,40 @@
(onClick)="toggleEditRecipient(recipient)"
pTooltip="Edit recipient">
</p-button>
<p-button
icon="pi pi-trash"
severity="danger"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="deleteRecipient(recipient)"
pTooltip="Delete recipient">
</p-button>
} @else {
<p-button
icon="pi pi-check"
severity="success"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="saveRecipient(recipient)"
pTooltip="Save changes">
</p-button>
<p-button
icon="pi pi-times"
severity="secondary"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="toggleEditRecipient(recipient)"
pTooltip="Cancel">
</p-button>
}
@if (recipient.isEditing) {
<div class="edit-actions">
<p-button
icon="pi pi-check"
severity="success"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="saveRecipient(recipient)"
pTooltip="Save changes">
</p-button>
<p-button
icon="pi pi-times"
severity="danger"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="toggleEditRecipient(recipient)"
pTooltip="Cancel">
</p-button>
</div>
}
</td>
<td class="actions-cell">
<p-button
icon="pi pi-trash"
severity="danger"
size="small"
[outlined]="true"
[rounded]="true"
(onClick)="deleteRecipient(recipient)"
pTooltip="Delete recipient">
</p-button>
</td>
</tr>
</ng-template>
<ng-template pTemplate="emptymessage">
<tr>
<td colspan="5">
<div class="empty-message">
<i class="pi pi-users"></i>
<p class="empty-title">No recipients found</p>
<p class="empty-subtitle">Add your first email recipient to start sending books</p>
</div>
</td>
</tr>
</ng-template>
</p-table>
</div>
</div>
</div>
}
</div>
</div>
}
</div>
</div>
@@ -1,184 +1,213 @@
.enclosing-container {
border-color: var(--p-content-border-color);
background: var(--p-content-background);
}
@use '../../../../shared/styles/settings-shared' as settings;
.settings-header {
margin-top: 2rem;
padding: 0 1rem;
.section-title-group {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
@media (max-width: 767px) {
flex-direction: column;
align-items: stretch;
p-button {
align-self: flex-end;
}
}
}
}
.settings-title {
display: flex;
align-items: center;
gap: 0.75rem;
font-size: 1.125rem;
font-weight: 600;
color: var(--p-text-color);
margin: 0 0 0.75rem 0;
.pi {
color: var(--p-primary-color);
font-size: 1.25rem;
}
}
.settings-description {
color: var(--p-text-muted-color);
font-size: 0.875rem;
line-height: 1.5;
margin-bottom: 1rem;
}
.settings-content {
display: flex;
flex-direction: column;
gap: 2rem;
}
.preferences-section {
@media (min-width: 768px) {
padding: 0 1rem;
}
.settings-card {
@include settings.settings-card;
}
.section-header {
margin-bottom: 1rem;
@include settings.settings-section-header;
}
.section-title-group {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
.section-header-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
@media (max-width: 767px) {
flex-direction: column;
align-items: flex-start;
gap: 0.75rem;
@media (max-width: 767px) {
flex-direction: column;
align-items: stretch;
p-button {
align-self: flex-end;
}
p-button {
align-self: flex-end;
}
}
}
.section-header-text {
flex: 1;
}
.section-title {
@include settings.settings-section-title;
}
.section-description {
@include settings.settings-section-description;
}
.section-body {
display: flex;
flex-direction: column;
gap: 1rem;
}
// Empty state
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 3rem 2rem;
text-align: center;
color: var(--p-text-muted-color);
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
border-radius: 6px;
.pi {
font-size: 2.5rem;
margin-bottom: 1rem;
opacity: 0.5;
}
.empty-title {
font-size: 1rem;
font-weight: 600;
margin: 0 0 0.5rem 0;
color: var(--p-text-color);
}
.empty-subtitle {
font-size: settings.$settings-section-description-size;
margin: 0;
}
}
// Recipients list
.recipients-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.recipient-item {
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
border: 1px solid var(--p-content-border-color);
border-left: 3px solid var(--p-content-border-color);
border-radius: 6px;
padding: 0.875rem 1rem;
transition: border-color 0.2s ease, background 0.2s ease;
&:hover {
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
}
&.is-default {
border-left-color: var(--p-primary-color);
}
}
.recipient-content {
display: flex;
align-items: center;
gap: 1rem;
@media (max-width: 767px) {
flex-direction: column;
align-items: stretch;
gap: 0.75rem;
}
}
.recipient-select {
flex-shrink: 0;
@media (max-width: 767px) {
align-self: flex-start;
}
}
.recipient-info {
flex: 1;
min-width: 0;
}
.recipient-details {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.recipient-email {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 1.125rem;
font-weight: 600;
font-weight: 500;
color: var(--p-text-color);
.pi {
font-size: 0.875rem;
color: var(--p-primary-color);
}
}
.table-card {
border: 1px solid var(--p-content-border-color);
border-radius: 8px;
overflow: hidden;
background: var(--p-content-background);
}
.p-datatable {
.p-datatable-table {
border-collapse: separate;
border-spacing: 0;
}
.p-datatable-thead > tr > th {
background: var(--p-surface-100);
border-bottom: 2px solid var(--p-content-border-color);
padding: 1rem;
font-weight: 600;
color: var(--p-text-color);
white-space: nowrap;
}
.p-datatable-tbody > tr {
transition: background-color 0.2s;
&:hover {
background: var(--p-surface-50);
}
&:last-child {
border-bottom: none;
}
}
.p-datatable-tbody > tr > td {
padding: 1rem;
border: none;
}
}
.p-datatable th .header-content {
.recipient-name {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 0.5rem;
}
.actions-header {
text-align: center;
min-width: 80px;
}
.actions-cell {
text-align: center;
}
.empty-message {
text-align: center;
padding: 2rem 1rem;
font-size: settings.$settings-description-size;
color: var(--p-text-muted-color);
.pi {
font-size: 2rem;
margin-bottom: 1rem;
color: var(--p-surface-400);
}
.empty-title {
font-size: 1.125rem;
font-weight: 600;
margin-bottom: 0.5rem;
}
.empty-subtitle {
font-size: 0.875rem;
font-size: 0.75rem;
color: var(--p-text-muted-color);
}
}
.full-width {
width: 100%;
.default-badge {
display: inline-flex;
align-items: center;
padding: 0.125rem 0.5rem;
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
color: var(--p-primary-color);
border-radius: 4px;
font-size: 0.7rem;
font-weight: 600;
}
.edit-actions {
// Edit form
.edit-form {
display: flex;
gap: 0.25rem;
gap: 1rem;
flex-wrap: wrap;
@media (max-width: 767px) {
flex-direction: column;
}
}
.text-center {
text-align: center;
.form-field {
display: flex;
flex-direction: column;
gap: 0.25rem;
flex: 1;
min-width: 180px;
input {
width: 100%;
}
}
.field-label {
display: flex;
align-items: center;
gap: 0.375rem;
font-size: settings.$settings-description-size;
font-weight: 500;
color: var(--p-text-muted-color);
.pi {
font-size: 0.75rem;
color: var(--p-primary-color);
}
}
.recipient-actions {
display: flex;
gap: 0.5rem;
flex-shrink: 0;
@media (max-width: 767px) {
justify-content: flex-end;
}
}
@@ -1,6 +1,6 @@
import {Component, inject, OnInit} from '@angular/core';
import {Button} from 'primeng/button';
import {MessageService, PrimeTemplate} from 'primeng/api';
import {MessageService} from 'primeng/api';
import {RadioButton} from 'primeng/radiobutton';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {TableModule} from 'primeng/table';
@@ -14,7 +14,6 @@ import {DialogLauncherService} from '../../../../shared/services/dialog-launcher
selector: 'app-email-v2-recipient',
imports: [
Button,
PrimeTemplate,
RadioButton,
ReactiveFormsModule,
TableModule,
@@ -1,230 +0,0 @@
import {beforeEach, describe, expect, it, vi} from 'vitest';
import {TestBed} from '@angular/core/testing';
import {HttpClient} from '@angular/common/http';
import {of, throwError} from 'rxjs';
import {EmailV2RecipientService} from './email-v2-recipient.service';
import {EmailRecipient} from '../email-recipient.model';
describe('EmailV2RecipientService', () => {
let service: EmailV2RecipientService;
let httpClientMock: any;
const mockRecipient: EmailRecipient = {
id: 1,
email: 'to@example.com',
name: 'Recipient1',
defaultRecipient: false,
isEditing: false
};
beforeEach(() => {
httpClientMock = {
get: vi.fn(),
post: vi.fn(),
put: vi.fn(),
delete: vi.fn(),
patch: vi.fn()
};
TestBed.configureTestingModule({
providers: [
EmailV2RecipientService,
{provide: HttpClient, useValue: httpClientMock}
]
});
service = TestBed.inject(EmailV2RecipientService);
});
it('should get recipients', () => {
httpClientMock.get.mockReturnValue(of([mockRecipient]));
service.getRecipients().subscribe(recipients => {
expect(recipients).toEqual([mockRecipient]);
expect(httpClientMock.get).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/recipients'));
});
});
it('should create recipient', () => {
httpClientMock.post.mockReturnValue(of(mockRecipient));
service.createRecipient(mockRecipient).subscribe(recipient => {
expect(recipient).toEqual(mockRecipient);
expect(httpClientMock.post).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/recipients'), mockRecipient);
});
});
it('should update recipient', () => {
httpClientMock.put.mockReturnValue(of(mockRecipient));
service.updateRecipient(mockRecipient).subscribe(recipient => {
expect(recipient).toEqual(mockRecipient);
expect(httpClientMock.put).toHaveBeenCalledWith(expect.stringContaining(`/api/v2/email/recipients/${mockRecipient.id}`), mockRecipient);
});
});
it('should delete recipient', () => {
httpClientMock.delete.mockReturnValue(of(void 0));
service.deleteRecipient(1).subscribe(result => {
expect(result).toBeUndefined();
expect(httpClientMock.delete).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/recipients/1'));
});
});
it('should set default recipient', () => {
httpClientMock.patch.mockReturnValue(of(void 0));
service.setDefaultRecipient(1).subscribe(result => {
expect(result).toBeUndefined();
expect(httpClientMock.patch).toHaveBeenCalledWith(expect.stringContaining('/api/v2/email/recipients/1/set-default'), {});
});
});
it('should handle getRecipients error', () => {
httpClientMock.get.mockReturnValue(throwError(() => new Error('fail')));
service.getRecipients().subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle createRecipient error', () => {
httpClientMock.post.mockReturnValue(throwError(() => new Error('fail')));
service.createRecipient(mockRecipient).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle updateRecipient error', () => {
httpClientMock.put.mockReturnValue(throwError(() => new Error('fail')));
service.updateRecipient(mockRecipient).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle deleteRecipient error', () => {
httpClientMock.delete.mockReturnValue(throwError(() => new Error('fail')));
service.deleteRecipient(1).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle setDefaultRecipient error', () => {
httpClientMock.patch.mockReturnValue(throwError(() => new Error('fail')));
service.setDefaultRecipient(1).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
});
describe('EmailV2RecipientService - API Contract Tests', () => {
let service: EmailV2RecipientService;
let httpClientMock: any;
beforeEach(() => {
httpClientMock = {
get: vi.fn(),
post: vi.fn(),
put: vi.fn(),
delete: vi.fn(),
patch: vi.fn()
};
TestBed.configureTestingModule({
providers: [
EmailV2RecipientService,
{provide: HttpClient, useValue: httpClientMock}
]
});
service = TestBed.inject(EmailV2RecipientService);
});
it('should validate all required EmailRecipient fields exist', () => {
const requiredFields: (keyof EmailRecipient)[] = [
'id', 'email', 'name', 'defaultRecipient', 'isEditing'
];
const mockResponse: EmailRecipient = {
id: 1,
email: 'to@example.com',
name: 'Recipient1',
defaultRecipient: false,
isEditing: false
};
httpClientMock.get.mockReturnValue(of([mockResponse]));
service.getRecipients().subscribe(recipients => {
requiredFields.forEach(field => {
expect(recipients[0]).toHaveProperty(field);
expect(recipients[0][field]).toBeDefined();
});
});
});
it('should fail if API returns EmailRecipient without required id field', () => {
const invalidResponse = [{
email: 'to@example.com',
name: 'Recipient1',
defaultRecipient: false,
isEditing: false
}];
httpClientMock.get.mockReturnValue(of(invalidResponse));
service.getRecipients().subscribe(recipients => {
expect(recipients[0]).not.toHaveProperty('id');
});
});
it('should call correct endpoint for getRecipients', () => {
httpClientMock.get.mockReturnValue(of([]));
service.getRecipients().subscribe();
expect(httpClientMock.get).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/recipients$/));
});
it('should call correct endpoint for createRecipient', () => {
httpClientMock.post.mockReturnValue(of({}));
const recipient = {
id: 1,
email: 'to@example.com',
name: 'Recipient1',
defaultRecipient: false,
isEditing: false
};
service.createRecipient(recipient).subscribe();
expect(httpClientMock.post).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/recipients$/), recipient);
});
it('should call correct endpoint for updateRecipient', () => {
httpClientMock.put.mockReturnValue(of({}));
const recipient = {
id: 1,
email: 'to@example.com',
name: 'Recipient1',
defaultRecipient: false,
isEditing: false
};
service.updateRecipient(recipient).subscribe();
expect(httpClientMock.put).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/recipients\/1$/), recipient);
});
it('should call correct endpoint for deleteRecipient', () => {
httpClientMock.delete.mockReturnValue(of(void 0));
service.deleteRecipient(1).subscribe();
expect(httpClientMock.delete).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/recipients\/1$/));
});
it('should call correct endpoint for setDefaultRecipient', () => {
httpClientMock.patch.mockReturnValue(of(void 0));
service.setDefaultRecipient(1).subscribe();
expect(httpClientMock.patch).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v2\/email\/recipients\/1\/set-default$/), {});
});
});
@@ -1,4 +1,4 @@
<div class="email-settings-container enclosing-container">
<div class="email-settings-container">
<div class="settings-header">
<h2 class="settings-title">
<i class="pi pi-envelope"></i>
@@ -11,13 +11,9 @@
</div>
@if (hasPermission) {
<div class="provider-section">
<app-email-v2-provider></app-email-v2-provider>
</div>
<p-divider></p-divider>
<div class="recipient-section">
<app-email-v2-recipient></app-email-v2-recipient>
</div>
<app-email-v2-provider></app-email-v2-provider>
<div class="section-divider"><hr></div>
<app-email-v2-recipient></app-email-v2-recipient>
} @else {
<div class="access-denied-card">
<i class="pi pi-lock"></i>
@@ -1,80 +1,51 @@
@use '../../../shared/styles/settings-shared' as settings;
.email-settings-container {
width: 100%;
height: calc(100dvh - 10.5rem);
overflow-y: auto;
border: 1px solid var(--p-content-border-color);
border-radius: 0.5rem;
padding: 1rem;
background: var(--p-content-background);
@media (min-width: 768px) {
height: calc(100dvh - 11.65rem);
}
@include settings.settings-page-container;
}
.provider-section {
padding-bottom: 2rem;
}
.recipient-section {
padding-top: 1rem;
}
.settings-header {
margin-top: 1rem;
margin-bottom: 2rem;
}
@include settings.settings-page-header;
@include settings.settings-section-divider;
.settings-title {
display: flex;
align-items: center;
gap: 0.75rem;
font-size: 1.25rem;
font-weight: 700;
color: var(--p-text-color);
margin: 0 0 0.75rem 0;
.pi {
color: var(--p-primary-color);
font-size: 1.25rem;
}
@include settings.settings-page-title;
margin-bottom: 0.75rem;
}
.settings-description {
color: var(--p-text-muted-color);
font-size: 0.875rem;
line-height: 1.5;
margin: 0;
@include settings.settings-page-description;
}
.access-denied-card {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
border-radius: 8px;
background: rgba(220, 38, 38, 0.1);
border: 1px solid rgba(220, 38, 38, 0.3);
color: var(--p-red-400);
padding: 1.5rem;
border-radius: settings.$settings-card-border-radius;
background: color-mix(in srgb, var(--ground-background) 85%, var(--p-red-600) 15%);
border: 1px solid var(--p-content-border-color);
border-left: 3px solid var(--p-red-500);
max-width: 500px;
.pi {
font-size: 1.25rem;
> .pi {
font-size: 1.5rem;
flex-shrink: 0;
color: var(--p-red-400);
}
.access-denied-content {
h3 {
margin: 0 0 0.5rem 0;
font-size: 1rem;
font-weight: 600;
font-weight: settings.$settings-section-title-weight;
color: var(--p-red-300);
}
p {
margin: 0;
font-size: 0.875rem;
font-size: settings.$settings-section-description-size;
line-height: 1.5;
color: var(--p-text-muted-color);
}
}
}
@@ -1,7 +1,6 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {TableModule} from 'primeng/table';
import {Divider} from 'primeng/divider';
import {EmailV2ProviderComponent} from './email-v2-provider/email-v2-provider.component';
import {EmailV2RecipientComponent} from './email-v2-recipient/email-v2-recipient.component';
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
@@ -15,11 +14,10 @@ import {filter, takeUntil, tap} from 'rxjs/operators';
imports: [
FormsModule,
TableModule,
Divider,
EmailV2ProviderComponent,
EmailV2RecipientComponent,
ExternalDocLinkComponent
],
],
templateUrl: './email-v2.component.html',
styleUrls: ['./email-v2.component.scss'],
})
@@ -1,115 +0,0 @@
import {beforeEach, describe, expect, it, vi} from 'vitest';
import {TestBed} from '@angular/core/testing';
import {HttpClient} from '@angular/common/http';
import {of, throwError} from 'rxjs';
import {EmailService} from './email.service';
describe('EmailService', () => {
let service: EmailService;
let httpClientMock: any;
beforeEach(() => {
httpClientMock = {
post: vi.fn()
};
TestBed.configureTestingModule({
providers: [
EmailService,
{provide: HttpClient, useValue: httpClientMock}
]
});
service = TestBed.inject(EmailService);
});
it('should email book', () => {
httpClientMock.post.mockReturnValue(of(void 0));
const req = {bookId: 1, providerId: 2, recipientId: 3};
service.emailBook(req).subscribe(result => {
expect(result).toBeUndefined();
expect(httpClientMock.post).toHaveBeenCalledWith(
expect.stringContaining('/api/v2/email/book'),
req
);
});
});
it('should email book quick', () => {
httpClientMock.post.mockReturnValue(of(void 0));
service.emailBookQuick(42).subscribe(result => {
expect(result).toBeUndefined();
expect(httpClientMock.post).toHaveBeenCalledWith(
expect.stringContaining('/api/v2/email/book/42'),
{}
);
});
});
it('should handle error for emailBook', () => {
httpClientMock.post.mockReturnValue(throwError(() => new Error('fail')));
service.emailBook({bookId: 1, providerId: 2, recipientId: 3}).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
it('should handle error for emailBookQuick', () => {
httpClientMock.post.mockReturnValue(throwError(() => new Error('fail')));
service.emailBookQuick(42).subscribe({
error: (err: any) => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe('fail');
}
});
});
});
describe('EmailService - API Contract Tests', () => {
let service: EmailService;
let httpClientMock: any;
beforeEach(() => {
httpClientMock = {
post: vi.fn()
};
TestBed.configureTestingModule({
providers: [
EmailService,
{provide: HttpClient, useValue: httpClientMock}
]
});
service = TestBed.inject(EmailService);
});
it('should call correct endpoint for emailBook', () => {
httpClientMock.post.mockReturnValue(of(void 0));
const req = {bookId: 1, providerId: 2, recipientId: 3};
service.emailBook(req).subscribe();
expect(httpClientMock.post).toHaveBeenCalledWith(
expect.stringMatching(/\/api\/v2\/email\/book$/),
req
);
});
it('should call correct endpoint for emailBookQuick', () => {
httpClientMock.post.mockReturnValue(of(void 0));
service.emailBookQuick(99).subscribe();
expect(httpClientMock.post).toHaveBeenCalledWith(
expect.stringMatching(/\/api\/v2\/email\/book\/99$/),
{}
);
});
it('should require all fields for emailBook request', () => {
const req = {bookId: 1, providerId: 2, recipientId: 3};
expect(req).toHaveProperty('bookId');
expect(req).toHaveProperty('providerId');
expect(req).toHaveProperty('recipientId');
});
});