<commit_before>var CartoDBLayer = require('../../../src/geo/map/cartodb-layer');
var TorqueLayer = require('../../../src/geo/map/torque-layer');
var LayersCollection = require('../../../src/geo/map/layers');
var Backbone = require('backbone');
var ModelUpdater = require('../../../src/windshaft-integration/model-updater');
var WindshaftError = require('../../../src/windshaft/error');
var CartoDBLayerGroup = require('../../../src/geo/cartodb-layer-group');
var WindshaftMap = require('../../../src/windshaft/map-base.js');

var MyWindshaftMap = WindshaftMap.extend({
});

describe('src/vis/model-updater', function () {
  beforeEach(function () {
    this.fakeVis = jasmine.createSpyObj('vis', ['reload']);

    this.windshaftMap = new MyWindshaftMap({
      urlTemplate: 'http://{user}.carto.com:80',
      userName: 'documentation'
    }, {
      client: {},
      layersCollection: {},
      dataviewsCollection: {},
      analysisCollection: {},
      modelUpdater: {},
      windshaftSettings: {}
    });

    spyOn(this.windshaftMap, 'getBaseURL').and.callFake(function (subdomain) {
      return 'http://' + (subdomain ? subdomain + '.' : '') + 'documentation.carto.com';
    });
    spyOn(this.windshaftMap, 'getLayerIndexesByType').and.returnValue([0]);
    spyOn(this.windshaftMap, 'getSupportedSubdomains').and.returnValue(['']);

    this.visModel = new Backbone.Model();
    this.visModel.setOk = jasmine.createSpy('setOk');
    this.visModel.setError = jasmine.createSpy('setError');
    this.layersCollection = new LayersCollection();
    this.layerGroupModel = new CartoDBLayerGroup({}, {
      layersCollection: this.layersCollection
    });
    this.analysisCollection = new Backbone.Collection();
    this.dataviewsCollection = new Backbone.Collection();

    this.modelUpdater = new ModelUpdater({
      visModel: this.visModel,
      layerGroupModel: this.layerGroupModel,
      layersCollection: this.layersCollection,
      dataviewsCollection: this.dataviewsCollection,
      analysisCollection: this.analysisCollection
    });

    // _getProtocol uses window.location.protocol internally, and that returns "file:"
    // when running the test suite using the jasmine test runner, so we need to fake it
    spyOn(this.modelUpdater, '_getProtocol').and.returnValue('http');
  });

  describe('.updateModels', function () {
    beforeEach(function () {
      this.windshaftMap.getBaseURL.and.callFake(function (subdomain) {
        return 'http://' + (subdomain ? subdomain + '.' : '') + 'documentation.carto.com/api/v1/map/90e64f1b9145961af7ba36d71b887dd2:0';
      });
    });

    it('should set vis state to ok', function () {
      this.modelUpdater.updateModels(this.windshaftMap);<commit_msg>Fix tests.<commit_after>var CartoDBLayer = require('../../../src/geo/map/cartodb-layer');
var TorqueLayer = require('../../../src/geo/map/torque-layer');
var LayersCollection = require('../../../src/geo/map/layers');
var DataviewsTracker = require('../../../src/vis/dataviews-tracker');
var Backbone = require('backbone');
var ModelUpdater = require('../../../src/windshaft-integration/model-updater');
var WindshaftError = require('../../../src/windshaft/error');
var CartoDBLayerGroup = require('../../../src/geo/cartodb-layer-group');
var WindshaftMap = require('../../../src/windshaft/map-base.js');

var MyWindshaftMap = WindshaftMap.extend({
});

describe('src/vis/model-updater', function () {
  beforeEach(function () {
    this.fakeVis = jasmine.createSpyObj('vis', ['reload']);

    this.windshaftMap = new MyWindshaftMap({
      urlTemplate: 'http://{user}.carto.com:80',
      userName: 'documentation'
    }, {
      client: {},
      layersCollection: {},
      dataviewsCollection: {},
      analysisCollection: {},
      modelUpdater: {},
      windshaftSettings: {}
    });

    spyOn(this.windshaftMap, 'getBaseURL').and.callFake(function (subdomain) {
      return 'http://' + (subdomain ? subdomain + '.' : '') + 'documentation.carto.com';
    });
    spyOn(this.windshaftMap, 'getLayerIndexesByType').and.returnValue([0]);
    spyOn(this.windshaftMap, 'getSupportedSubdomains').and.returnValue(['']);

    this.visModel = new Backbone.Model();
    this.visModel.setOk = jasmine.createSpy('setOk');
    this.visModel.setError = jasmine.createSpy('setError');
    this.layersCollection = new LayersCollection();

    this.dataviewsTracker = new DataviewsTracker(null, {
      vis: this.visModel
    });

    this.layerGroupModel = new CartoDBLayerGroup({}, {
      layersCollection: this.layersCollection
    });
    this.analysisCollection = new Backbone.Collection();
    this.dataviewsCollection = new Backbone.Collection();

    this.modelUpdater = new ModelUpdater({
      visModel: this.visModel,
      layerGroupModel: this.layerGroupModel,
      layersCollection: this.layersCollection,
      dataviewsCollection: this.dataviewsCollection,
      analysisCollection: this.analysisCollection,
      dataviewsTracker: this.dataviewsTracker
    });

    // _getProtocol uses window.location.protocol internally, and that returns "file:"
    // when running the test suite using the jasmine test runner, so we need to fake it
    spyOn(this.modelUpdater, '_getProtocol').and.returnValue('http');
  });

  describe('.updateModels', function () {
    beforeEach(function () {
      this.windshaftMap.getBaseURL.and.callFake(function (subdomain) {
        return 'http://' + (subdomain ? subdomain + '.' : '') + 'documentation.carto.com/api/v1/map/90e64f1b9145961af7ba36d71b887dd2:0';
      });
    });

    it('should set vis state to ok', function () {
      this.modelUpdater.updateModels(this.windshaftMap);
{'fraction_non_alphanumeric': 0.16590024761230987, 'fraction_numerical': 0.00919702865228157, 'mean_word_length': 3.6125611745513866, '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': '411775', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1758, 'n_words': 282}