import { TestBed } from '@angular/core/testing';

import { sampleWithRequiredData, sampleWithNewData } from '../input-data-upload-log.test-samples';

import { InputDataUploadLogFormService } from './input-data-upload-log-form.service';

describe('InputDataUploadLog Form Service', () => {
  let service: InputDataUploadLogFormService;

  beforeEach(() => {
    TestBed.configureTestingModule({});
    service = TestBed.inject(InputDataUploadLogFormService);
  });

  describe('Service methods', () => {
    describe('createInputDataUploadLogFormGroup', () => {
      it('should create a new form with FormControl', () => {
        const formGroup = service.createInputDataUploadLogFormGroup();

        expect(formGroup.controls).toEqual(
          expect.objectContaining({
            id: expect.any(Object),
            logMessage: expect.any(Object),
            creationDate: expect.any(Object),
            creationUsername: expect.any(Object),
            version: expect.any(Object),
            inputDataUpload: expect.any(Object),
          }),
        );
      });

      it('passing IInputDataUploadLog should create a new form with FormGroup', () => {
        const formGroup = service.createInputDataUploadLogFormGroup(sampleWithRequiredData);

        expect(formGroup.controls).toEqual(
          expect.objectContaining({
            id: expect.any(Object),
            logMessage: expect.any(Object),
            creationDate: expect.any(Object),
            creationUsername: expect.any(Object),
            version: expect.any(Object),
            inputDataUpload: expect.any(Object),
          }),
        );
      });
    });

    describe('getInputDataUploadLog', () => {
      it('should return NewInputDataUploadLog for default InputDataUploadLog initial value', () => {
        const formGroup = service.createInputDataUploadLogFormGroup(sampleWithNewData);

        const inputDataUploadLog = service.getInputDataUploadLog(formGroup) as any;

        expect(inputDataUploadLog).toMatchObject(sampleWithNewData);
      });

      it('should return NewInputDataUploadLog for empty InputDataUploadLog initial value', () => {
        const formGroup = service.createInputDataUploadLogFormGroup();

        const inputDataUploadLog = service.getInputDataUploadLog(formGroup) as any;

        expect(inputDataUploadLog).toMatchObject({});
      });

      it('should return IInputDataUploadLog', () => {
        const formGroup = service.createInputDataUploadLogFormGroup(sampleWithRequiredData);

        const inputDataUploadLog = service.getInputDataUploadLog(formGroup) as any;

        expect(inputDataUploadLog).toMatchObject(sampleWithRequiredData);
      });
    });

    describe('resetForm', () => {
      it('passing IInputDataUploadLog should not enable id FormControl', () => {
        const formGroup = service.createInputDataUploadLogFormGroup();
        expect(formGroup.controls.id.disabled).toBe(true);

        service.resetForm(formGroup, sampleWithRequiredData);

        expect(formGroup.controls.id.disabled).toBe(true);
      });

      it('passing NewInputDataUploadLog should disable id FormControl', () => {
        const formGroup = service.createInputDataUploadLogFormGroup(sampleWithRequiredData);
        expect(formGroup.controls.id.disabled).toBe(true);

        service.resetForm(formGroup, { id: null });

        expect(formGroup.controls.id.disabled).toBe(true);
      });
    });
  });
});
