import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { TooltipComponent } from './tooltip.component';

describe('TooltipComponent', () => {
  let spectator: Spectator<TooltipComponent>;
  const createComponent = createComponentFactory(TooltipComponent);

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

  it('should return string content from text()', () => {
    spectator = createComponent();
    const testContent = 'Tooltip text';
    spectator.component.content.set(testContent);
    expect(spectator.component.text()).toBe(testContent);
    expect(spectator.component.template()).toBeUndefined();
  });

  it('should return undefined from template() if content is string', () => {
    spectator = createComponent();
    spectator.component.content.set('plain string');
    expect(spectator.component.template()).toBeUndefined();
  });

  it('should set and get title signal', () => {
    spectator = createComponent();
    spectator.component.title.set('My Title');
    expect(spectator.component.title()).toBe('My Title');
  });

  it('should render the title when set', () => {
    spectator = createComponent();
    spectator.component.title.set('Tooltip Title');
    spectator.detectChanges();
    const titleEl = spectator.query('.ui-tooltip-title');
    expect(titleEl).toHaveText('Tooltip Title');
  });

  it('should not render the title div when title is not set', () => {
    spectator = createComponent();
    spectator.component.title.set(undefined);
    spectator.detectChanges();
    const titleEl = spectator.query('.ui-tooltip-title');
    expect(titleEl).toBeNull();
  });

  it('should render string content in the content div', () => {
    spectator = createComponent();
    const testContent = 'Tooltip content';
    spectator.component.content.set(testContent);
    spectator.detectChanges();
    const contentEl = spectator.query('.ui-tooltip-content');
    expect(contentEl).toHaveText(testContent);
  });
});
