import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator';
import { OrderItemListItemDTO } from '@swagger/oms';
import { ShowCompartmentCodePipe } from './show-compartment-code.pipe';

describe('ShowCompartmentCodePipe', () => {
  let spectator: SpectatorPipe<ShowCompartmentCodePipe>;
  const createPipe = createPipeFactory(ShowCompartmentCodePipe);

  it('should return false if it is not the first item', () => {
    spectator = createPipe(`{{ false | showCompartmentCode }}`);
    expect(spectator.element).toHaveText('false');
  });

  it('should return true when no prior identical compartment code exists', () => {
    const mockItems: OrderItemListItemDTO[] = ([
      {
        compartmentCode: 123,
        orderItemSubsetId: 114380039,
      },
      {
        compartmentCode: 456,
        orderItemSubsetId: 114380027,
      },
    ] as unknown) as OrderItemListItemDTO[];

    spectator = createPipe(`{{ true | showCompartmentCode:item:items }}`, {
      hostProps: {
        item: mockItems[1],
        items: mockItems,
      },
    });

    expect(spectator.element).toHaveText('true');
  });

  it('should return false when one or more prior identical compartment codes exist', () => {
    const mockItems: OrderItemListItemDTO[] = ([
      {
        compartmentCode: 456,
        orderItemSubsetId: 114380039,
      },
      {
        compartmentCode: 456,
        orderItemSubsetId: 114380027,
      },
      {
        compartmentCode: 456,
        orderItemSubsetId: 114380072,
      },
    ] as unknown) as OrderItemListItemDTO[];

    spectator = createPipe(`{{ true | showCompartmentCode:item:items }}`, {
      hostProps: {
        item: mockItems[1],
        items: mockItems,
      },
    });

    expect(spectator.element).toHaveText('false');
  });
});
