import { Component, signal } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { provideRouter, Router } from '@angular/router';
import { AuthStore } from '../../../core/auth/auth-store';
import { More } from './more';

@Component({ template: '' })
class LoginStub {}

describe('More', () => {
  it('shows the feature links and logs the user out', async () => {
    const clearSession = vi.fn();
    await TestBed.configureTestingModule({
      imports: [More],
      providers: [
        provideRouter([{ path: 'auth/login', component: LoginStub }]),
        {
          provide: AuthStore,
          useValue: {
            currentUser: signal({ firstName: 'Alex', lastName: 'Muster', email: 'a@b.de' }),
            clearSession,
          },
        },
      ],
    }).compileComponents();
    const fixture = TestBed.createComponent(More);
    fixture.detectChanges();

    expect(fixture.nativeElement.textContent).toContain('Strafenkatalog');
    expect(fixture.nativeElement.textContent).toContain('Einladen');
    expect(fixture.nativeElement.textContent).toContain('Profil');
    expect(fixture.nativeElement.textContent).toContain('Öffentliche Freigabe');

    fixture.componentInstance['logout']();
    await fixture.whenStable();
    expect(clearSession).toHaveBeenCalled();
    expect(TestBed.inject(Router).url).toBe('/auth/login');
  });
});
