import { createHostFactory, SpectatorHost } from '@ngneat/spectator';
import { UiIconModule } from '@ui/icon';
import { UiButtonLoaderComponent, UiLoaderComponent } from './loader.component';

describe('UiLoaderComponent', () => {
  let spectator: SpectatorHost<UiLoaderComponent>;
  const createHost = createHostFactory({
    component: UiLoaderComponent,
    imports: [UiIconModule],
  });

  beforeEach(() => {
    spectator = createHost('<div [uiLoader]="loading"></div>', {
      hostProps: { loading: false },
    });
  });

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

  describe('loader', () => {
    it('should render .spinner if true', () => {
      spectator.setHostInput({ loading: true });
      expect(spectator.query('.spinner')).toBeVisible();
    });

    it('should note render .spinner if false', () => {
      spectator.setHostInput({ loading: false });
      expect(spectator.query('.spinner')).not.toBeVisible();
    });
  });
});

describe('UiButtonLoaderComponent', () => {
  let spectator: SpectatorHost<UiButtonLoaderComponent>;
  let createHost = createHostFactory({
    component: UiButtonLoaderComponent,
    imports: [UiIconModule],
  });

  beforeEach(() => {
    spectator = createHost('<button [uiLoader]="loading"></button>', {
      hostProps: { loading: false },
    });
  });

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

  describe('loader', () => {
    it('should render .spinner if true', () => {
      spectator.setHostInput({ loading: true });
      expect(spectator.query('.spinner')).toBeVisible();
    });

    it('should note render .spinner if false', () => {
      spectator.setHostInput({ loading: false });
      expect(spectator.query('.spinner')).not.toBeVisible();
    });

    it('should disable the host element if true', () => {
      spectator.setHostInput({ loading: true });
      expect(spectator.element).toBeDisabled();
    });

    it('should not disable the host element if false', () => {
      spectator.setHostInput({ loading: false });
      expect(spectator.element).not.toBeDisabled();
    });
  });
});
