1 import { ComponentFixture, TestBed } from '@angular/core/testing'
3 import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
4 import { provideHttpClientTesting } from '@angular/common/http/testing'
5 import { FormsModule, ReactiveFormsModule } from '@angular/forms'
6 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
7 import { PdfViewerModule } from 'ng2-pdf-viewer'
8 import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
9 import { of } from 'rxjs'
10 import { DocumentService } from 'src/app/services/rest/document.service'
11 import { SplitConfirmDialogComponent } from './split-confirm-dialog.component'
13 describe('SplitConfirmDialogComponent', () => {
14 let component: SplitConfirmDialogComponent
15 let fixture: ComponentFixture<SplitConfirmDialogComponent>
16 let documentService: DocumentService
18 beforeEach(async () => {
19 await TestBed.configureTestingModule({
21 NgxBootstrapIconsModule.pick(allIcons),
25 SplitConfirmDialogComponent,
29 provideHttpClient(withInterceptorsFromDi()),
30 provideHttpClientTesting(),
32 }).compileComponents()
34 fixture = TestBed.createComponent(SplitConfirmDialogComponent)
35 documentService = TestBed.inject(DocumentService)
36 component = fixture.componentInstance
37 fixture.detectChanges()
40 it('should load document on init', () => {
41 const getSpy = jest.spyOn(documentService, 'get')
42 component.documentID = 1
43 getSpy.mockReturnValue(of({ id: 1 } as any))
45 expect(documentService.get).toHaveBeenCalledWith(1)
48 it('should update pagesString when pages are added', () => {
49 component.totalPages = 5
52 expect(component.pagesString).toEqual('1-2,3-5')
55 expect(component.pagesString).toEqual('1-2,3-4,5')
58 it('should update pagesString when pages are removed', () => {
59 component.totalPages = 5
64 expect(component.pagesString).toEqual('1-2,3-4,5')
65 component.removeSplit(0)
66 expect(component.pagesString).toEqual('1-4,5')
69 it('should enable confirm button when pages are added', () => {
70 component.totalPages = 5
73 expect(component.confirmButtonEnabled).toBeTruthy()
76 it('should disable confirm button when all pages are removed', () => {
77 component.totalPages = 5
80 component.removeSplit(0)
81 expect(component.confirmButtonEnabled).toBeFalsy()
84 it('should not add split if page is the last page', () => {
85 component.totalPages = 5
88 expect(component.pagesString).toEqual('1-5')
91 it('should update totalPages when pdf is loaded', () => {
92 component.pdfPreviewLoaded({ numPages: 5 } as any)
93 expect(component.totalPages).toEqual(5)
96 it('should correctly disable split button', () => {
97 component.totalPages = 5
99 expect(component.canSplit).toBeTruthy()
101 expect(component.canSplit).toBeFalsy()
103 expect(component.canSplit).toBeTruthy()
104 component['pages'] = new Set([1, 2, 3, 4])
105 expect(component.canSplit).toBeFalsy()