mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix: fix some popover closing behavior
This commit is contained in:
		| @@ -4,7 +4,7 @@ | |||||||
|   <ng-content></ng-content> |   <ng-content></ng-content> | ||||||
| </a> | </a> | ||||||
| <ng-template #previewContent> | <ng-template #previewContent> | ||||||
|   <div class="preview-popup-container"> |   <div class="preview-popup-container" (mouseenter)="mouseEnterPreview()" (mouseleave)="mouseLeavePreview(); close()"> | ||||||
|     @if (error) { |     @if (error) { | ||||||
|       <div class="w-100 h-100 position-relative"> |       <div class="w-100 h-100 position-relative"> | ||||||
|         <p class="fst-italic position-absolute top-50 start-50 translate-middle" i18n>Error loading preview</p> |         <p class="fst-italic position-absolute top-50 start-50 translate-middle" i18n>Error loading preview</p> | ||||||
|   | |||||||
| @@ -1,9 +1,4 @@ | |||||||
| import { | import { ComponentFixture, TestBed } from '@angular/core/testing' | ||||||
|   ComponentFixture, |  | ||||||
|   fakeAsync, |  | ||||||
|   TestBed, |  | ||||||
|   tick, |  | ||||||
| } from '@angular/core/testing' |  | ||||||
|  |  | ||||||
| import { | import { | ||||||
|   HttpClient, |   HttpClient, | ||||||
| @@ -61,6 +56,7 @@ describe('PreviewPopupComponent', () => { | |||||||
|     fixture = TestBed.createComponent(PreviewPopupComponent) |     fixture = TestBed.createComponent(PreviewPopupComponent) | ||||||
|     component = fixture.componentInstance |     component = fixture.componentInstance | ||||||
|     component.document = { ...doc } |     component.document = { ...doc } | ||||||
|  |     jest.useFakeTimers() | ||||||
|     fixture.detectChanges() |     fixture.detectChanges() | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
| @@ -139,16 +135,36 @@ describe('PreviewPopupComponent', () => { | |||||||
|     expect(component.previewText).toEqual('Preview text') |     expect(component.previewText).toEqual('Preview text') | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
|   it('should show preview on mouseover after delay to preload content', fakeAsync(() => { |   it('should show preview on mouseover after delay to preload content', () => { | ||||||
|     component.mouseEnterPreview() |     component.mouseEnterPreview() | ||||||
|     expect(component.popover.isOpen()).toBeTruthy() |     expect(component.popover.isOpen()).toBeTruthy() | ||||||
|     tick(600) |     jest.advanceTimersByTime(600) | ||||||
|     component.close() |     component.close() | ||||||
|  |     jest.advanceTimersByTime(600) | ||||||
|  |   }) | ||||||
|  |  | ||||||
|  |   it('should not show preview on mouseover if mouse no longer on preview', () => { | ||||||
|     component.mouseEnterPreview() |     component.mouseEnterPreview() | ||||||
|     tick(100) |     jest.advanceTimersByTime(100) | ||||||
|     component.mouseLeavePreview() |     component.mouseLeavePreview() | ||||||
|     tick(600) |     jest.advanceTimersByTime(600) | ||||||
|     expect(component.popover.isOpen()).toBeFalsy() |     expect(component.popover.isOpen()).toBeFalsy() | ||||||
|   })) |   }) | ||||||
|  |  | ||||||
|  |   it('should not close preview on mouseleave if mouse back on preview', () => { | ||||||
|  |     component.close() | ||||||
|  |     component.mouseEnterPreview() | ||||||
|  |     jest.advanceTimersByTime(300) | ||||||
|  |     expect(component.popover.isOpen()).toBeTruthy() | ||||||
|  |   }) | ||||||
|  |  | ||||||
|  |   it('should support immediate close on mouseleave', () => { | ||||||
|  |     component.mouseEnterPreview() | ||||||
|  |     jest.advanceTimersByTime(600) | ||||||
|  |     expect(component.popover.isOpen()).toBeTruthy() | ||||||
|  |     component.mouseLeavePreview() | ||||||
|  |     component.close(true) | ||||||
|  |     jest.advanceTimersByTime(1) | ||||||
|  |     expect(component.popover.isOpen()).toBeFalsy() | ||||||
|  |   }) | ||||||
| }) | }) | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ export class PreviewPopupComponent implements OnDestroy { | |||||||
|  |  | ||||||
|   @ViewChild('popover') popover: NgbPopover |   @ViewChild('popover') popover: NgbPopover | ||||||
|  |  | ||||||
|   mouseOnPreview: boolean |   mouseOnPreview: boolean = false | ||||||
|  |  | ||||||
|   popoverClass: string = 'shadow popover-preview' |   popoverClass: string = 'shadow popover-preview' | ||||||
|  |  | ||||||
| @@ -118,7 +118,7 @@ export class PreviewPopupComponent implements OnDestroy { | |||||||
|           // show popover |           // show popover | ||||||
|           this.popoverClass = this.popoverClass.replace('pe-none opacity-0', '') |           this.popoverClass = this.popoverClass.replace('pe-none opacity-0', '') | ||||||
|         } else { |         } else { | ||||||
|           this.popover.close() |           this.popover.close(true) | ||||||
|         } |         } | ||||||
|       }, 600) |       }, 600) | ||||||
|     } |     } | ||||||
| @@ -128,7 +128,12 @@ export class PreviewPopupComponent implements OnDestroy { | |||||||
|     this.mouseOnPreview = false |     this.mouseOnPreview = false | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public close() { |   public close(immediate: boolean = false) { | ||||||
|     this.popover.close(false) |     setTimeout( | ||||||
|  |       () => { | ||||||
|  |         if (!this.mouseOnPreview) this.popover.close() | ||||||
|  |       }, | ||||||
|  |       immediate ? 0 : 300 | ||||||
|  |     ) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon