jest.mock('@ng-bootstrap/ng-bootstrap');

import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { HttpResponse } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { of } from 'rxjs';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

import { InputDataUploadService } from '../service/input-data-upload.service';

import { InputDataUploadImportDialogComponent } from './input-data-upload-import-dialog.component';

describe('InputDataUpload Management Import Component', () => {
  let comp: InputDataUploadImportDialogComponent;
  let fixture: ComponentFixture<InputDataUploadImportDialogComponent>;
  let service: InputDataUploadService;
  let mockActiveModal: NgbActiveModal;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule, InputDataUploadImportDialogComponent],
      providers: [NgbActiveModal],
    })
      .overrideTemplate(InputDataUploadImportDialogComponent, '')
      .compileComponents();
    fixture = TestBed.createComponent(InputDataUploadImportDialogComponent);
    comp = fixture.componentInstance;
    service = TestBed.inject(InputDataUploadService);
    mockActiveModal = TestBed.inject(NgbActiveModal);
  });

  describe('confirmImport', () => {
    it('Should call import service on confirmImport', inject(
      [],
      fakeAsync(() => {
        // GIVEN
        jest.spyOn(service, 'import').mockReturnValue(of(new HttpResponse({ body: {} })));

        // WHEN
        comp.confirmImport(123);
        tick();

        // THEN
        expect(service.import).toHaveBeenCalledWith(123);
        expect(mockActiveModal.close).toHaveBeenCalledWith('imported');
      }),
    ));

    it('Should not call import service on clear', () => {
      // GIVEN
      jest.spyOn(service, 'import');

      // WHEN
      comp.cancel();

      // THEN
      expect(service.import).not.toHaveBeenCalled();
      expect(mockActiveModal.close).not.toHaveBeenCalled();
      expect(mockActiveModal.dismiss).toHaveBeenCalled();
    });
  });
});
