From 746e62b6006e931ada9ce5c7f19200210ee1b69c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:55:24 -0700 Subject: [PATCH] Increase coverage --- src-ui/src/app/app.component.spec.ts | 7 +- .../statistics-widget.component.spec.ts | 75 +++++++++++++++++++ .../statistics-widget.component.ts | 2 +- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/app.component.spec.ts b/src-ui/src/app/app.component.spec.ts index 458f9b582..10016fa64 100644 --- a/src-ui/src/app/app.component.spec.ts +++ b/src-ui/src/app/app.component.spec.ts @@ -71,6 +71,7 @@ describe('AppComponent', () => { })) it('should display toast on document consumed with link if user has access', () => { + const navigateSpy = jest.spyOn(router, 'navigate') jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) let toast: Toast toastService.getToasts().subscribe((toasts) => (toast = toasts[0])) @@ -80,9 +81,13 @@ describe('AppComponent', () => { .spyOn(consumerStatusService, 'onDocumentConsumptionFinished') .mockReturnValue(fileStatusSubject) component.ngOnInit() - fileStatusSubject.next(new FileStatus()) + const status = new FileStatus() + status.documentId = 1 + fileStatusSubject.next(status) expect(toastSpy).toHaveBeenCalled() expect(toast.action).not.toBeUndefined() + toast.action() + expect(navigateSpy).toHaveBeenCalledWith(['documents', status.documentId]) }) it('should display toast on document consumed without link if user does not have access', () => { diff --git a/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.spec.ts b/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.spec.ts index 609f0dd7d..a838e7f52 100644 --- a/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.spec.ts +++ b/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.spec.ts @@ -13,11 +13,18 @@ import { routes } from 'src/app/app-routing.module' import { PermissionsGuard } from 'src/app/guards/permissions.guard' import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive' import { DndModule } from 'ngx-drag-drop' +import { + ConsumerStatusService, + FileStatus, +} from 'src/app/services/consumer-status.service' +import { Subject } from 'rxjs' describe('StatisticsWidgetComponent', () => { let component: StatisticsWidgetComponent let fixture: ComponentFixture let httpTestingController: HttpTestingController + let consumerStatusService: ConsumerStatusService + const fileStatusSubject = new Subject() beforeEach(async () => { TestBed.configureTestingModule({ @@ -36,6 +43,10 @@ describe('StatisticsWidgetComponent', () => { }).compileComponents() fixture = TestBed.createComponent(StatisticsWidgetComponent) + consumerStatusService = TestBed.inject(ConsumerStatusService) + jest + .spyOn(consumerStatusService, 'onDocumentConsumptionFinished') + .mockReturnValue(fileStatusSubject) component = fixture.componentInstance httpTestingController = TestBed.inject(HttpTestingController) @@ -50,6 +61,12 @@ describe('StatisticsWidgetComponent', () => { expect(req.request.method).toEqual('GET') }) + it('should reload after doc is consumed', () => { + const reloadSpy = jest.spyOn(component, 'reload') + fileStatusSubject.next(new FileStatus()) + expect(reloadSpy).toHaveBeenCalled() + }) + it('should display inbox link with count', () => { const mockStats = { documents_total: 200, @@ -114,4 +131,62 @@ describe('StatisticsWidgetComponent', () => { 'CSV(10%)' ) }) + + it('should limit mime types to 5 max', () => { + const mockStats = { + documents_total: 222, + documents_inbox: 18, + inbox_tag: 10, + document_file_type_counts: [ + { + mime_type: 'application/pdf', + mime_type_count: 160, + }, + { + mime_type: 'text/plain', + mime_type_count: 20, + }, + { + mime_type: 'text/csv', + mime_type_count: 20, + }, + { + mime_type: 'application/vnd.oasis.opendocument.text', + mime_type_count: 11, + }, + { + mime_type: 'application/msword', + mime_type_count: 9, + }, + { + mime_type: 'image/jpeg', + mime_type_count: 2, + }, + ], + character_count: 162312, + } + + const req = httpTestingController.expectOne( + `${environment.apiBaseUrl}statistics/` + ) + + req.flush(mockStats) + fixture.detectChanges() + + expect(fixture.nativeElement.textContent.replace(/\s/g, '')).toContain( + 'PDF(72.1%)' + ) + expect(fixture.nativeElement.textContent.replace(/\s/g, '')).toContain( + 'TXT(9%)' + ) + expect(fixture.nativeElement.textContent.replace(/\s/g, '')).toContain( + 'CSV(9%)' + ) + expect(fixture.nativeElement.textContent.replace(/\s/g, '')).toContain( + 'ODT(5%)' + ) + expect(fixture.nativeElement.textContent.replace(/\s/g, '')).toContain( + 'Other(0.9%)' + ) + }) }) diff --git a/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts b/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts index a662126b0..01799e9ac 100644 --- a/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts +++ b/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts @@ -97,7 +97,7 @@ export class StatisticsWidgetComponent this.reload() this.subscription = this.consumerStatusService .onDocumentConsumptionFinished() - .subscribe((status) => { + .subscribe(() => { this.reload() }) }