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

import { MetadataValueDetailComponent } from './metadata-value-detail.component';

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

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

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

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

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