fix(metadata): hide sidecar tab when sidecar json is disabled (#814)
This commit is contained in:
+2
-2
@@ -37,7 +37,7 @@
|
|||||||
{{ t('tabSearch') }}
|
{{ t('tabSearch') }}
|
||||||
</p-tab>
|
</p-tab>
|
||||||
}
|
}
|
||||||
@if ((admin || canEditMetadata) && !isPhysical && isLocalStorage) {
|
@if (canShowSidecarTab) {
|
||||||
<p-tab value="sidecar">
|
<p-tab value="sidecar">
|
||||||
<i [class]="'pi pi-file'"></i>
|
<i [class]="'pi pi-file'"></i>
|
||||||
{{ t('tabSidecar') }}
|
{{ t('tabSidecar') }}
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
<app-metadata-searcher [book]="book()" [isActiveTab]="tab === 'match'"></app-metadata-searcher>
|
<app-metadata-searcher [book]="book()" [isActiveTab]="tab === 'match'"></app-metadata-searcher>
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
@if ((admin || canEditMetadata) && !isPhysical && isLocalStorage) {
|
@if (canShowSidecarTab) {
|
||||||
<p-tabpanel value="sidecar">
|
<p-tabpanel value="sidecar">
|
||||||
<app-sidecar-viewer [book]="book()"></app-sidecar-viewer>
|
<app-sidecar-viewer [book]="book()"></app-sidecar-viewer>
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
|
|||||||
+78
-6
@@ -1,9 +1,81 @@
|
|||||||
import {describe, expect, it} from 'vitest';
|
import {signal, type WritableSignal} from '@angular/core';
|
||||||
|
import {TestBed} from '@angular/core/testing';
|
||||||
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
|
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
||||||
|
|
||||||
// TODO(seam): This surface combines routed params, dynamic-dialog inputs, TanStack query
|
import {createQueryClientHarness} from '../../../../core/testing/query-testing';
|
||||||
// state, and metadata-host book switching, so it needs a routed integration harness.
|
import {AppSettings, type MetadataPersistenceSettings} from '../../../../shared/model/app-settings.model';
|
||||||
describe.skip('BookMetadataCenterComponent', () => {
|
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||||
it('needs a routed dialog harness for tab sync, book switching, and recommendation loading', () => {
|
import {BookMetadataHostService} from '../../../../shared/service/book-metadata-host.service';
|
||||||
expect.hasAssertions();
|
import {BookService} from '../../../book/service/book.service';
|
||||||
|
import {UserService} from '../../../settings/user-management/user.service';
|
||||||
|
import {BookMetadataCenterComponent} from './book-metadata-center.component';
|
||||||
|
|
||||||
|
describe('BookMetadataCenterComponent', () => {
|
||||||
|
let appSettingsSignal: WritableSignal<AppSettings | null>;
|
||||||
|
let currentUserSignal: WritableSignal<{permissions?: {admin?: boolean; canEditMetadata?: boolean}} | null>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const queryClientHarness = createQueryClientHarness();
|
||||||
|
|
||||||
|
appSettingsSignal = signal<AppSettings | null>(null);
|
||||||
|
currentUserSignal = signal({permissions: {admin: true, canEditMetadata: true}});
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
...queryClientHarness.providers,
|
||||||
|
{provide: ActivatedRoute, useValue: {}},
|
||||||
|
{provide: Router, useValue: {navigate: vi.fn()}},
|
||||||
|
{provide: BookService, useValue: {}},
|
||||||
|
{provide: UserService, useValue: {currentUser: currentUserSignal}},
|
||||||
|
{provide: AppSettingsService, useValue: {appSettings: appSettingsSignal}},
|
||||||
|
{provide: BookMetadataHostService, useValue: {}},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the sidecar tab only when sidecar JSON is enabled', () => {
|
||||||
|
const component = TestBed.runInInjectionContext(() => new BookMetadataCenterComponent());
|
||||||
|
TestBed.flushEffects();
|
||||||
|
|
||||||
|
expect(component.canShowSidecarTab).toBe(false);
|
||||||
|
|
||||||
|
appSettingsSignal.set(buildSettings({sidecarEnabled: true}));
|
||||||
|
|
||||||
|
expect(component.canShowSidecarTab).toBe(true);
|
||||||
|
|
||||||
|
appSettingsSignal.set(buildSettings({sidecarEnabled: false}));
|
||||||
|
|
||||||
|
expect(component.canShowSidecarTab).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function buildSettings({
|
||||||
|
diskType = 'LOCAL',
|
||||||
|
sidecarEnabled,
|
||||||
|
}: {
|
||||||
|
diskType?: AppSettings['diskType'];
|
||||||
|
sidecarEnabled: boolean;
|
||||||
|
}): AppSettings {
|
||||||
|
const metadataPersistenceSettings: MetadataPersistenceSettings = {
|
||||||
|
moveFilesToLibraryPattern: false,
|
||||||
|
convertCbrCb7ToCbz: false,
|
||||||
|
saveToOriginalFile: {
|
||||||
|
epub: {enabled: false, maxFileSizeInMb: 250},
|
||||||
|
pdf: {enabled: false, maxFileSizeInMb: 250},
|
||||||
|
cbx: {enabled: false, maxFileSizeInMb: 250},
|
||||||
|
audiobook: {enabled: false, maxFileSizeInMb: 1000},
|
||||||
|
},
|
||||||
|
sidecarSettings: {
|
||||||
|
enabled: sidecarEnabled,
|
||||||
|
writeOnUpdate: false,
|
||||||
|
writeOnScan: false,
|
||||||
|
includeCoverFile: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
diskType,
|
||||||
|
metadataPersistenceSettings,
|
||||||
|
} as AppSettings;
|
||||||
|
}
|
||||||
|
|||||||
+5
@@ -86,7 +86,12 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
get isPhysical(): boolean { return this.book()?.isPhysical ?? false; }
|
get isPhysical(): boolean { return this.book()?.isPhysical ?? false; }
|
||||||
isLocalStorage: boolean = true;
|
isLocalStorage: boolean = true;
|
||||||
|
get canShowSidecarTab(): boolean {
|
||||||
|
const settings = this.appSettingsService.appSettings();
|
||||||
|
const sidecarEnabled = settings?.metadataPersistenceSettings?.sidecarSettings?.enabled ?? false;
|
||||||
|
|
||||||
|
return (this.admin || this.canEditMetadata) && !this.isPhysical && this.isLocalStorage && sidecarEnabled;
|
||||||
|
}
|
||||||
private validTabs = ['view', 'edit', 'match', 'sidecar'];
|
private validTabs = ['view', 'edit', 'match', 'sidecar'];
|
||||||
|
|
||||||
get tab(): string {
|
get tab(): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user