import { TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { provideRouter } from '@angular/router';
import { ForgotPassword } from './forgot-password';
import { environment } from '../../../../environments/environment';

describe('ForgotPassword', () => {
  let httpMock: HttpTestingController;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [ForgotPassword],
      providers: [provideHttpClient(), provideHttpClientTesting(), provideRouter([])],
    }).compileComponents();
    httpMock = TestBed.inject(HttpTestingController);
  });

  afterEach(() => httpMock.verify());

  it('requests an email and shows the success state', () => {
    const fixture = TestBed.createComponent(ForgotPassword);
    fixture.componentInstance['form'].setValue({ email: 'alex@example.de' });
    fixture.componentInstance['onSubmit']();

    httpMock.expectOne(`${environment.apiUrl}auth/forgot/password`).flush(null);

    expect(fixture.componentInstance['sent']()).toBe(true);
  });
});
