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 { ResilientActivityService } from '../../service/resilient-activity.service';

import { ResilientActivityActionsButtonDialogComponent } from './resilient-activity-actions-button-dialog.component';

describe('Resilient Activity Actions Button Dialog Component', () => {
  let comp: ResilientActivityActionsButtonDialogComponent;
  let fixture: ComponentFixture<ResilientActivityActionsButtonDialogComponent>;
  let service: InputDataUploadService;
  let mockActiveModal: NgbActiveModal;

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

  describe('confirmActivityInvoke', () => {
    it('Should call activity engine service on confirmActivityInvoke', 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();
    });
  });
});
