<commit_before><commit_msg>edit feature: content view tests<commit_after>var Backbone = require('backbone');
var EditFeatureContentView = require('../../../../../javascripts/cartodb3/editor/layers/edit-feature-content-view');
var MapModeModel = require('../../../../../javascripts/cartodb3/map-mode-model');
var LayerDefinitionsCollection = require('../../../../../javascripts/cartodb3/data/layer-definitions-collection');
var AnalysisDefinitionNodesCollection = require('../../../../../javascripts/cartodb3/data/analysis-definition-nodes-collection');
var ConfigModel = require('../../../../../javascripts/cartodb3/data/config-model');
var FeatureDefinitionModel = require('../../../../../javascripts/cartodb3/data/feature-definition-model');
var EditorModel = require('../../../../../javascripts/cartodb3/data/editor-model');

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

    var analysisDefinitionNodesCollection = new AnalysisDefinitionNodesCollection(null, {
      configModel: this.configModel
    });

    var layerDefinitionsCollection = new LayerDefinitionsCollection(null, {
      configModel: this.configModel,
      analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
      mapId: 'm-123'
    });
    layerDefinitionsCollection.add({
      id: 'l-1',
      kind: 'carto',
      options: {
        table_name: 'foo'
      }
    });
    this.layerDefinitionModel = layerDefinitionsCollection.at(0);

    this.mapModeModel = new MapModeModel()
    this.editorModel = new EditorModel();

    var featureDefinition = new FeatureDefinitionModel({}, {
      configModel: this.configModel,
      layerDefinitionModel: this.layerDefinitionModel
    });
    this.mapModeModel.enterDrawingFeatureMode(featureDefinition)

    this.view = new EditFeatureContentView({
      layerDefinitionModel: this.layerDefinitionModel,
      configModel: this.configModel,
      stackLayoutModel: {},
      mapModeModel: this.mapModeModel,
      editorModel: this.editorModel,
      model: new Backbone.Model({
        hasChanges: false
      })
    });
    spyOn(this.view, '_addRow').and.callThrough();
    spyOn(this.view, '_renderInfo').and.callThrough();

    this.view.render();
  });

  it('should get table details', function () {
    expect(this.view._tableName).toBe('foo');
    expect(this.view._url).toBe('/u/pepe/dataset/foo');
  });

  it('should render properly', function () {
    expect(_.size(this.view._subviews)).toBe(2); // header, content
  });

  describe('when feature is new', function () {
    it('should add row', function () {
      expect(this.view._addRow).toHaveBeenCalled();
      expect(this.view._renderInfo).toHaveBeenCalled();
    });
  });

  describe('when feature already exists', function () {
    var view;

    beforeEach(function () {
      var featureDefinition = new FeatureDefinitionModel({
        id: 1
      }, {
        configModel: this.configModel,
        layerDefinitionModel: this.layerDefinitionModel
      });
      featureDefinition.fetch();

      this.mapModeModel.enterEditingFeatureMode(featureDefinition);

      view = new EditFeatureContentView({
        layerDefinitionModel: this.layerDefinitionModel,
        configModel: this.configModel,
        stackLayoutModel: {},
        mapModeModel: this.mapModeModel,
        editorModel: this.editorModel,
        model: new Backbone.Model({
          hasChanges: false
        })
      });
      spyOn(view, '_addRow').and.callThrough();
      spyOn(view, '_renderInfo').and.callThrough();

      view.render();
    });

    it('should not add row', function () {
      expect(view._addRow).not.toHaveBeenCalled();
      expect(view._renderInfo).toHaveBeenCalled();
    });
  });

  it('should have no leaks', function () {
    expect(this.view).toHaveNoLeaks();
  });
});
{'fraction_non_alphanumeric': 0.15231280347559417, 'fraction_numerical': 0.0035778175313059034, 'mean_word_length': 3.231351351351351, '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': '1697219', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1066, 'n_words': 179}