<commit_before>var LayerDefinitionModel = require('../../../../../../javascripts/cartodb3/data/layer-definition-model');
var InfowindowsView = require('../../../../../../javascripts/cartodb3/editor/layers/layer-content-views/infowindows-view');
var ConfigModel = require('../../../../../../javascripts/cartodb3/data/config-model');
var QuerySchemaModel = require('../../../../../../javascripts/cartodb3/data/query-schema-model');
var InfowindowView = require('../../../../../../javascripts/cartodb3/editor/layers/layer-content-views/infowindow/infowindow-click-view');
var TooltipView = require('../../../../../../javascripts/cartodb3/editor/layers/layer-content-views/infowindow/infowindow-hover-view');
var InfowindowDefinitionModel = require('../../../../../../javascripts/cartodb3/data/infowindow-definition-model');
var _ = require('underscore');
var EditorModel = require('../../../../../../javascripts/cartodb3/data/editor-model');

describe('editor/layers/layer-content-view/infowindows-view', function () {
  beforeEach(function () {
    this.configModel = new ConfigModel({
      base_url: '/u/pepe'
    });

    this.querySchemaModel = new QuerySchemaModel({
      query: 'SELECT * FROM foobar',
      status: 'fetched'
    }, {
      configModel: this.configModel
    });
  });

  describe('when layer has infowindowModel', function () {
    beforeEach(function () {
      this.layerDefinitionModel = new LayerDefinitionModel({
        id: 'l-1',
        fetched: true,
        options: {
          type: 'CartoDB',
          table_name: 'foo',
          cartocss: 'asd',
          source: 'a0'
        },
        infowindow: {},
        tooltip: {}
      }, {
        parse: true,
        configModel: this.configModel
      });
      spyOn(this.layerDefinitionModel, 'save');

      this.view = new InfowindowsView({
        configModel: this.configModel,
        editorModel: new EditorModel(),
        layerDefinitionModel: this.layerDefinitionModel,
        querySchemaModel: this.querySchemaModel
      });

      this.view.render();
    });

    it('should render two tabs', function () {
      expect(this.view._layerTabPaneView).toBeDefined();
      expect(_.size(this.view._layerTabPaneView._subviews)).toBe(3); // 2 tabs, 1 pane
      expect(this.view.$('.CDB-NavSubmenu .CDB-NavSubmenu-item').length).toBe(2);
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0)').text()).toContain('editor.layers.infowindow-menu-tab-pane-labels.click');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_light');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1)').text()).toContain('editor.layers.infowindow-menu-tab-pane-labels.hover');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toContain('editor.layers.tooltip.style.none');
    });

    it('should change tab if infowindow (and tooltip) changes', function () {
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_light');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toBe('editor.layers.tooltip.style.none');
      this.view._layerInfowindowModel.set('template_name', 'infowindow_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toBe('editor.layers.tooltip.style.none');
      this.view._layerTooltipModel.set('template_name', 'tooltip_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toBe('editor.layers.tooltip.style.tooltip_dark');
    });

    describe('infowindows tabs', function () {
      var model;

      beforeEach(function () {
        model = new InfowindowDefinitionModel({}, {
          configModel: this.configModel
        });
      });

      it('infowindow should render properly', function () {
        var view = new InfowindowView({
          layerDefinitionModel: this.layerDefinitionModel,
          querySchemaModel: this.querySchemaModel,
          model: model,
          editorModel: new EditorModel()
        });

        view.render();
        expect(_.size(view._subviews)).toBe(1); // fields / codemirror view
      });

      it('tooltip should render properly', function () {
        var view = new TooltipView({
          layerDefinitionModel: this.layerDefinitionModel,
          querySchemaModel: this.querySchemaModel,
          model: model,
          editorModel: new EditorModel()
        });

        view.render();
        expect(_.size(view._subviews)).toBe(1); // fields / codemirror view
      });
    });

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

  describe('when layer doesn\'t have infowindowModel (basemap, torque, ...)', function () {
    beforeEach(function () {
      this.layerDefinitionModel = new LayerDefinitionModel({
        id: 'l-1',
        fetched: true,
        options: {
          type: 'CartoDB',
          table_name: 'foo',
          cartocss: 'asd',
          source: 'a0'
        }
      }, {
        parse: true,
        configModel: this.configModel
      });
      spyOn(this.layerDefinitionModel, 'save');

      this.view = new InfowindowsView({
        configModel: this.configModel,
        editorModel: new EditorModel(),
        layerDefinitionModel: this.layerDefinitionModel,
        querySchemaModel: this.querySchemaModel
      });

      this.view.render();
    });

    it('should render placeholder', function () {
      expect(this.view._layerTabPaneView).not.toBeDefined();
      expect(this.view.$('.CDB-Size-huge').length).toBe(1);
      expect(this.view.$('.CDB-Size-huge').text()).toBe('editor.layers.infowindow.placeholder-text');
    });

    it('should not have any leaks', function () {
      expect(this.view).toHaveNoLeaks();
    });
  });
});
<commit_msg>popups: disable: tests<commit_after>var LayerDefinitionModel = require('../../../../../../javascripts/cartodb3/data/layer-definition-model');
var InfowindowsView = require('../../../../../../javascripts/cartodb3/editor/layers/layer-content-views/infowindows-view');
var ConfigModel = require('../../../../../../javascripts/cartodb3/data/config-model');
var QuerySchemaModel = require('../../../../../../javascripts/cartodb3/data/query-schema-model');
var InfowindowView = require('../../../../../../javascripts/cartodb3/editor/layers/layer-content-views/infowindow/infowindow-click-view');
var TooltipView = require('../../../../../../javascripts/cartodb3/editor/layers/layer-content-views/infowindow/infowindow-hover-view');
var InfowindowDefinitionModel = require('../../../../../../javascripts/cartodb3/data/infowindow-definition-model');
var _ = require('underscore');
var EditorModel = require('../../../../../../javascripts/cartodb3/data/editor-model');

describe('editor/layers/layer-content-view/infowindows-view', function () {
  beforeEach(function () {
    this.configModel = new ConfigModel({
      base_url: '/u/pepe'
    });

    this.querySchemaModel = new QuerySchemaModel({
      query: 'SELECT * FROM foobar',
      status: 'fetched'
    }, {
      configModel: this.configModel
    });
  });

  describe('when layer has infowindowModel', function () {
    beforeEach(function () {
      this.layerDefinitionModel = new LayerDefinitionModel({
        id: 'l-1',
        fetched: true,
        options: {
          type: 'CartoDB',
          table_name: 'foo',
          cartocss: 'asd',
          source: 'a0'
        },
        infowindow: {},
        tooltip: {}
      }, {
        parse: true,
        configModel: this.configModel
      });
      spyOn(this.layerDefinitionModel, 'save');

      this.view = new InfowindowsView({
        configModel: this.configModel,
        editorModel: new EditorModel(),
        layerDefinitionModel: this.layerDefinitionModel,
        querySchemaModel: this.querySchemaModel
      });

      this.view.render();
    });

    it('should render two tabs', function () {
      expect(this.view._layerTabPaneView).toBeDefined();
      expect(_.size(this.view._layerTabPaneView._subviews)).toBe(3); // 2 tabs, 1 pane
      expect(this.view.$('.CDB-NavSubmenu .CDB-NavSubmenu-item').length).toBe(2);
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0)').text()).toContain('editor.layers.infowindow-menu-tab-pane-labels.click');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_light');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1)').text()).toContain('editor.layers.infowindow-menu-tab-pane-labels.hover');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toContain('editor.layers.tooltip.style.none');
    });

    it('should change tab if infowindow (and tooltip) changes', function () {
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_light');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toBe('editor.layers.tooltip.style.none');
      this.view._layerInfowindowModel.set('template_name', 'infowindow_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toBe('editor.layers.tooltip.style.none');
      this.view._layerTooltipModel.set('template_name', 'tooltip_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(0) .CDB-NavSubmenu-status').text()).toBe('editor.layers.infowindow.style.infowindow_dark');
      expect(this.view.$('.CDB-NavSubmenu-item:eq(1) .CDB-NavSubmenu-status').text()).toBe('editor.layers.tooltip.style.tooltip_dark');
    });

    describe('infowindows tabs', function () {
      var model;

      beforeEach(function () {
        model = new InfowindowDefinitionModel({}, {
          configModel: this.configModel
        });
      });

      it('infowindow should render properly', function () {
        var view = new InfowindowView({
          layerDefinitionModel: this.layerDefinitionModel,
          querySchemaModel: this.querySchemaModel,
          model: model,
          editorModel: new EditorModel()
        });

        view.render();
        expect(_.size(view._subviews)).toBe(1); // fields / codemirror view
      });

      it('tooltip should render properly', function () {
        var view = new TooltipView({
          layerDefinitionModel: this.layerDefinitionModel,
          querySchemaModel: this.querySchemaModel,
          model: model,
          editorModel: new EditorModel()
        });

        view.render();
        expect(_.size(view._subviews)).toBe(1); // fields / codemirror view
      });
    });

    it('should render placeholder if styleModel is Aggregated Type', function () {
      expect(_.size(this.view._subviews)).toBe(1);
      expect(this.view.$('.CDB-Size-huge').length).toBe(0);

      this.view._layerDefinitionModel.styleModel.set('type', 'hexabins');
      this.view.render();

      expect(_.size(this.view._subviews)).toBe(0);
      expect(this.view.$('.CDB-Size-huge').length).toBe(1);
    });

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

  describe('when layer doesn\'t have infowindowModel (basemap, torque, ...)', function () {
    beforeEach(function () {
      this.layerDefinitionModel = new LayerDefinitionModel({
        id: 'l-1',
        fetched: true,
        options: {
          type: 'CartoDB',
          table_name: 'foo',
          cartocss: 'asd',
          source: 'a0'
        }
      }, {
        parse: true,
        configModel: this.configModel
      });
      spyOn(this.layerDefinitionModel, 'save');

      this.view = new InfowindowsView({
        configModel: this.configModel,
        editorModel: new EditorModel(),
        layerDefinitionModel: this.layerDefinitionModel,
        querySchemaModel: this.querySchemaModel
      });

      this.view.render();
    });

    it('should render placeholder', function () {
      expect(this.view._layerTabPaneView).not.toBeDefined();
      expect(this.view.$('.CDB-Size-huge').length).toBe(1);
      expect(this.view.$('.CDB-Size-huge').text()).toBe('editor.layers.infowindow.placeholder-text');
    });

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

{'fraction_non_alphanumeric': 0.1787966062115669, 'fraction_numerical': 0.0048260294232116445, 'mean_word_length': 2.9016094746431826, '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': '6545369', 'n_tokens_mistral': 3953, 'n_tokens_neox': 3857, 'n_words': 526}