]> git.ipfire.org Git - thirdparty/paperless-ngx.git/blob
8b9bf38982641d66e995b68a788bb7becff73893
[thirdparty/paperless-ngx.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing'
2 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
3 import { MergeConfirmDialogComponent } from './merge-confirm-dialog.component'
4 import { HttpClientTestingModule } from '@angular/common/http/testing'
5 import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
6 import { of } from 'rxjs'
7 import { DocumentService } from 'src/app/services/rest/document.service'
8 import { FormsModule, ReactiveFormsModule } from '@angular/forms'
9
10 describe('MergeConfirmDialogComponent', () => {
11 let component: MergeConfirmDialogComponent
12 let fixture: ComponentFixture<MergeConfirmDialogComponent>
13 let documentService: DocumentService
14
15 beforeEach(async () => {
16 await TestBed.configureTestingModule({
17 declarations: [MergeConfirmDialogComponent],
18 providers: [NgbActiveModal],
19 imports: [
20 HttpClientTestingModule,
21 NgxBootstrapIconsModule.pick(allIcons),
22 ReactiveFormsModule,
23 FormsModule,
24 ],
25 }).compileComponents()
26
27 fixture = TestBed.createComponent(MergeConfirmDialogComponent)
28 documentService = TestBed.inject(DocumentService)
29 component = fixture.componentInstance
30 fixture.detectChanges()
31 })
32
33 it('should fetch documents on ngOnInit', () => {
34 const documents = [
35 { id: 1, name: 'Document 1' },
36 { id: 2, name: 'Document 2' },
37 { id: 3, name: 'Document 3' },
38 ]
39 jest.spyOn(documentService, 'getCachedMany').mockReturnValue(of(documents))
40
41 component.ngOnInit()
42
43 expect(component.documents).toEqual(documents)
44 expect(documentService.getCachedMany).toHaveBeenCalledWith(
45 component.documentIDs
46 )
47 })
48
49 it('should move documentIDs on drop', () => {
50 component.documentIDs = [1, 2, 3]
51 const event = {
52 previousIndex: 1,
53 currentIndex: 2,
54 }
55
56 component.onDrop(event as any)
57
58 expect(component.documentIDs).toEqual([1, 3, 2])
59 })
60
61 it('should get document by ID', () => {
62 const documents = [
63 { id: 1, name: 'Document 1' },
64 { id: 2, name: 'Document 2' },
65 { id: 3, name: 'Document 3' },
66 ]
67 jest.spyOn(documentService, 'getCachedMany').mockReturnValue(of(documents))
68
69 component.ngOnInit()
70
71 expect(component.getDocument(2)).toEqual({ id: 2, name: 'Document 2' })
72 })
73 })