From 3008d3d3e2179ed9a8db611f45cf5512d648e2fe Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 14 Sep 2026 20:55:35 -0700 Subject: [PATCH] Tests for the frontend wiring --- .../bulk-editor/bulk-editor.component.spec.ts | 10 ++- .../document-list-view.service.spec.ts | 69 ++++++++++++++++++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts index b8696a958a..c3f258c10d 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts @@ -8,7 +8,7 @@ import { EventEmitter, signal } from '@angular/core' import { ComponentFixture, TestBed } from '@angular/core/testing' import { By } from '@angular/platform-browser' import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' -import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' +import { allIcons, NgxBootstrapIconsModule } from 'ngx-bootstrap-icons' import { of, throwError } from 'rxjs' import { Correspondent } from 'src/app/data/correspondent' import { CustomField, CustomFieldDataType } from 'src/app/data/custom-field' @@ -496,16 +496,19 @@ describe('BulkEditorComponent', () => { .mockReturnValue([{ id: 3 }, { id: 4 }]) jest .spyOn(documentListViewService, 'selected', 'get') - .mockReturnValue(new Set([3, 4])) + .mockReturnValue(new Set([3])) jest .spyOn(documentListViewService, 'allSelected', 'get') .mockReturnValue(true) + jest + .spyOn(documentListViewService, 'excluded', 'get') + .mockReturnValue(new Set([4])) jest .spyOn(documentListViewService, 'filterRules', 'get') .mockReturnValue([{ rule_type: FILTER_TITLE, value: 'apple' }]) jest .spyOn(documentListViewService, 'selectedCount', 'get') - .mockReturnValue(25) + .mockReturnValue(24) jest .spyOn(permissionsService, 'currentUserHasObjectPermissions') .mockReturnValue(true) @@ -524,6 +527,7 @@ describe('BulkEditorComponent', () => { expect(req.request.body).toEqual({ all: true, filters: { title_search: 'apple' }, + excluded_documents: [4], method: 'modify_tags', parameters: { add_tags: [101], remove_tags: [] }, }) diff --git a/src-ui/src/app/services/document-list-view.service.spec.ts b/src-ui/src/app/services/document-list-view.service.spec.ts index 9447101ad7..772c851e06 100644 --- a/src-ui/src/app/services/document-list-view.service.spec.ts +++ b/src-ui/src/app/services/document-list-view.service.spec.ts @@ -580,7 +580,7 @@ describe('DocumentListViewService', () => { expect(documentListViewService.isSelected(documents[3])).toBeTruthy() }) - it('should clear all-selected mode when toggling a single document', () => { + it('should exclude a toggled document while keeping all-selected mode', () => { documentListViewService.reload() const req = httpTestingController.expectOne( `${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true&include_selection_data=true` @@ -592,8 +592,73 @@ describe('DocumentListViewService', () => { documentListViewService.toggleSelected(documents[0]) - expect(documentListViewService.allSelected).toBeFalsy() + expect(documentListViewService.allSelected).toBeTruthy() + expect(documentListViewService.excluded).toEqual(new Set([documents[0].id])) + expect(documentListViewService.selectedCount).toEqual(documents.length - 1) expect(documentListViewService.isSelected(documents[0])).toBeFalsy() + + documentListViewService.toggleSelected(documents[0]) + + expect(documentListViewService.excluded.size).toEqual(0) + expect(documentListViewService.selectedCount).toEqual(documents.length) + expect(documentListViewService.isSelected(documents[0])).toBeTruthy() + }) + + it('should preserve exclusions across pages', () => { + documentListViewService.pageSize = 3 + let req = httpTestingController.expectOne( + `${environment.apiBaseUrl}documents/?page=1&page_size=3&ordering=-created&truncate_content=true&include_selection_data=true` + ) + req.flush({ count: documents.length, results: documents.slice(0, 3) }) + + documentListViewService.selectAll() + documentListViewService.toggleSelected(documents[0]) + documentListViewService.currentPage = 2 + req = httpTestingController.expectOne( + `${environment.apiBaseUrl}documents/?page=2&page_size=3&ordering=-created&truncate_content=true&include_selection_data=true` + ) + req.flush({ count: documents.length, results: documents.slice(3, 6) }) + + expect(documentListViewService.excluded).toEqual(new Set([documents[0].id])) + expect(documentListViewService.selectedCount).toEqual(documents.length - 1) + expect(documentListViewService.selected).toEqual( + new Set(documents.slice(3, 6).map((document) => document.id)) + ) + + documentListViewService.currentPage = 1 + req = httpTestingController.expectOne( + `${environment.apiBaseUrl}documents/?page=1&page_size=3&ordering=-created&truncate_content=true&include_selection_data=true` + ) + req.flush({ count: documents.length, results: documents.slice(0, 3) }) + + expect(documentListViewService.isSelected(documents[0])).toBeFalsy() + expect(documentListViewService.isSelected(documents[1])).toBeTruthy() + }) + + it('should clear exclusions when filters change', () => { + documentListViewService.reload() + let req = httpTestingController.expectOne( + `${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true&include_selection_data=true` + ) + req.flush(full_results) + documentListViewService.selectAll() + documentListViewService.toggleSelected(documents[0]) + + documentListViewService.setFilterRules(filterRules) + req = httpTestingController.expectOne( + `${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true&include_selection_data=true&tags__id__all=9` + ) + req.flush({ count: 3, results: documents.slice(0, 3) }) + + expect(documentListViewService.allSelected).toBeTruthy() + expect(documentListViewService.excluded.size).toEqual(0) + expect(documentListViewService.selectedCount).toEqual(3) + + documentListViewService.setFilterRules([]) + req = httpTestingController.expectOne( + `${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true&include_selection_data=true` + ) + req.flush(full_results) }) it('should clear all-selected mode when selecting a range', () => {