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

import { VariableScopeDetailComponent } from './variable-scope-detail.component';

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

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

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

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

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