<commit_before>var AddCustomBasemapView = require('../../../../../../javascripts/cartodb/common/dialogs/add_custom_basemap/add_custom_basemap_view.js');
var AddCustomBasemapModel = require('../../../../../../javascripts/cartodb/common/dialogs/add_custom_basemap/add_custom_basemap_model.js');
var Backbone = require('backbone');
var $ = require('jquery');

describe('common/dialog/add_custom_basemap/add_custom_basemap_view', function() {
  beforeEach(function() {
    spyOn(AddCustomBasemapModel.prototype, 'initialize').and.callThrough();
    this.map = new cdb.admin.Map();
    this.baseLayers = new Backbone.Collection({
      urlRoot: 'localhost/user/layers'
    });
    this.view = new AddCustomBasemapView({
      map: this.map,
      baseLayers: this.baseLayers
    });
    this.view.render();
  });

  it('should render the tabs', function() {
    expect(this.innerHTML()).toContain('XYZ');
  });

  it('should create view model with map and baselayers', function() {
    expect(AddCustomBasemapModel.prototype.initialize).toHaveBeenCalled();
    expect(AddCustomBasemapModel.prototype.initialize).toHaveBeenCalledWith(jasmine.objectContaining({ map: this.map }));
    expect(AddCustomBasemapModel.prototype.initialize).toHaveBeenCalledWith(jasmine.objectContaining({ baseLayers: this.baseLayers }));
  });

  it('should start on XYZ view', function() {
    expect(this.innerHTML()).toContain('Insert your XYZ URL');
    expect(this.innerHTML()).toContain('js-xyz is-selected');
  });

  it('should not have any leaks', function() {
    expect(this.view).toHaveNoLeaks();
  });

  describe('when click OK', function() {
    beforeEach(function() {
      this.layer = new cdb.admin.TileLayer();
      this.deferred = $.Deferred();
      spyOn(this.layer, 'save').and.returnValue(this.deferred);
      this.view.model.activeTabModel().set({
        layer: this.layer
      });
      spyOn(this.view.model, 'saveLayer').and.callThrough();
      spyOn(this.view, 'close');
      this.view.$('.ok').click();
    });

    it('should save layer', function() {
      expect(this.view.model.saveLayer).toHaveBeenCalled();
      expect(this.view.model.saveLayer.calls.argsFor(0)[0]).toEqual(this.layer);
      expect(this.view.model.saveLayer.calls.argsFor(0)[1]).toEqual(jasmine.objectContaining({
        success: jasmine.any(Function),
        error: jasmine.any(Function)
      }));
      expect(this.layer.save).toHaveBeenCalled();
    });

    it('should show saving…', function() {
      expect(this.innerHTML()).toContain('Saving…');
    });

    it('should only save once', function() {
      this.view.$('.ok').click();
      expect(this.view.model.saveLayer.calls.count()).toEqual(1);
    });

    describe('when save succeeds', function() {
      beforeEach(function() {
        this.deferred.resolveWith();
      });

      it('should close view', function() {
        expect(this.view.close).toHaveBeenCalled();
      });<commit_msg>Change saving text to setting basemap<commit_after>var AddCustomBasemapView = require('../../../../../../javascripts/cartodb/common/dialogs/add_custom_basemap/add_custom_basemap_view.js');
var AddCustomBasemapModel = require('../../../../../../javascripts/cartodb/common/dialogs/add_custom_basemap/add_custom_basemap_model.js');
var Backbone = require('backbone');
var $ = require('jquery');

describe('common/dialog/add_custom_basemap/add_custom_basemap_view', function() {
  beforeEach(function() {
    spyOn(AddCustomBasemapModel.prototype, 'initialize').and.callThrough();
    this.map = new cdb.admin.Map();
    this.baseLayers = new Backbone.Collection({
      urlRoot: 'localhost/user/layers'
    });
    this.view = new AddCustomBasemapView({
      map: this.map,
      baseLayers: this.baseLayers
    });
    this.view.render();
  });

  it('should render the tabs', function() {
    expect(this.innerHTML()).toContain('XYZ');
  });

  it('should create view model with map and baselayers', function() {
    expect(AddCustomBasemapModel.prototype.initialize).toHaveBeenCalled();
    expect(AddCustomBasemapModel.prototype.initialize).toHaveBeenCalledWith(jasmine.objectContaining({ map: this.map }));
    expect(AddCustomBasemapModel.prototype.initialize).toHaveBeenCalledWith(jasmine.objectContaining({ baseLayers: this.baseLayers }));
  });

  it('should start on XYZ view', function() {
    expect(this.innerHTML()).toContain('Insert your XYZ URL');
    expect(this.innerHTML()).toContain('js-xyz is-selected');
  });

  it('should not have any leaks', function() {
    expect(this.view).toHaveNoLeaks();
  });

  describe('when click OK', function() {
    beforeEach(function() {
      this.layer = new cdb.admin.TileLayer();
      this.deferred = $.Deferred();
      spyOn(this.layer, 'save').and.returnValue(this.deferred);
      this.view.model.activeTabModel().set({
        layer: this.layer
      });
      spyOn(this.view.model, 'saveLayer').and.callThrough();
      spyOn(this.view, 'close');
      this.view.$('.ok').click();
    });

    it('should save layer', function() {
      expect(this.view.model.saveLayer).toHaveBeenCalled();
      expect(this.view.model.saveLayer.calls.argsFor(0)[0]).toEqual(this.layer);
      expect(this.view.model.saveLayer.calls.argsFor(0)[1]).toEqual(jasmine.objectContaining({
        success: jasmine.any(Function),
        error: jasmine.any(Function)
      }));
      expect(this.layer.save).toHaveBeenCalled();
    });

    it('should show saving…', function() {
      expect(this.innerHTML()).toContain('Setting basemap…');
    });

    it('should only save once', function() {
      this.view.$('.ok').click();
      expect(this.view.model.saveLayer.calls.count()).toEqual(1);
    });

    describe('when save succeeds', function() {
      beforeEach(function() {
        this.deferred.resolveWith();
      });

      it('should close view', function() {
        expect(this.view.close).toHaveBeenCalled();
      });
{'fraction_non_alphanumeric': 0.17282700421940927, 'fraction_numerical': 0.0016877637130801688, 'mean_word_length': 3.7294493216280924, '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': '2410074', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1843, 'n_words': 262}