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

import { OutputDataDetailComponent } from './output-data-detail.component';

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

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

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

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

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