refactor(ui): move large library processing screen to notifications (#1428)

Co-authored-by: Alex <25013571+alexhb1@users.noreply.github.com>
This commit is contained in:
brios
2026-05-22 15:57:07 +01:00
committed by GitHub
co-authored by Alex
parent 0e76b381aa
commit dbbc7c3878
20 changed files with 334 additions and 427 deletions
+12 -40
View File
@@ -13,18 +13,19 @@ import { AppConfigService } from "./shared/service/app-config.service";
import { MetadataProgressService } from "./shared/service/metadata-progress.service";
import { BookdropFileService } from "./features/bookdrop/service/bookdrop-file.service";
import { TaskService } from "./features/settings/task-management/task.service";
import { LibraryService } from "./features/book/service/library.service";
import { LibraryHealthService } from "./features/book/service/library-health.service";
import { LibraryLoadingService } from "./features/library-creator/library-loading.service";
import { AuthService } from "./shared/service/auth.service";
import { ConfirmationService } from "primeng/api";
import { MessageService } from "primeng/api";
import { CommandPaletteService } from "./features/command-palette/command-palette.service";
import { LibraryImportProgressService } from "./shared/service/library-import-progress.service";
interface StompMessage {
body: string;
}
const DEFAULT_AUTH = { ready: true, authenticated: true };
describe("AppComponent", () => {
let fixture: ComponentFixture<AppComponent>;
let component: AppComponent;
@@ -46,15 +47,8 @@ describe("AppComponent", () => {
let bookdropFileService: { handleIncomingFile: ReturnType<typeof vi.fn> };
let taskService: { handleTaskProgress: ReturnType<typeof vi.fn> };
let libraryHealthService: { initWebsocket: ReturnType<typeof vi.fn>, fetchHealth: ReturnType<typeof vi.fn> };
let libraryLoadingService: {
showBookLoadingProgress: ReturnType<typeof vi.fn>;
hide: ReturnType<typeof vi.fn>;
};
let authService: { forceLogout: ReturnType<typeof vi.fn>, isAuthenticated: ReturnType<typeof signal> };
let libraryService: {
largeLibraryLoading: ReturnType<typeof signal>;
setLargeLibraryLoading: ReturnType<typeof vi.fn>;
};
let libraryImportProgressService: { recordBookAdded: ReturnType<typeof vi.fn> };
let commandPaletteService: {
toggle: ReturnType<typeof vi.fn>;
open: ReturnType<typeof vi.fn>;
@@ -73,8 +67,7 @@ describe("AppComponent", () => {
}
function configureComponent(
auth = { ready: true, authenticated: true },
largeLibraryLoading = { isLoading: false, expectedCount: 0 },
auth = DEFAULT_AUTH
): void {
topics = new Map();
rxStompService = {
@@ -94,15 +87,8 @@ describe("AppComponent", () => {
bookdropFileService = { handleIncomingFile: vi.fn() };
taskService = { handleTaskProgress: vi.fn() };
libraryHealthService = { initWebsocket: vi.fn(), fetchHealth: vi.fn() };
libraryLoadingService = {
showBookLoadingProgress: vi.fn(),
hide: vi.fn(),
};
authService = { forceLogout: vi.fn(), isAuthenticated: signal(auth.authenticated) };
libraryService = {
largeLibraryLoading: signal(largeLibraryLoading),
setLargeLibraryLoading: vi.fn(),
};
libraryImportProgressService = { recordBookAdded: vi.fn() };
commandPaletteService = {
toggle: vi.fn(),
open: vi.fn(),
@@ -131,10 +117,9 @@ describe("AppComponent", () => {
{ provide: MetadataProgressService, useValue: metadataProgressService },
{ provide: BookdropFileService, useValue: bookdropFileService },
{ provide: TaskService, useValue: taskService },
{ provide: LibraryService, useValue: libraryService },
{ provide: LibraryHealthService, useValue: libraryHealthService },
{ provide: LibraryLoadingService, useValue: libraryLoadingService },
{ provide: AuthService, useValue: authService },
{ provide: LibraryImportProgressService, useValue: libraryImportProgressService },
{ provide: CommandPaletteService, useValue: commandPaletteService },
ConfirmationService,
MessageService],
@@ -175,27 +160,15 @@ describe("AppComponent", () => {
expect(libraryHealthService.fetchHealth).not.toHaveBeenCalled();
});
it("routes websocket book notifications through the large library loading branch", () => {
configureComponent({ ready: true, authenticated: true }, { isLoading: true, expectedCount: 2 });
it("routes websocket book notifications to bookService", () => {
configureComponent();
topics
.get("/user/queue/book-add")
?.next({ body: JSON.stringify({ metadata: { title: "First" } }) });
topics
.get("/user/queue/book-add")
?.next({ body: JSON.stringify({ metadata: { title: "Second" } }) });
expect(bookService.handleNewlyCreatedBook).toHaveBeenCalledTimes(2);
expect(
libraryLoadingService.showBookLoadingProgress,
).toHaveBeenNthCalledWith(1, "First", 1, 2);
expect(
libraryLoadingService.showBookLoadingProgress,
).toHaveBeenNthCalledWith(2, "Second", 2, 2);
expect(libraryService.setLargeLibraryLoading).toHaveBeenCalledWith(
false,
0,
);
expect(bookService.handleNewlyCreatedBook).toHaveBeenCalledWith({ metadata: { title: "First" } });
expect(libraryImportProgressService.recordBookAdded).toHaveBeenCalledWith("First");
});
it("forwards websocket updates to the matching root services", () => {
@@ -261,12 +234,11 @@ describe("AppComponent", () => {
expect(authService.forceLogout).toHaveBeenCalledWith("session_revoked");
});
it("unsubscribes and hides the loading overlay when destroyed", () => {
it("unsubscribes when destroyed", () => {
configureComponent();
component.ngOnDestroy();
expect(libraryLoadingService.hide).toHaveBeenCalledOnce();
topics
.get("/user/queue/book-update")
?.next({ body: JSON.stringify({ id: 99 }) });