Skip to content
Snippets Groups Projects
search-field.component.spec.ts 1.46 KiB
Newer Older
  • Learn to ignore specific revisions
  • OZGCloud's avatar
    OZGCloud committed
    import { EMPTY_STRING } from '@alfa-client/tech-shared';
    
    import { getElementFromFixtureByType, mock } from '@alfa-client/test-utils';
    import { EventEmitter } from '@angular/core';
    
    import { ComponentFixture, TestBed } from '@angular/core/testing';
    
    OZGCloud's avatar
    OZGCloud committed
    import { FormControl } from '@angular/forms';
    import { TextInputComponent } from '../../form/text-input/text-input.component';
    
    import { SearchFieldComponent } from './search-field.component';
    
    describe('SearchFieldComponent', () => {
      let component: SearchFieldComponent;
      let fixture: ComponentFixture<SearchFieldComponent>;
    
      beforeEach(async () => {
        await TestBed.configureTestingModule({
          imports: [SearchFieldComponent],
        }).compileComponents();
    
        fixture = TestBed.createComponent(SearchFieldComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
      });
    
      it('should create', () => {
        expect(component).toBeTruthy();
      });
    
    OZGCloud's avatar
    OZGCloud committed
    
    
      describe('inputClicked', () => {
    
    OZGCloud's avatar
    OZGCloud committed
        it('should emit event', () => {
    
          component.inputClicked = <any>mock(EventEmitter);
    
    OZGCloud's avatar
    OZGCloud committed
          const input = getElementFromFixtureByType(fixture, TextInputComponent);
    
    
          input.inputElement.nativeElement.click();
    
    OZGCloud's avatar
    OZGCloud committed
    
    
          expect(component.inputClicked.emit).toHaveBeenCalled();
    
    OZGCloud's avatar
    OZGCloud committed
        });
      });
    
      describe('clearValue', () => {
        it('should set empty value', () => {
          component.control = new FormControl('test');
    
          component.clearInput();
    
          expect(component.control.value).toBe(EMPTY_STRING);
        });
      });