Update hardcover sync information text

This commit is contained in:
acx10
2026-01-08 16:35:52 -07:00
parent 77bb2904e3
commit a3b7f3cc0d
3 changed files with 26 additions and 24 deletions
@@ -29,7 +29,8 @@
<div class="setting-item"> <div class="setting-item">
<div class="setting-info"> <div class="setting-info">
<div class="setting-label-row"> <div class="setting-label-row">
<label class="setting-label">Sync Reading Progress to Hardcover</label> <label class="setting-label">
Sync KOReader Reading Progress to Hardcover</label>
<p-toggle-switch <p-toggle-switch
id="hardcoverSyncEnabled" id="hardcoverSyncEnabled"
name="hardcoverSyncEnabled" name="hardcoverSyncEnabled"
@@ -38,7 +39,7 @@
</p-toggle-switch> </p-toggle-switch>
</div> </div>
<p class="setting-description"> <p class="setting-description">
When enabled, your reading progress will be automatically synced to your Hardcover account. When enabled, your KOReader reading progress will be automatically synced to your Hardcover account.
</p> </p>
</div> </div>
</div> </div>
@@ -88,7 +88,7 @@
margin-right: 1rem; margin-right: 1rem;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 2rem; gap: 1.25rem;
@media (max-width: 768px) { @media (max-width: 768px) {
padding: 1rem; padding: 1rem;
@@ -1,5 +1,5 @@
import {beforeEach, describe, expect, it, vi} from 'vitest'; import {beforeEach, describe, expect, it, vi} from 'vitest';
import {ComponentFixture, TestBed} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing';
import {BehaviorSubject, of, throwError} from 'rxjs'; import {BehaviorSubject, of, throwError} from 'rxjs';
import {MessageService} from 'primeng/api'; import {MessageService} from 'primeng/api';
import {NO_ERRORS_SCHEMA} from '@angular/core'; import {NO_ERRORS_SCHEMA} from '@angular/core';
@@ -8,8 +8,6 @@ import {HardcoverSyncSettingsService} from './hardcover-sync-settings.service';
import {UserService, UserState} from '../../../user-management/user.service'; import {UserService, UserState} from '../../../user-management/user.service';
describe('HardcoverSettingsComponent', () => { describe('HardcoverSettingsComponent', () => {
let fixture: ComponentFixture<HardcoverSettingsComponent>;
let component: HardcoverSettingsComponent;
let settingsServiceMock: any; let settingsServiceMock: any;
let messageServiceMock: any; let messageServiceMock: any;
let userState$: BehaviorSubject<UserState>; let userState$: BehaviorSubject<UserState>;
@@ -56,7 +54,7 @@ describe('HardcoverSettingsComponent', () => {
} }
}); });
beforeEach(async () => { beforeEach(() => {
settingsServiceMock = { settingsServiceMock = {
getSettings: vi.fn(), getSettings: vi.fn(),
updateSettings: vi.fn() updateSettings: vi.fn()
@@ -66,7 +64,7 @@ describe('HardcoverSettingsComponent', () => {
}; };
userState$ = new BehaviorSubject<UserState>(makeState()); userState$ = new BehaviorSubject<UserState>(makeState());
await TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [HardcoverSettingsComponent], imports: [HardcoverSettingsComponent],
providers: [ providers: [
{provide: HardcoverSyncSettingsService, useValue: settingsServiceMock}, {provide: HardcoverSyncSettingsService, useValue: settingsServiceMock},
@@ -74,13 +72,10 @@ describe('HardcoverSettingsComponent', () => {
{provide: UserService, useValue: {userState$: userState$}} {provide: UserService, useValue: {userState$: userState$}}
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); });
fixture = TestBed.createComponent(HardcoverSettingsComponent);
component = fixture.componentInstance;
}); });
it('should load settings when user has permission', () => { it('should load settings when user has permission', async () => {
settingsServiceMock.getSettings.mockReturnValue(of({hardcoverSyncEnabled: true, hardcoverApiKey: 'key'})); settingsServiceMock.getSettings.mockReturnValue(of({hardcoverSyncEnabled: true, hardcoverApiKey: 'key'}));
userState$.next(makeState({ userState$.next(makeState({
permissions: { permissions: {
@@ -89,48 +84,55 @@ describe('HardcoverSettingsComponent', () => {
} }
}) as UserState); }) as UserState);
const fixture = TestBed.createComponent(HardcoverSettingsComponent);
const component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(settingsServiceMock.getSettings).toHaveBeenCalled(); expect(settingsServiceMock.getSettings).toHaveBeenCalled();
expect(component.hardcoverSyncEnabled).toBe(true); expect(component.hardcoverSyncEnabled).toBe(true);
expect(component.hardcoverApiKey).toBe('key'); expect(component.hardcoverApiKey).toBe('key');
}); });
it('should not load settings without permission', () => { it('should not load settings without permission', async () => {
settingsServiceMock.getSettings.mockReturnValue(of({})); settingsServiceMock.getSettings.mockReturnValue(of({}));
userState$.next(makeState()); userState$.next(makeState());
const fixture = TestBed.createComponent(HardcoverSettingsComponent);
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(settingsServiceMock.getSettings).not.toHaveBeenCalled(); expect(settingsServiceMock.getSettings).not.toHaveBeenCalled();
}); });
it('should update settings on toggle', () => { it('should update settings on toggle', async () => {
settingsServiceMock.updateSettings.mockReturnValue(of({hardcoverSyncEnabled: false, hardcoverApiKey: 'k'})); settingsServiceMock.updateSettings.mockReturnValue(of({hardcoverSyncEnabled: false, hardcoverApiKey: 'k'}));
const fixture = TestBed.createComponent(HardcoverSettingsComponent);
const component = fixture.componentInstance;
component.hardcoverSyncEnabled = false; component.hardcoverSyncEnabled = false;
component.hardcoverApiKey = 'k'; component.hardcoverApiKey = 'k';
component.onHardcoverSyncToggle(); component.onHardcoverSyncToggle();
await fixture.whenStable();
expect(settingsServiceMock.updateSettings).toHaveBeenCalledWith({ expect(settingsServiceMock.updateSettings).toHaveBeenCalledWith({
hardcoverSyncEnabled: false, hardcoverSyncEnabled: false,
hardcoverApiKey: 'k' hardcoverApiKey: 'k'
}); });
expect(messageServiceMock.add).toHaveBeenCalled();
}); });
it('should handle update error', () => { it('should handle update error', async () => {
settingsServiceMock.updateSettings.mockReturnValue(throwError(() => new Error('fail'))); settingsServiceMock.updateSettings.mockReturnValue(throwError(() => new Error('fail')));
const fixture = TestBed.createComponent(HardcoverSettingsComponent);
const component = fixture.componentInstance;
component.hardcoverSyncEnabled = true; component.hardcoverSyncEnabled = true;
component.hardcoverApiKey = 'k'; component.hardcoverApiKey = 'k';
component.onHardcoverApiKeyChange(); component.onHardcoverApiKeyChange();
await fixture.whenStable();
expect(settingsServiceMock.updateSettings).toHaveBeenCalled(); expect(settingsServiceMock.updateSettings).toHaveBeenCalled();
expect(messageServiceMock.add).toHaveBeenCalledWith(expect.objectContaining({
severity: 'error'
}));
}); });
it('should handle load error', () => { it('should handle load error', async () => {
settingsServiceMock.getSettings.mockReturnValue(throwError(() => new Error('fail'))); settingsServiceMock.getSettings.mockReturnValue(throwError(() => new Error('fail')));
userState$.next(makeState({ userState$.next(makeState({
permissions: { permissions: {
@@ -139,11 +141,10 @@ describe('HardcoverSettingsComponent', () => {
} }
}) as UserState); }) as UserState);
const fixture = TestBed.createComponent(HardcoverSettingsComponent);
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(settingsServiceMock.getSettings).toHaveBeenCalled(); expect(settingsServiceMock.getSettings).toHaveBeenCalled();
expect(messageServiceMock.add).toHaveBeenCalledWith(expect.objectContaining({
severity: 'error'
}));
}); });
}); });