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

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

import { OrganizationTypeFormService } from './organization-type-form.service';

describe('OrganizationType Form Service', () => {
  let service: OrganizationTypeFormService;

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

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

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

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

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

    describe('getOrganizationType', () => {
      it('should return NewOrganizationType for default OrganizationType initial value', () => {
        const formGroup = service.createOrganizationTypeFormGroup(sampleWithNewData);

        const organizationType = service.getOrganizationType(formGroup) as any;

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

      it('should return NewOrganizationType for empty OrganizationType initial value', () => {
        const formGroup = service.createOrganizationTypeFormGroup();

        const organizationType = service.getOrganizationType(formGroup) as any;

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

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

        const organizationType = service.getOrganizationType(formGroup) as any;

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

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

        service.resetForm(formGroup, sampleWithRequiredData);

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

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

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

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