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

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

import { VariableCategoryFormService } from './variable-category-form.service';

describe('VariableCategory Form Service', () => {
  let service: VariableCategoryFormService;

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

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

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

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

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

    describe('getVariableCategory', () => {
      it('should return NewVariableCategory for default VariableCategory initial value', () => {
        const formGroup = service.createVariableCategoryFormGroup(sampleWithNewData);

        const variableCategory = service.getVariableCategory(formGroup) as any;

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

      it('should return NewVariableCategory for empty VariableCategory initial value', () => {
        const formGroup = service.createVariableCategoryFormGroup();

        const variableCategory = service.getVariableCategory(formGroup) as any;

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

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

        const variableCategory = service.getVariableCategory(formGroup) as any;

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

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

        service.resetForm(formGroup, sampleWithRequiredData);

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

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

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

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