import { Spectator, createComponentFactory } from '@ngneat/spectator/jest';
import { FilterInputMenuComponent } from './input-menu.component';
import { MockComponent } from 'ng-mocks';
import { FilterActionsComponent } from '../../actions';
import { InputRendererComponent } from '../../inputs/input-renderer';
import { FilterInput } from '../../core';
import { InputType } from '../../types';

describe('FilterInputMenuComponent', () => {
  let spectator: Spectator<FilterInputMenuComponent>;
  const createComponent = createComponentFactory({
    component: FilterInputMenuComponent,
    declarations: [MockComponent(FilterActionsComponent), MockComponent(InputRendererComponent)],
    detectChanges: false,
  });

  beforeEach(() => {
    spectator = createComponent();
  });

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

  it('should emit reseted event when reset is triggered', () => {
    const resetSpy = jest.spyOn(spectator.component.reseted, 'emit');

    // Act
    spectator.component.reseted.emit();

    // Assert
    expect(resetSpy).toHaveBeenCalled();
  });

  it('should emit applied event when apply is triggered', () => {
    const applySpy = jest.spyOn(spectator.component.applied, 'emit');

    // Act
    spectator.component.applied.emit();

    // Assert
    expect(applySpy).toHaveBeenCalled();
  });

  it('should render the filter input', () => {
    // Arrange
    const filterInput: FilterInput = {
      key: 'test-key',
      group: 'test-group',
      type: InputType.Text,
      label: 'Test Label',
      target: 'input',
    };
    spectator.setInput('filterInput', filterInput);

    // Act
    spectator.detectChanges();

    // Assert
    expect(spectator.query(InputRendererComponent)).toBeTruthy();
  });
});
