import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import {
  FeedbackDialogComponent,
  FeedbackDialogData,
} from './feedback-dialog.component';
import { DialogRef, DIALOG_DATA } from '@angular/cdk/dialog';
import { NgIcon } from '@ng-icons/core';
import { DialogComponent } from '../dialog.component';

// Test suite for FeedbackDialogComponent
describe('FeedbackDialogComponent', () => {
  let spectator: Spectator<FeedbackDialogComponent>;
  let mockDialogRef: DialogRef<void>;
  const mockData: FeedbackDialogData = {
    message: 'Feedback message',
  };

  const createComponent = createComponentFactory({
    component: FeedbackDialogComponent,
    imports: [NgIcon],
    providers: [
      {
        provide: DialogRef,
        useValue: { close: jest.fn() },
      },
      {
        provide: DIALOG_DATA,
        useValue: mockData,
      },
      {
        provide: DialogComponent,
        useValue: {},
      },
    ],
  });

  beforeEach(() => {
    spectator = createComponent();
    mockDialogRef = spectator.inject(DialogRef);
    jest.clearAllMocks();
  });

  it('should create', () => {
    expect(spectator.component).toBeTruthy();
  });

  it('should display the feedback message passed in data', () => {
    // Adjust selector if template uses a different data-what value
    const messageElement = spectator.query('[data-what="message"]');
    expect(messageElement).toHaveText('Feedback message');
  });

  it('should render the check icon', () => {
    // The icon should be present if the template uses NgIcon with isaActionCheck
    const iconElement = spectator.query('ng-icon');
    expect(iconElement).toBeTruthy();
  });

  it('should auto-close after delay by default', (done) => {
    // The component should auto-close after the default delay (1500ms)
    setTimeout(() => {
      expect(mockDialogRef.close).toHaveBeenCalled();
      done();
    }, 1600); // Wait slightly longer than default delay
  });
});
