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

import { ResilientActivityActionsButtonComponent } from './resilient-activity-actions-button.component';

describe('Resilient Activity Actions Button Component', () => {
  let comp: ResilientActivityActionsButtonComponent;
  let fixture: ComponentFixture<ResilientActivityActionsButtonComponent>;

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

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

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

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