From b64191feb77a23954063cdfff87a23913235acb9 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:32:22 -0700 Subject: [PATCH] Fix tests --- .../document-list.component.spec.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-list.component.spec.ts b/src-ui/src/app/components/document-list/document-list.component.spec.ts index bf21616e8..77dc03f84 100644 --- a/src-ui/src/app/components/document-list/document-list.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-list.component.spec.ts @@ -64,6 +64,8 @@ import { SettingsService } from 'src/app/services/settings.service' import { SETTINGS_KEYS } from 'src/app/data/ui-settings' import { IsNumberPipe } from 'src/app/pipes/is-number.pipe' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' +import { PermissionsService } from 'src/app/services/permissions.service' +import { NgSelectModule } from '@ng-select/ng-select' const docs: Document[] = [ { @@ -101,6 +103,7 @@ describe('DocumentListComponent', () => { let toastService: ToastService let modalService: NgbModal let settingsService: SettingsService + let permissionService: PermissionsService beforeEach(async () => { TestBed.configureTestingModule({ @@ -148,6 +151,7 @@ describe('DocumentListComponent', () => { NgbPopoverModule, NgbTooltipModule, NgxBootstrapIconsModule.pick(allIcons), + NgSelectModule, ], }).compileComponents() @@ -160,6 +164,7 @@ describe('DocumentListComponent', () => { toastService = TestBed.inject(ToastService) modalService = TestBed.inject(NgbModal) settingsService = TestBed.inject(SettingsService) + permissionService = TestBed.inject(PermissionsService) fixture = TestBed.createComponent(DocumentListComponent) component = fixture.componentInstance }) @@ -548,18 +553,13 @@ describe('DocumentListComponent', () => { expect(routerSpy).toHaveBeenCalledWith(['documents', 99]) }) - it('should support checking if notes enabled to hide column', () => { + it('should hide columns if no perms or notes disabled', () => { + jest.spyOn(permissionService, 'currentUserCan').mockReturnValue(true) jest.spyOn(documentListService, 'documents', 'get').mockReturnValue(docs) - fixture.detectChanges() expect(documentListService.sortField).toEqual('created') - const detailsDisplayModeButton = fixture.debugElement.query( - By.css('input[type="radio"]') - ) - detailsDisplayModeButton.nativeElement.checked = true - detailsDisplayModeButton.triggerEventHandler('change') + component.displayMode = 'details' fixture.detectChanges() - expect(component.displayMode).toEqual('details') expect( fixture.debugElement.queryAll(By.directive(SortableDirective)) @@ -572,6 +572,13 @@ describe('DocumentListComponent', () => { expect( fixture.debugElement.queryAll(By.directive(SortableDirective)) ).toHaveLength(8) + + // insufficient perms + jest.spyOn(permissionService, 'currentUserCan').mockReturnValue(false) + fixture.detectChanges() + expect( + fixture.debugElement.queryAll(By.directive(SortableDirective)) + ).toHaveLength(5) }) it('should support toggle on document objects', () => {