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

import { MetadataPropertyDetailComponent } from './metadata-property-detail.component';

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

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

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

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

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