From 409060abb43f6374c747e86ffe88811062a7fbc0 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 5 Jun 2026 22:57:13 -0700 Subject: [PATCH] Coverage, remove 0 check --- .../admin/tasks/tasks.component.spec.ts | 31 +++++++++++++++++-- .../components/admin/tasks/tasks.component.ts | 4 --- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts index 7a0034ea1..a87ec49b0 100644 --- a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts +++ b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts @@ -11,7 +11,7 @@ import { Router } from '@angular/router' import { RouterTestingModule } from '@angular/router/testing' import { NgbModal, NgbModalRef, NgbModule } from '@ng-bootstrap/ng-bootstrap' import { allIcons, NgxBootstrapIconsModule } from 'ngx-bootstrap-icons' -import { throwError } from 'rxjs' +import { of, throwError } from 'rxjs' import { routes } from 'src/app/app-routing.module' import { PaperlessTask, @@ -499,7 +499,12 @@ describe('TasksComponent', () => { it('should support dismiss all tasks', () => { let modal: NgbModalRef modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1])) - const dismissSpy = jest.spyOn(tasksService, 'dismissAllTasks') + const dismissSpy = jest + .spyOn(tasksService, 'dismissAllTasks') + .mockReturnValue(of({})) + const reloadPageSpy = jest + .spyOn(component as any, 'reloadPage') + .mockImplementation(() => undefined) component.dismissAllTasks() @@ -507,6 +512,28 @@ describe('TasksComponent', () => { expect(modal.componentInstance.messageBold).toBe('Dismiss all 7 tasks?') modal.componentInstance.confirmClicked.emit() expect(dismissSpy).toHaveBeenCalled() + expect(reloadPageSpy).toHaveBeenCalledWith(false) + expect(component.selectedTasks.size).toBe(0) + }) + + it('should show an error and re-enable modal buttons when dismissing all tasks fails', () => { + const error = new Error('dismiss all failed') + const toastSpy = jest.spyOn(toastService, 'showError') + const dismissSpy = jest + .spyOn(tasksService, 'dismissAllTasks') + .mockReturnValue(throwError(() => error)) + + let modal: NgbModalRef + modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1])) + + component.dismissAllTasks() + expect(modal).not.toBeUndefined() + + modal.componentInstance.confirmClicked.emit() + + expect(dismissSpy).toHaveBeenCalled() + expect(toastSpy).toHaveBeenCalledWith('Error dismissing tasks', error) + expect(modal.componentInstance.buttonsEnabled).toBe(true) }) it('should dismiss the currently visible scoped and filtered tasks', () => { diff --git a/src-ui/src/app/components/admin/tasks/tasks.component.ts b/src-ui/src/app/components/admin/tasks/tasks.component.ts index 4aff56c6d..ed72a401d 100644 --- a/src-ui/src/app/components/admin/tasks/tasks.component.ts +++ b/src-ui/src/app/components/admin/tasks/tasks.component.ts @@ -335,10 +335,6 @@ export class TasksComponent } dismissAllTasks() { - if (this.totalTasks === 0) { - return - } - let modal = this.modalService.open(ConfirmDialogComponent, { backdrop: 'static', })