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'
10 describe('MergeConfirmDialogComponent', () => {
11 let component: MergeConfirmDialogComponent
12 let fixture: ComponentFixture<MergeConfirmDialogComponent>
13 let documentService: DocumentService
15 beforeEach(async () => {
16 await TestBed.configureTestingModule({
17 declarations: [MergeConfirmDialogComponent],
18 providers: [NgbActiveModal],
20 HttpClientTestingModule,
21 NgxBootstrapIconsModule.pick(allIcons),
25 }).compileComponents()
27 fixture = TestBed.createComponent(MergeConfirmDialogComponent)
28 documentService = TestBed.inject(DocumentService)
29 component = fixture.componentInstance
30 fixture.detectChanges()
33 it('should fetch documents on ngOnInit', () => {
35 { id: 1, name: 'Document 1' },
36 { id: 2, name: 'Document 2' },
37 { id: 3, name: 'Document 3' },
39 jest.spyOn(documentService, 'getCachedMany').mockReturnValue(of(documents))
43 expect(component.documents).toEqual(documents)
44 expect(documentService.getCachedMany).toHaveBeenCalledWith(
49 it('should move documentIDs on drop', () => {
50 component.documentIDs = [1, 2, 3]
56 component.onDrop(event as any)
58 expect(component.documentIDs).toEqual([1, 3, 2])
61 it('should get document by ID', () => {
63 { id: 1, name: 'Document 1' },
64 { id: 2, name: 'Document 2' },
65 { id: 3, name: 'Document 3' },
67 jest.spyOn(documentService, 'getCachedMany').mockReturnValue(of(documents))
71 expect(component.getDocument(2)).toEqual({ id: 2, name: 'Document 2' })