import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { ProductFormatIconComponent } from './product-format-icon.component';
import { NgIcon } from '@ng-icons/core';

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

  beforeEach(() => {
    spectator = createComponent({ props: { format: 'HC' } });
  });

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

  it('should render ng-icon with lowercased format as name', () => {
    const icon = spectator.query(NgIcon);
    expect(icon).toBeTruthy();
    expect(icon?.name()).toBe('hc');
  });

  it('should set correct data attributes on host', () => {
    const host = spectator.element;
    expect(host).toHaveAttribute('data-what', 'product-format-icon');
    expect(host).toHaveAttribute('data-which', 'shared-product-format-icon');
  });
});
