import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter, withComponentInputBinding } from '@angular/router';
import { RouterTestingHarness } from '@angular/router/testing';
import { of } from 'rxjs';

import { EmissionFactorDetailComponent } from './emission-factor-detail.component';

describe('EmissionFactor Management Detail Component', () => {
  let comp: EmissionFactorDetailComponent;
  let fixture: ComponentFixture<EmissionFactorDetailComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [EmissionFactorDetailComponent],
      providers: [
        provideRouter(
          [
            {
              path: '**',
              component: EmissionFactorDetailComponent,
              resolve: { emissionFactor: () => of({ id: 123 }) },
            },
          ],
          withComponentInputBinding(),
        ),
      ],
    })
      .overrideTemplate(EmissionFactorDetailComponent, '')
      .compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(EmissionFactorDetailComponent);
    comp = fixture.componentInstance;
  });

  describe('OnInit', () => {
    it('Should load emissionFactor on init', async () => {
      const harness = await RouterTestingHarness.create();
      const instance = await harness.navigateByUrl('/', EmissionFactorDetailComponent);

      // THEN
      expect(instance.emissionFactor()).toEqual(expect.objectContaining({ id: 123 }));
    });
  });

  describe('PreviousState', () => {
    it('Should navigate to previous state', () => {
      jest.spyOn(window.history, 'back');
      comp.previousState();
      expect(window.history.back).toHaveBeenCalled();
    });
  });
});
