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 { provideHttpClientTesting } 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 import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
11 describe('MergeConfirmDialogComponent', () => {
12 let component: MergeConfirmDialogComponent
13 let fixture: ComponentFixture<MergeConfirmDialogComponent>
14 let documentService: DocumentService
16 beforeEach(async () => {
17 await TestBed.configureTestingModule({
18 declarations: [MergeConfirmDialogComponent],
20 NgxBootstrapIconsModule.pick(allIcons),
26 provideHttpClient(withInterceptorsFromDi()),
27 provideHttpClientTesting(),
29 }).compileComponents()
31 fixture = TestBed.createComponent(MergeConfirmDialogComponent)
32 documentService = TestBed.inject(DocumentService)
33 component = fixture.componentInstance
34 fixture.detectChanges()
37 it('should fetch documents on ngOnInit', () => {
39 { id: 1, name: 'Document 1' },
40 { id: 2, name: 'Document 2' },
41 { id: 3, name: 'Document 3' },
43 jest.spyOn(documentService, 'getFew').mockReturnValue(
45 all: documents.map((d) => d.id),
46 count: documents.length,
53 expect(component.documents).toEqual(documents)
54 expect(documentService.getFew).toHaveBeenCalledWith(component.documentIDs)
57 it('should move documentIDs on drop', () => {
58 component.documentIDs = [1, 2, 3]
64 component.onDrop(event as any)
66 expect(component.documentIDs).toEqual([1, 3, 2])
69 it('should get document by ID', () => {
71 { id: 1, name: 'Document 1' },
72 { id: 2, name: 'Document 2' },
73 { id: 3, name: 'Document 3' },
75 jest.spyOn(documentService, 'getFew').mockReturnValue(
77 all: documents.map((d) => d.id),
78 count: documents.length,
85 expect(component.getDocument(2)).toEqual({ id: 2, name: 'Document 2' })