<commit_before>import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientModule, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';

import 'jasmine';

import { InfoWindowComponent } from './info-window.component';
import { Injectable, Injector } from '@angular/core';
import { Observable } from 'rxjs';
import { BlobAction } from '../blob-action';
import { of } from 'rxjs/internal/observable/of';
import { MarkerMode } from '../marker-mode';

// Mock the HttpClient's interceptor so that HTTP requests are handled locally and not in the real back end.
@Injectable()
export class MockInterceptor implements HttpInterceptor {

  private responseUrl = {
    imageUrl: "imageUrl"
  }
  private responseKey = {
    blobKey: "blobKey"
  }

  constructor() { }

  // Handles get / post requests
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    if (req.method === "GET" && req.url === '/blob-service?blobAction=' + BlobAction.GET_URL) {
      return of(new HttpResponse({ status: 200, body: this.responseUrl }));
    }
    else if (req.method === "POST" && req.url === this.responseUrl.imageUrl) {
      return of(new HttpResponse({ status: 200, body: this.responseKey }));
    }

    next.handle(req);
  }
}

describe('InfoWindowComponent', () => {
  let component: InfoWindowComponent;
  let fixture: ComponentFixture<InfoWindowComponent>;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [InfoWindowComponent],
      imports: [HttpClientModule],
      providers: [{
        provide: HTTP_INTERCEPTORS,
        useClass: MockInterceptor,
        multi: true
      }]
    });
    fixture = TestBed.createComponent(InfoWindowComponent);
    component = fixture.componentInstance;
  });

  it('Should create an infoWindowComponent instance', () => {
    expect(component).toBeTruthy();
  });

  it('Should initialize blobKeyValue with the original blob key', () => {

    component.originalBlobKey = "originalKey";
    component.ngOnInit();
    expect(component.getBlobKeyValue()).toBe("originalKey");
  });

  it('Should emit on submit', () => {

    spyOn(component.submitEvent, 'emit');
    // Trigger the submit event
    component.submit("animal", "description", "reporter");

    fixture.detectChanges();

    expect(component.submitEvent.emit).toHaveBeenCalledWith({ animal: "animal", description: "description", reporter: "reporter", blobKey: component.getBlobKeyValue() });
  });

  it('Should emit on delete', () => {

    spyOn(component.deleteEvent, 'emit');
    // Trigger the delete event
    component.delete();

    fixture.detectChanges();

    expect(component.deleteEvent.emit).toHaveBeenCalled();
  });

  it('Should emit on update', () => {

    spyOn(component.updateEvent, 'emit');
    // Trigger the update event
    component.update();

    fixture.detectChanges();

    expect(component.updateEvent.emit).toHaveBeenCalled();
  });

  it('Should emit on cancel', () => {

    spyOn(component.cancelEvent, 'emit');
    // Trigger the cancel event
    component.cancel();

    fixture.detectChanges();

    expect(component.cancelEvent.emit).toHaveBeenCalled();
  });

  it('Should post the file that was uploaded', async () => {

    // Create an instance of type 'create' so that it has the 'file-name' element
    component.type = MarkerMode.CREATE;
    fixture.detectChanges();

    // Create a file to post
    const fileList: FileList = {
      length: 1,
      item(index: number): File {
        return fileList[index];
      }
    };
    fileList[0] = new File(["file data"], "file.txt");

    // Mock the document.getElementById function to avoid accessing the tests page's document instead of the component's document
    const dummyElement = fixture.debugElement.nativeElement.querySelector('#file-name');
    spyOn(document, "getElementById").and.returnValue(dummyElement);

    await component.postFile(fileList)

    expect(component.getBlobKeyValue()).toBe("blobKey");
  });

  it('Should remove the file selected and set blobKeyValue to the original blob key', () => {

    // Create an instance of type 'create' so that it has the 'file-name' element
    component.type = MarkerMode.CREATE;
    fixture.detectChanges();

    // Create an empty files list
    const fileList: FileList = {
      length: 1,
      item(index: number): File {
        return fileList[index];
      }
    };

    // Mock the document.getElementById function to avoid accessing the tests page's document instead of the component's document
    const dummyElement = fixture.debugElement.nativeElement.querySelector('#file-name');
    spyOn(document, "getElementById").and.returnValue(dummyElement);


    component.originalBlobKey = "originalKey";
    component.postFile(fileList);

    expect(component.getBlobKeyValue()).toBe("originalKey");
  });

  it('Should remove the image of the report', () => {

    const dummyEvent = {<commit_msg>Remove empty line<commit_after>import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientModule, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';

import 'jasmine';

import { InfoWindowComponent } from './info-window.component';
import { Injectable, Injector } from '@angular/core';
import { Observable } from 'rxjs';
import { BlobAction } from '../blob-action';
import { of } from 'rxjs/internal/observable/of';
import { MarkerMode } from '../marker-mode';

// Mock the HttpClient's interceptor so that HTTP requests are handled locally and not in the real back end.
@Injectable()
export class MockInterceptor implements HttpInterceptor {

  private responseUrl = {
    imageUrl: "imageUrl"
  }
  private responseKey = {
    blobKey: "blobKey"
  }

  constructor() { }

  // Handles get / post requests
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    if (req.method === "GET" && req.url === '/blob-service?blobAction=' + BlobAction.GET_URL) {
      return of(new HttpResponse({ status: 200, body: this.responseUrl }));
    }
    else if (req.method === "POST" && req.url === this.responseUrl.imageUrl) {
      return of(new HttpResponse({ status: 200, body: this.responseKey }));
    }

    next.handle(req);
  }
}

describe('InfoWindowComponent', () => {
  let component: InfoWindowComponent;
  let fixture: ComponentFixture<InfoWindowComponent>;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [InfoWindowComponent],
      imports: [HttpClientModule],
      providers: [{
        provide: HTTP_INTERCEPTORS,
        useClass: MockInterceptor,
        multi: true
      }]
    });
    fixture = TestBed.createComponent(InfoWindowComponent);
    component = fixture.componentInstance;
  });

  it('Should create an infoWindowComponent instance', () => {
    expect(component).toBeTruthy();
  });

  it('Should initialize blobKeyValue with the original blob key', () => {

    component.originalBlobKey = "originalKey";
    component.ngOnInit();
    expect(component.getBlobKeyValue()).toBe("originalKey");
  });

  it('Should emit on submit', () => {

    spyOn(component.submitEvent, 'emit');
    // Trigger the submit event
    component.submit("animal", "description", "reporter");

    fixture.detectChanges();

    expect(component.submitEvent.emit).toHaveBeenCalledWith({ animal: "animal", description: "description", reporter: "reporter", blobKey: component.getBlobKeyValue() });
  });

  it('Should emit on delete', () => {

    spyOn(component.deleteEvent, 'emit');
    // Trigger the delete event
    component.delete();

    fixture.detectChanges();

    expect(component.deleteEvent.emit).toHaveBeenCalled();
  });

  it('Should emit on update', () => {

    spyOn(component.updateEvent, 'emit');
    // Trigger the update event
    component.update();

    fixture.detectChanges();

    expect(component.updateEvent.emit).toHaveBeenCalled();
  });

  it('Should emit on cancel', () => {

    spyOn(component.cancelEvent, 'emit');
    // Trigger the cancel event
    component.cancel();

    fixture.detectChanges();

    expect(component.cancelEvent.emit).toHaveBeenCalled();
  });

  it('Should post the file that was uploaded', async () => {

    // Create an instance of type 'create' so that it has the 'file-name' element
    component.type = MarkerMode.CREATE;
    fixture.detectChanges();

    // Create a file to post
    const fileList: FileList = {
      length: 1,
      item(index: number): File {
        return fileList[index];
      }
    };
    fileList[0] = new File(["file data"], "file.txt");

    // Mock the document.getElementById function to avoid accessing the tests page's document instead of the component's document
    const dummyElement = fixture.debugElement.nativeElement.querySelector('#file-name');
    spyOn(document, "getElementById").and.returnValue(dummyElement);

    await component.postFile(fileList)

    expect(component.getBlobKeyValue()).toBe("blobKey");
  });

  it('Should remove the file selected and set blobKeyValue to the original blob key', () => {

    // Create an instance of type 'create' so that it has the 'file-name' element
    component.type = MarkerMode.CREATE;
    fixture.detectChanges();

    // Create an empty files list
    const fileList: FileList = {
      length: 1,
      item(index: number): File {
        return fileList[index];
      }
    };

    // Mock the document.getElementById function to avoid accessing the tests page's document instead of the component's document
    const dummyElement = fixture.debugElement.nativeElement.querySelector('#file-name');
    spyOn(document, "getElementById").and.returnValue(dummyElement);

    component.originalBlobKey = "originalKey";
    component.postFile(fileList);

    expect(component.getBlobKeyValue()).toBe("originalKey");
  });

  it('Should remove the image of the report', () => {

    const dummyEvent = {
{'fraction_non_alphanumeric': 0.13313403089187842, 'fraction_numerical': 0.0017937219730941704, 'mean_word_length': 3.7518939393939394, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1699350', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2768, 'n_words': 724}