Increase coverage
This commit is contained in:
parent
84b516fefc
commit
746e62b600
@ -71,6 +71,7 @@ describe('AppComponent', () => {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
it('should display toast on document consumed with link if user has access', () => {
|
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)
|
jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
|
||||||
let toast: Toast
|
let toast: Toast
|
||||||
toastService.getToasts().subscribe((toasts) => (toast = toasts[0]))
|
toastService.getToasts().subscribe((toasts) => (toast = toasts[0]))
|
||||||
@ -80,9 +81,13 @@ describe('AppComponent', () => {
|
|||||||
.spyOn(consumerStatusService, 'onDocumentConsumptionFinished')
|
.spyOn(consumerStatusService, 'onDocumentConsumptionFinished')
|
||||||
.mockReturnValue(fileStatusSubject)
|
.mockReturnValue(fileStatusSubject)
|
||||||
component.ngOnInit()
|
component.ngOnInit()
|
||||||
fileStatusSubject.next(new FileStatus())
|
const status = new FileStatus()
|
||||||
|
status.documentId = 1
|
||||||
|
fileStatusSubject.next(status)
|
||||||
expect(toastSpy).toHaveBeenCalled()
|
expect(toastSpy).toHaveBeenCalled()
|
||||||
expect(toast.action).not.toBeUndefined()
|
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', () => {
|
it('should display toast on document consumed without link if user does not have access', () => {
|
||||||
|
@ -13,11 +13,18 @@ import { routes } from 'src/app/app-routing.module'
|
|||||||
import { PermissionsGuard } from 'src/app/guards/permissions.guard'
|
import { PermissionsGuard } from 'src/app/guards/permissions.guard'
|
||||||
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
||||||
import { DndModule } from 'ngx-drag-drop'
|
import { DndModule } from 'ngx-drag-drop'
|
||||||
|
import {
|
||||||
|
ConsumerStatusService,
|
||||||
|
FileStatus,
|
||||||
|
} from 'src/app/services/consumer-status.service'
|
||||||
|
import { Subject } from 'rxjs'
|
||||||
|
|
||||||
describe('StatisticsWidgetComponent', () => {
|
describe('StatisticsWidgetComponent', () => {
|
||||||
let component: StatisticsWidgetComponent
|
let component: StatisticsWidgetComponent
|
||||||
let fixture: ComponentFixture<StatisticsWidgetComponent>
|
let fixture: ComponentFixture<StatisticsWidgetComponent>
|
||||||
let httpTestingController: HttpTestingController
|
let httpTestingController: HttpTestingController
|
||||||
|
let consumerStatusService: ConsumerStatusService
|
||||||
|
const fileStatusSubject = new Subject<FileStatus>()
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -36,6 +43,10 @@ describe('StatisticsWidgetComponent', () => {
|
|||||||
}).compileComponents()
|
}).compileComponents()
|
||||||
|
|
||||||
fixture = TestBed.createComponent(StatisticsWidgetComponent)
|
fixture = TestBed.createComponent(StatisticsWidgetComponent)
|
||||||
|
consumerStatusService = TestBed.inject(ConsumerStatusService)
|
||||||
|
jest
|
||||||
|
.spyOn(consumerStatusService, 'onDocumentConsumptionFinished')
|
||||||
|
.mockReturnValue(fileStatusSubject)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
|
|
||||||
httpTestingController = TestBed.inject(HttpTestingController)
|
httpTestingController = TestBed.inject(HttpTestingController)
|
||||||
@ -50,6 +61,12 @@ describe('StatisticsWidgetComponent', () => {
|
|||||||
expect(req.request.method).toEqual('GET')
|
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', () => {
|
it('should display inbox link with count', () => {
|
||||||
const mockStats = {
|
const mockStats = {
|
||||||
documents_total: 200,
|
documents_total: 200,
|
||||||
@ -114,4 +131,62 @@ describe('StatisticsWidgetComponent', () => {
|
|||||||
'CSV(10%)'
|
'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%)'
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -97,7 +97,7 @@ export class StatisticsWidgetComponent
|
|||||||
this.reload()
|
this.reload()
|
||||||
this.subscription = this.consumerStatusService
|
this.subscription = this.consumerStatusService
|
||||||
.onDocumentConsumptionFinished()
|
.onDocumentConsumptionFinished()
|
||||||
.subscribe((status) => {
|
.subscribe(() => {
|
||||||
this.reload()
|
this.reload()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user