import { TestBed } from '@angular/core/testing';
import {
  ReverseActionCellRenderer,
  ReverseActionCellRendererParams,
} from './reverse-action-cell-renderer';
import { TeamActivity } from '../../models/transaction.model';

describe('ReverseActionCellRenderer', () => {
  const activity: TeamActivity = {
    id: 7,
    date: '2026-07-01',
    amount: 5,
    type: 'fine',
    isTeamWalletTransaction: false,
  };

  function create(canReverse: boolean, onReverse = vi.fn()) {
    const fixture = TestBed.createComponent(ReverseActionCellRenderer);
    fixture.componentInstance.agInit({
      data: activity,
      canReverse: () => canReverse,
      onReverse,
    } as unknown as ReverseActionCellRendererParams);
    fixture.detectChanges();
    return { fixture, onReverse };
  }

  it('shows the reverse button when the activity can be reversed', () => {
    const { fixture } = create(true);
    expect(fixture.nativeElement.querySelector('[data-testid="reverse-booking"]')).not.toBeNull();
  });

  it('hides the reverse button when it cannot be reversed', () => {
    const { fixture } = create(false);
    expect(fixture.nativeElement.querySelector('[data-testid="reverse-booking"]')).toBeNull();
  });

  it('invokes onReverse with the row activity when clicked', () => {
    const { fixture, onReverse } = create(true);
    fixture.nativeElement.querySelector('[data-testid="reverse-booking"]').click();
    expect(onReverse).toHaveBeenCalledWith(activity);
  });
});
