<commit_before>describe('Generic location view', function () {

  describe('opening an info window', function () {
    beforeEach(function () {
      spyOn(GenericLocationView.prototype, "render");

      this.view = new GenericLocationView({
        model: new Backbone.Model()
      });

    });

    it('should open infoWindow', function () {
      this.view.infoWindow = new InfoWindowView({
        appModel: new AppModel()
      });

      spyOn(this.view.infoWindow, "open");

      this.view.openInfoWindow(0, 1, 2);

      expect(this.view.infoWindow.open).toHaveBeenCalledWith(0, 1, 2);
    });

    it('should translate info window body', function () {
      this.view.infoWindow = new InfoWindowView({ appModel: new AppModel({text: 'på svenska', textEn: 'in english'})});

      var expected = this.view.infoWindow.getRootLanguage() == 'sv' ? 'på svenska' : 'in english';
      var text = this.view.infoWindow.getLanguageKey();
      expect(this.view.infoWindow.appModel.get(text)).toEqual(expected);
    });
  });

  describe('remove', function () {
    beforeEach(function () {
      spyOn(GenericLocationView.prototype, "render");

      this.view = new GenericLocationView({
        model: new Backbone.Model(),
        infoWindow: new InfoWindowView({
          appModel: new AppModel()
        })
      });

    });

    it('should close info window on remove', function () {
      spyOn(this.view.infoWindow, "close");
      this.view.marker = {};
      this.view.marker.setMap = function (foo) {
      };

      this.view.remove();

      expect(this.view.infoWindow.close).toHaveBeenCalled();
    });

    it('should clear map for marker', function () {
      var setMapHasRun = false;

      this.view.marker = {};
      this.view.marker.setMap = function (foo) {
        setMapHasRun = true;
      };

      this.view.remove();

      expect(setMapHasRun).toBeTruthy();
    });

    it('should nullify marker', function () {
      this.view.marker = {};
      this.view.marker.setMap = function (foo) {
      };

      this.view.remove();

      expect(this.view.marker).toBeNull();
    });
  });

  describe('updateVisibility', function () {
    beforeEach(function () {
      GenericLocationView.prototype.render = function () {
      };

      this.view = new GenericLocationView({
        model: new Location(),
        infoWindow: new InfoWindowView({
          appModel: new AppModel()
        })
      });

    });

    it('should set visibility of model on marker', function () {
      this.view.marker = new google.maps.Marker();
      spyOn(this.view.marker, 'setVisible');

      this.view.model.set('visible', true);
      this.view.updateVisibility();
      expect(this.view.marker.setVisible).toHaveBeenCalledWith(true);

      this.view.model.set('visible', false);
      this.view.updateVisibility();
      expect(this.view.marker.setVisible).toHaveBeenCalledWith(false);
    });
  });
});<commit_msg>Testing the marker click event.<commit_after>describe('Generic location view', function () {

  describe('opening an info window', function () {
    beforeEach(function () {
      spyOn(GenericLocationView.prototype, "render");

      this.view = new GenericLocationView({
        model: new Backbone.Model()
      });

    });

    it('should open infoWindow', function () {
      this.view.infoWindow = new InfoWindowView({
        appModel: new AppModel()
      });

      spyOn(this.view.infoWindow, "open");

      this.view.openInfoWindow(0, 1, 2);

      expect(this.view.infoWindow.open).toHaveBeenCalledWith(0, 1, 2);
    });

    it('should translate info window body', function () {
      this.view.infoWindow = new InfoWindowView({ appModel: new AppModel({text: 'på svenska', textEn: 'in english'})});

      var expected = this.view.infoWindow.getRootLanguage() == 'sv' ? 'på svenska' : 'in english';
      var text = this.view.infoWindow.getLanguageKey();
      expect(this.view.infoWindow.appModel.get(text)).toEqual(expected);
    });
  });

  describe('remove', function () {
    beforeEach(function () {
      spyOn(GenericLocationView.prototype, "render");

      this.view = new GenericLocationView({
        model: new Backbone.Model(),
        infoWindow: new InfoWindowView({
          appModel: new AppModel()
        })
      });

    });

    it('should close info window on remove', function () {
      spyOn(this.view.infoWindow, "close");
      this.view.marker = {};
      this.view.marker.setMap = function (foo) {
      };

      this.view.remove();

      expect(this.view.infoWindow.close).toHaveBeenCalled();
    });

    it('should clear map for marker', function () {
      var setMapHasRun = false;

      this.view.marker = {};
      this.view.marker.setMap = function (foo) {
        setMapHasRun = true;
      };

      this.view.remove();

      expect(setMapHasRun).toBeTruthy();
    });

    it('should nullify marker', function () {
      this.view.marker = {};
      this.view.marker.setMap = function (foo) {
      };

      this.view.remove();

      expect(this.view.marker).toBeNull();
    });
  });

  describe('updateVisibility', function () {
    beforeEach(function () {
      GenericLocationView.prototype.render = function () {
      };

      this.view = new GenericLocationView({
        model: new Location(),
        infoWindow: new InfoWindowView({
          appModel: new AppModel()
        })
      });

    });

    it('should set visibility of model on marker', function () {
      this.view.marker = new google.maps.Marker();
      spyOn(this.view.marker, 'setVisible');

      this.view.model.set('visible', true);
      this.view.updateVisibility();
      expect(this.view.marker.setVisible).toHaveBeenCalledWith(true);

      this.view.model.set('visible', false);
      this.view.updateVisibility();
      expect(this.view.marker.setVisible).toHaveBeenCalledWith(false);
    });
  });

  describe('handleMarkerClick', function () {
    beforeEach(function () {
      GenericLocationView.prototype.render = function () {
      };

      this.view = new GenericLocationView({
        model: new Location(),
        infoWindow: new InfoWindowView({
          appModel: new AppModel()
        })
      });

    });

    it('should set trigger the "clicked" event on its model', function () {
      spyOn(this.view, 'openInfoWindow');

      var clicked = false;
      this.view.model.on('clicked', function () {
        clicked = true;
      });

      this.view.handleMarkerClick({latLng: ''});

      expect(clicked).toBeTruthy();
    });

    it('should call openInfoWindow', function () {
      spyOn(this.view, 'openInfoWindow');

      this.view.handleMarkerClick({latLng: ''});

      expect(this.view.openInfoWindow).toHaveBeenCalledWith(this.view.model, this.view.marker, '');
    });

    it('should set destination on infoWindow if directionAware=true', function () {
      spyOn(this.view, 'openInfoWindow');
      spyOn(this.view.infoWindow, 'setDestination');
      this.view.model.set('directionAware', true);

      this.view.handleMarkerClick({latLng: ''});

      expect(this.view.infoWindow.setDestination).toHaveBeenCalledWith('');
    });

    it('should not set destination on infoWindow if directionAware=false', function () {
      spyOn(this.view, 'openInfoWindow');
      spyOn(this.view.infoWindow, 'setDestination');
      this.view.model.set('directionAware', false);

      this.view.handleMarkerClick({latLng: ''});

      expect(this.view.infoWindow.setDestination).not.toHaveBeenCalled();
    });
  });
});
{'fraction_non_alphanumeric': 0.15149105367793242, 'fraction_numerical': 0.0015904572564612327, 'mean_word_length': 2.788152610441767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4329825', 'n_tokens_mistral': 2251, 'n_tokens_neox': 2196, 'n_words': 408}