import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator';
import { TitlePipe } from './title.pipe';

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

  it('should return the first and second string array index of the input with - seperator', () => {
    const author = 'test author';
    const title = 'test title';

    spectator = createPipe(`{{ value | title }}`, {
      hostProps: {
        value: [author, title],
      },
    });
    expect(spectator.element).toHaveText(`${author} - ${title}`);
  });

  it('should trim and add ... the first index if its length is greater then max', () => {
    const author = 'Lorem ipsum dolor sit amet, consetetur sadipscing ';
    const title = 'test title';

    spectator = createPipe(`{{ value | title }}`, {
      hostProps: {
        value: [author, title],
      },
    });
    expect(spectator.element).toHaveText(`Lorem ipsum dolor sit amet, consete... - ${title}`);
  });

  it('should trim and add ... the second index if its length is greater then max', () => {
    const author = 'test author';
    const title = 'Lorem ipsum dolor sit amet, consetetur sadipscing ';
    spectator = createPipe(`{{ value | title }}`, {
      hostProps: {
        value: [author, title],
      },
    });
    expect(spectator.element).toHaveText(`${author} - Lorem ipsum dolor sit amet, conset...`);
  });
});
