import { GetStatusFromHistoryPipe } from './get-status-from-history.pipe';
import { historyDtoMock, historiesDtoMock } from '../../../shared/mockdata';
import { ShelfHistoryLogDetails } from '../../../defs';

fdescribe('Pipe: GetNewStatusFromHistoryPipe', () => {
  let pipe: GetStatusFromHistoryPipe;

  beforeEach(() => {
    pipe = new GetStatusFromHistoryPipe();
  });

  it('should return the new status value', () => {
    const historyWithState: ShelfHistoryLogDetails = historiesDtoMock
      .find((h) => h.values.find((v) => v.caption === 'Status'))
      .values.find((value) => value && value.caption === 'Status');

    const result = pipe.transform(historyWithState);
    const expected = 'bestellt';

    expect(result).toBe(expected);

    const historiesWithOtherChanges = historiesDtoMock
      .find((h) => h.values.find((v) => v.caption === 'vorgemerkt'))
      .values.find((value) => value && value.caption === 'vorgemerkt');

    const result2 = pipe.transform(historiesWithOtherChanges, 'new');
    const expected2 = 'ja';

    expect(result2).toBe(expected2);
  });

  it('should return the old status value', () => {
    const historyWithState: ShelfHistoryLogDetails = historiesDtoMock
      .find((h) => h.values.find((v) => v.caption === 'Status'))
      .values.find((value) => value && value.caption === 'Status');

    const result = pipe.transform(historyWithState, 'old');
    const expected = 'eingetroffen';

    expect(result).toBe(expected);
  });

  it('should return a default value if the status string is empty', () => {
    const historyWithEmptyState: ShelfHistoryLogDetails = historiesDtoMock
      .find((h) => h.values.find((v) => v.value === ''))
      .values.find((value) => value && value.value === '');

    const result = pipe.transform(historyWithEmptyState, 'new');
    expect(result).toBe('-');
  });
});
