<commit_before>import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockHttpInterceptor } from '../mock-http-interceptor';
import { ToastService } from '../toast/toast.service';
import { } from 'googlemaps';

import { MapComponent } from './map.component';
import { InfoWindowComponent } from '../info-window/info-window.component';

// Mock toast service for location error
class MockToastService {
  showToast() { }
}

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

  beforeEach(() => {
    fakeMarker = {
      animal: "",
      description: "",
      reporter: "",
      lat: 40,
      lng: 90,
      blobKey: "",
      userId: {value: "0"}
    };
    TestBed.configureTestingModule({
      declarations: [MapComponent, InfoWindowComponent],
      imports: [HttpClientModule],
      providers: [{
        provide: HTTP_INTERCEPTORS,
        useClass: MockHttpInterceptor,
        multi: true
      }, {
        provide: ToastService,
        useClass: MockToastService
      }]
    });
    fixture = TestBed.createComponent(MapComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should center on user location', () => {
    spyOn(navigator.geolocation, 'getCurrentPosition').and.callFake(function(success) {
      const position = {
        coords: {
          accuracy: 1,
          altitude: 1,
          altitudeAccuracy: 1,
          heading: 1,
          speed: 0,
          latitude: 20,
          longitude: 85
        }, timestamp: 1
      };
      success(position);
    });

    component.focusOnUserLocation();
    const location = new google.maps.LatLng(20, 85)
    
    expect(component["gMap"].getCenter().lat()).toEqual(location.lat());
    expect(component["gMap"].getCenter().lng()).toEqual(location.lng());
  });

  it('should handle location error', () => {
    spyOn(navigator.geolocation, 'getCurrentPosition').and.callFake(function (success, error) {
      const err = {
        code: 0,
        PERMISSION_DENIED: 1,
        POSITION_UNAVAILABLE: 2,
        TIMEOUT: 3,
        message: ""
      };
      error(err);
    });

    component.focusOnUserLocation();<commit_msg>Change variable name from 'location' to 'expectedLocation'<commit_after>import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockHttpInterceptor } from '../mock-http-interceptor';
import { ToastService } from '../toast/toast.service';
import { } from 'googlemaps';

import { MapComponent } from './map.component';
import { InfoWindowComponent } from '../info-window/info-window.component';

// Mock toast service for location error
class MockToastService {
  showToast() { }
}

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

  beforeEach(() => {
    fakeMarker = {
      animal: "",
      description: "",
      reporter: "",
      lat: 40,
      lng: 90,
      blobKey: "",
      userId: {value: "0"}
    };
    TestBed.configureTestingModule({
      declarations: [MapComponent, InfoWindowComponent],
      imports: [HttpClientModule],
      providers: [{
        provide: HTTP_INTERCEPTORS,
        useClass: MockHttpInterceptor,
        multi: true
      }, {
        provide: ToastService,
        useClass: MockToastService
      }]
    });
    fixture = TestBed.createComponent(MapComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should center on user location', () => {
    spyOn(navigator.geolocation, 'getCurrentPosition').and.callFake(function(success) {
      const position = {
        coords: {
          accuracy: 1,
          altitude: 1,
          altitudeAccuracy: 1,
          heading: 1,
          speed: 0,
          latitude: 20,
          longitude: 85
        }, timestamp: 1
      };
      success(position);
    });

    component.focusOnUserLocation();
    const expectedLocation = new google.maps.LatLng(20, 85)
    
    expect(component["gMap"].getCenter().lat()).toEqual(expectedLocation.lat());
    expect(component["gMap"].getCenter().lng()).toEqual(expectedLocation.lng());
  });

  it('should handle location error', () => {
    spyOn(navigator.geolocation, 'getCurrentPosition').and.callFake(function (success, error) {
      const err = {
        code: 0,
        PERMISSION_DENIED: 1,
        POSITION_UNAVAILABLE: 2,
        TIMEOUT: 3,
        message: ""
      };
      error(err);
    });

    component.focusOnUserLocation();
{'fraction_non_alphanumeric': 0.1391911311845617, 'fraction_numerical': 0.009443646068569083, 'mean_word_length': 2.839243498817967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '377726', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1410, 'n_words': 287}