/*
 * Copyright (C) 2023 Robert Bosch GmbH Copyright (C) 2023 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component } from '@angular/core';
import { BciTouchedFlagDirective } from './bci-touched-flag.directive';

@Component({
  template: '<input id="targetedInput" bciTouchedFlag (isTouched)="mockMethod($event)">',
})
class TestComponent {
  inputTouched = false;

  mockMethod(event): void {
    this.inputTouched = event;
  }
}

describe('BciTouchedFlagDirective', () => {
  let fixture: ComponentFixture<TestComponent>;
  let directive: BciTouchedFlagDirective;
  let component: TestComponent;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [TestComponent],
      imports: [BciTouchedFlagDirective]
    });
    fixture = TestBed.createComponent(TestComponent);
    directive = fixture.debugElement.nativeElement.querySelector('[bciTouchedFlag]');
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create an instance', (): void => {
    expect(directive).toBeTruthy();
  });

  it('should emit true when input is touched', (): void => {
    const input = fixture.debugElement.nativeElement.querySelector('#targetedInput');
    input.click();

    expect(component.inputTouched).toBeTruthy();
  });
});
