<commit_before>describe("Basemap adder dialog", function() {
  var basemap_dialog, table, server, base_layers;

  beforeEach(function() {
    table = TestUtil.createTable('test');

    base_layers = new Backbone.Collection()
    base_layers.url = '/test';

    basemap_dialog = new cdb.admin.BaseMapAdder({
      model: this.model,
      baseLayers: base_layers,
      ok: function(layer) {}
    });
    server = sinon.fakeServer.create();

  });


  it("should open the basemap chooser dialog", function() {
    basemap_dialog.render();
    expect(basemap_dialog.$el.find(".modal:eq(0) div.head h3").text()).toEqual('Add your basemap');
  });

  it("should render the tabs and the panes", function() {
    basemap_dialog.render();
    expect(basemap_dialog.$el.find(".basemap-tab").size()).toBe(4);
  });

  it("should activate mapbox pane by default and change pane", function() {
    basemap_dialog.render();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("xyz");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('block');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.mapboxPane.$el.find("input[name='url']").attr('placeholder')).toEqual('Insert your Mapbox map URL or map id');
    expect(basemap_dialog.mapboxPane.$el.find("input[name='access_token']").attr('placeholder')).toEqual('Insert your Mapbox access token');
    basemap_dialog.$el.find(".mapbox").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("mapbox");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('block');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.find("input").attr('placeholder')).toEqual('Insert your XYZ URL template');
    basemap_dialog.$el.find(".wms").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("wms");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('block');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.find("input").attr('placeholder')).toEqual('Insert your WMS base URL');
    basemap_dialog.$el.find(".nasa").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("nasa");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('block');
    basemap_dialog.$el.find(".mapbox").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("mapbox");
  });

  it("should have the ok button disabled when the input has no value, and enabled when it has", function() {
    //
  });

  it("should fix https url", function() {
    var url = cdb.admin.ZXYBasemapChooserPane.prototype._fixHTTPS('http://test.com/1.json', { protocol: 'https:' });
    expect(url).toEqual('https://test.com/1.json');

    url = cdb.admin.ZXYBasemapChooserPane.prototype._fixHTTPS('http://test.com/1.json', { protocol: 'http:' });
    expect(url).toEqual('http://test.com/1.json');
  });

  it("should fix mapbox https url", function() {
    var url = cdb.admin.MapboxBasemapChooserPane.prototype._fixHTTPS(
      'http://a.tiles.mapbox.com/v4/examples.map-4l7djmvo.json',
      { protocol: 'https:' }
    );

    expect(url).toEqual('https://dnv9my2eseobd.cloudfront.net/v4/examples.map-4l7djmvo.json');

    url = cdb.admin.MapboxBasemapChooserPane.prototype._fixHTTPS(
      'http://a.tiles.mapbox.com/v4/examples.map-4l7djmvo.json',
      { protocol: 'http:' }
    );
    expect(url).toEqual(
      'http://a.tiles.mapbox.com/v4/examples.map-4l7djmvo.json'
    )
  });

  it("should send mapbox url if user provides the mapbox edit url", function(done) {
    var s = sinon.spy();<commit_msg>Adds a couple of WMS related specs<commit_after>describe("Basemap adder dialog", function() {
  var basemap_dialog, table, server, base_layers;

  beforeEach(function() {
    table = TestUtil.createTable('test');

    base_layers = new Backbone.Collection()
    base_layers.url = '/test';

    basemap_dialog = new cdb.admin.BaseMapAdder({
      model: this.model,
      baseLayers: base_layers,
      ok: function(layer) {}
    });
    server = sinon.fakeServer.create();

  });


  it("should open the basemap chooser dialog", function() {
    basemap_dialog.render();
    expect(basemap_dialog.$el.find(".modal:eq(0) div.head h3").text()).toEqual('Add your basemap');
  });

  it("should render the tabs and the panes", function() {
    basemap_dialog.render();
    expect(basemap_dialog.$el.find(".basemap-tab").size()).toBe(4);
  });

  it("should activate mapbox pane by default and change pane", function() {
    basemap_dialog.render();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("xyz");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('block');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.mapboxPane.$el.find("input[name='url']").attr('placeholder')).toEqual('Insert your Mapbox map URL or map id');
    expect(basemap_dialog.mapboxPane.$el.find("input[name='access_token']").attr('placeholder')).toEqual('Insert your Mapbox access token');
    basemap_dialog.$el.find(".mapbox").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("mapbox");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('block');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.find("input").attr('placeholder')).toEqual('Insert your XYZ URL template');
    basemap_dialog.$el.find(".wms").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("wms");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('block');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.find("input").attr('placeholder')).toEqual('Insert your WMS base URL');
    basemap_dialog.$el.find(".nasa").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("nasa");
    expect(basemap_dialog.mapboxPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.zxyPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.wmsPane.$el.css('display')).toBe('none');
    expect(basemap_dialog.nasaPane.$el.css('display')).toBe('block');
    basemap_dialog.$el.find(".mapbox").click();
    expect(basemap_dialog.basemap_panes.activeTab).toEqual("mapbox");
  });

  it("should have the ok button disabled when the input has no value, and enabled when it has", function() {
    //
  });

  it("should trigger a success event if the WMS is valid", function(done) {

    var success = false;
    var view  = new cdb.admin.WMSBasemapChooserPane();

    view.bind("chooseWMSLayers", function() {
      success = true;
    });

    var url = "http://geodata.nationaalgeoregister.nl/bevolkingskernen2008/wms";
    view.checkTileJson(url);

    setTimeout(function() {
      expect(success).toEqual(true);
      done();
    }, 500);

  });

  it("should trigger an error if the WMS is invalid", function(done) {

    var error = false;
    var view  = new cdb.admin.WMSBasemapChooserPane();

    view.bind("errorChooser", function() {
      error = true;
    });

    var url = "I'm not an URL, you know";

    view.checkTileJson(url);

    setTimeout(function() {
      expect(error).toEqual(true);
      done();
    }, 500);

  });

  it("should fix https url", function() {
    var url = cdb.admin.ZXYBasemapChooserPane.prototype._fixHTTPS('http://test.com/1.json', { protocol: 'https:' });
    expect(url).toEqual('https://test.com/1.json');

    url = cdb.admin.ZXYBasemapChooserPane.prototype._fixHTTPS('http://test.com/1.json', { protocol: 'http:' });
    expect(url).toEqual('http://test.com/1.json');
  });

  it("should fix mapbox https url", function() {
    var url = cdb.admin.MapboxBasemapChooserPane.prototype._fixHTTPS(
      'http://a.tiles.mapbox.com/v4/examples.map-4l7djmvo.json',
      { protocol: 'https:' }
    );

    expect(url).toEqual('https://dnv9my2eseobd.cloudfront.net/v4/examples.map-4l7djmvo.json');

    url = cdb.admin.MapboxBasemapChooserPane.prototype._fixHTTPS(
      'http://a.tiles.mapbox.com/v4/examples.map-4l7djmvo.json',
      { protocol: 'http:' }
    );
    expect(url).toEqual(
      'http://a.tiles.mapbox.com/v4/examples.map-4l7djmvo.json'
    )
  });

  it("should send mapbox url if user provides the mapbox edit url", function(done) {
    var s = sinon.spy();
{'fraction_non_alphanumeric': 0.1839557399723375, 'fraction_numerical': 0.005532503457814661, 'mean_word_length': 4.458768873403019, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '3750392', 'n_tokens_mistral': 3281, 'n_tokens_neox': 3256, 'n_words': 427}