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

import { VariableClassTypeDetailComponent } from './variable-class-type-detail.component';

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

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

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

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

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