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

import { sampleWithRequiredData, sampleWithNewData } from '../variable-class-type.test-samples';

import { VariableClassTypeFormService } from './variable-class-type-form.service';

describe('VariableClassType Form Service', () => {
  let service: VariableClassTypeFormService;

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

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

        expect(formGroup.controls).toEqual(
          expect.objectContaining({
            id: expect.any(Object),
            name: expect.any(Object),
            description: expect.any(Object),
            label: expect.any(Object),
            version: expect.any(Object),
          }),
        );
      });

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

        expect(formGroup.controls).toEqual(
          expect.objectContaining({
            id: expect.any(Object),
            name: expect.any(Object),
            description: expect.any(Object),
            label: expect.any(Object),
            version: expect.any(Object),
          }),
        );
      });
    });

    describe('getVariableClassType', () => {
      it('should return NewVariableClassType for default VariableClassType initial value', () => {
        const formGroup = service.createVariableClassTypeFormGroup(sampleWithNewData);

        const variableClassType = service.getVariableClassType(formGroup) as any;

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

      it('should return NewVariableClassType for empty VariableClassType initial value', () => {
        const formGroup = service.createVariableClassTypeFormGroup();

        const variableClassType = service.getVariableClassType(formGroup) as any;

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

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

        const variableClassType = service.getVariableClassType(formGroup) as any;

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

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

        service.resetForm(formGroup, sampleWithRequiredData);

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

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

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

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