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

import { InputDataDetailComponent } from './input-data-detail.component';

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

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

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

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

      // THEN
      expect(instance.inputData()).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();
    });
  });
});
