import { TestBed } from '@angular/core/testing';
import { ActivatedRoute, convertToParamMap, provideRouter } from '@angular/router';
import { of } from 'rxjs';
import { PublicTeamApi } from '../../core/team/public-team-api';
import { PublicPlayer } from './public-player';

describe('PublicPlayer', () => {
  it('renders player identity and public transaction history', async () => {
    await TestBed.configureTestingModule({
      imports: [PublicPlayer],
      providers: [
        provideRouter([]),
        {
          provide: ActivatedRoute,
          useValue: {
            snapshot: { paramMap: convertToParamMap({ token: 'public-token', playerId: '7' }) },
          },
        },
        {
          provide: PublicTeamApi,
          useValue: {
            loadPlayerHistory: vi.fn(() =>
              of({
                player: {
                  id: 7,
                  firstName: 'Ada',
                  lastName: 'Lovelace',
                  balance: -5,
                  active: true,
                },
                transactions: [
                  {
                    id: 1,
                    date: '2026-07-31',
                    amount: 5,
                    note: 'Training',
                    type: { id: 11, name: 'fine' },
                  },
                ],
              }),
            ),
          },
        },
      ],
    }).compileComponents();
    const fixture = TestBed.createComponent(PublicPlayer);
    fixture.detectChanges();

    expect(fixture.nativeElement.textContent).toContain('Ada Lovelace');
    expect(fixture.nativeElement.textContent).toContain('Training');
    expect(fixture.nativeElement.textContent).toContain('-5,00');
  });
});
