feat(kobo): show full Kobo API path in sync settings (#2381)

Co-authored-by: Dave Machado <15134885+davemachado@users.noreply.github.com>
This commit is contained in:
Dave Machado
2026-08-23 12:27:28 +01:00
committed by GitHub
co-authored by Dave Machado
parent 9f6754fe0b
commit 852da004a0
4 changed files with 117 additions and 0 deletions
@@ -121,6 +121,37 @@
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<span class="setting-label">{{ t('kobo.apiPath') }}</span>
<div class="token-input-group">
<input
pInputText
id="koboApiPath"
[value]="koboApiPath"
[type]="showToken ? 'text' : 'password'"
aria-label="{{ t('kobo.apiPath') }}"
readonly
class="token-input"
/>
<p-button
icon="pi pi-copy"
outlined="true"
severity="info"
size="small"
[ariaLabel]="t('kobo.apiPath')"
(onClick)="copyText(koboApiPath, t('kobo.apiPath'))"
[disabled]="!koboApiPath">
</p-button>
</div>
</div>
<p class="setting-description">
{{ t('kobo.apiPathDesc') }}
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
@@ -12,6 +12,7 @@ import {UserService, type User} from '../../../user-management/user.service';
import {KoboService, type KoboSyncSettings} from './kobo.service';
import {KoboSyncSettingsComponent} from './kobo-sync-settings-component';
import {AppSettingsService} from '../../../../../shared/service/app-settings.service';
import {ConfirmationService, MessageService} from '@openng/optimus-ui/api';
const DEFAULT_KOBO_SYNC_SETTINGS: KoboSyncSettings = {
token: '',
@@ -243,6 +244,83 @@ describe('KoboSyncSettingsComponent', () => {
});
expect(fixture.nativeElement.querySelector('input#koboToken')).not.toBeNull();
const apiPathInput = fixture.nativeElement.querySelector('input#koboApiPath') as HTMLInputElement | null;
expect(apiPathInput).not.toBeNull();
expect(apiPathInput?.value).toBe(`${window.location.origin}/api/kobo/token-123`);
fixture.destroy();
});
it('recomputes the API path when the token is regenerated', () => {
const userState = signal<User | null>(buildUser({canSyncKobo: true}));
const appSettingsState = signal<AppSettings | null>(null);
const initialSettings: KoboSyncSettings = {
...DEFAULT_KOBO_SYNC_SETTINGS,
token: 'old-token',
syncEnabled: true,
};
TestBed.configureTestingModule({
imports: [KoboSyncSettingsComponent],
providers: [
{provide: UserService, useValue: {currentUser: () => userState()}},
{provide: AppSettingsService, useValue: {appSettings: () => appSettingsState()}},
{
provide: KoboService,
useValue: {
getUser: () => of(initialSettings),
updateSettings: (s: KoboSyncSettings) => of(s),
createOrUpdateToken: () => of({...initialSettings, token: 'new-token'}),
},
},
{provide: SettingsHelperService, useValue: {saveSetting: vi.fn()}},
{provide: ShelfService, useValue: {reloadShelves: vi.fn()}},
{provide: TranslocoService, useValue: {translate: vi.fn((key: string) => key)}},
],
});
// Auto-accept the confirmation dialog and stub the toast so no template is needed.
// The rendered [value]="koboApiPath" binding is covered by the hydration test above;
// here we assert the recompute at the component-state level after regeneration.
TestBed.overrideComponent(KoboSyncSettingsComponent, {
set: {
template: '',
providers: [
{provide: ConfirmationService, useValue: {confirm: (o: {accept?: () => void}) => o.accept?.()}},
{provide: MessageService, useValue: {add: vi.fn()}},
],
},
});
const fixture = TestBed.createComponent(KoboSyncSettingsComponent);
const component = fixture.componentInstance;
TestBed.flushEffects();
expect(component.koboApiPath).toBe(`${window.location.origin}/api/kobo/old-token`);
component.confirmRegenerateToken();
expect(component.syncForm.controls.token.value).toBe('new-token');
expect(component.koboApiPath).toBe(`${window.location.origin}/api/kobo/new-token`);
fixture.destroy();
});
it('builds the full Kobo API path from the token and is empty without one', () => {
const userState = signal<User | null>(buildUser({canSyncKobo: true}));
const appSettingsState = signal<AppSettings | null>(null);
setupKoboTest({userState, appSettingsState, getUser: () => of(DEFAULT_KOBO_SYNC_SETTINGS)});
const fixture = TestBed.createComponent(KoboSyncSettingsComponent);
const component = fixture.componentInstance;
TestBed.flushEffects();
expect(component.koboApiPath).toBe('');
component.syncForm.controls.token.setValue('token-xyz');
expect(component.koboApiPath).toBe(`${window.location.origin}/api/kobo/token-xyz`);
fixture.destroy();
});
});
@@ -47,6 +47,12 @@ export class KoboSyncSettingsComponent implements OnInit {
isAdmin = false;
credentialsSaved = false;
showToken = false;
readonly koboApiBase = `${window.location.origin}/api/kobo`;
get koboApiPath(): string {
const token = this.syncForm.controls.token.value;
return token ? `${this.koboApiBase}/${token}` : '';
}
readonly syncForm = this.fb.nonNullable.group({
token: [''],
@@ -49,6 +49,8 @@
"autoAddDesc": "When enabled, newly added books will be automatically added to your Kobo shelf for syncing. This eliminates the need to manually add each book to the shelf.",
"token": "Kobo Sync Token",
"tokenDesc": "Your unique sync token for authenticating with your Kobo device. Keep this secure.",
"apiPath": "Kobo API Path",
"apiPathDesc": "The full Kobo sync URL for your device. Use this as the API endpoint when configuring your Kobo.",
"tokenManagement": "Token Management",
"regenerateToken": "Regenerate Token",
"tokenManagementDesc": "Regenerate your sync token if needed. This will invalidate the current token.",