import { createComponentFactory, Spectator } from '@ngneat/spectator';
import { SharedHistoryLogEntryValuesComponent } from '@shared/components/history';
import { DiffDTO as CrmDiffDTO } from '@generated/swagger/crm-api';
import { DiffDTO as OmsDiffDTO } from '@generated/swagger/oms-api';

describe('SharedHistoryLogEntryValuesComponent', () => {
  let spectator: Spectator<SharedHistoryLogEntryValuesComponent>;
  let historyValuesMock: CrmDiffDTO | OmsDiffDTO;

  const createComponent = createComponentFactory({
    component: SharedHistoryLogEntryValuesComponent,
    imports: [],
    declarations: [],
  });

  beforeEach(() => {
    spectator = createComponent();
  });

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

  describe('values', () => {
    beforeEach(() => {
      historyValuesMock = {
        caption: 'test',
        previousValue: 'previous',
        value: 'next',
      };
    });

    it('should render caption if caption exist', () => {
      spectator.setInput('historyLogEntryValues', historyValuesMock);
      expect(spectator.query('.caption')).toHaveText(historyValuesMock.caption);
    });

    it('should render previousValue if previousValue exist', () => {
      spectator.setInput('historyLogEntryValues', historyValuesMock);
      expect(spectator.query('.previous-value')).toHaveText(historyValuesMock.previousValue);
    });

    it('should render value if value exist', () => {
      spectator.setInput('historyLogEntryValues', historyValuesMock);
      expect(spectator.query('.value')).toHaveText(historyValuesMock.value);
    });
  });
});
