<commit_before>var initializeGlobals = function() {
  storybase.globals.API_ROOT = '/api/0.1/';
  storybase.globals.MAP_CENTER = [39.74151, -104.98672];
  storybase.globals.MAP_ZOOM_LEVEL = 11;
  storybase.globals.MAP_POINT_ZOOM_LEVEL = 14; 
};

describe('AppView', function() {
  beforeEach(function() {
    initializeGlobals();
    this.dispatcher = _.clone(Backbone.Events);
    this.view = new storybase.builder.views.AppView({
      dispatcher: this.dispatcher
    });
  });

  describe('when receiving the "error" event', function() {
    beforeEach(function() {
      // Binding event handlers to the dispatcher happens in the view's
      // initialize method, so we have to spy on the prototype so the
      // spied method will get bound.
      spyOn(storybase.builder.views.AppView.prototype, 'error');
      this.view = new storybase.builder.views.AppView({
        dispatcher: this.dispatcher
      });
    });

    it('calls the error method', function() {
      var errMsg = 'An error message';
      this.dispatcher.trigger('error', errMsg);
      expect(this.view.error).toHaveBeenCalledWith(errMsg);
    });
  });
});

describe('SectionEditView view', function() {
  beforeEach(function() {
    this.dispatcher = _.clone(Backbone.Events);
  });

  describe('when initialized with an existing story and section', function () {
    beforeEach(function() {
      var Section = Backbone.Model.extend({
        url: function() {
          return '/api/0.1/stories/357c5885c4e844cb8a4cd4eebe912a1c/sections/dc044f23e93649d6b1bd48625fc301cd/'
        }
      });
      var SectionAssets = Backbone.Collection.extend({
        url: function() {
          return '/api/0.1/stories/357c5885c4e844cb8a4cd4eebe912a1c/sections/dc044f23e93649d6b1bd48625fc301cd/assets/'
        },

        parse: function(response) {
          return response.objects;
        }
      });
      var Story = Backbone.Model.extend({
        url: function() {
          return '/api/0.1/stories/357c5885c4e844cb8a4cd4eebe912a1c/';
        }
      });
      this.section = new Section({
        id: "dc044f23e93649d6b1bd48625fc301cd",
        layout_template: "<div class=\"section-layout side-by-side\">\n    <div class=\"left\">\n        <div class=\"storybase-container-placeholder\" id=\"left\"></div>\n    </div>\n    <div class=\"right\">\n        <div class=\"storybase-container-placeholder\" id=\"right\"></div>\n    </div>\n</div>\n",
      }); 
      this.section.assets = new SectionAssets;
      this.view = new storybase.builder.views.SectionEditView({
        dispatcher: this.dispatcher,
        model: this.section,
        story: new Story(), 
        templateSource: $('#section-edit-template').html()
      });
    });

    describe('when receiving the "do:add:sectionasset" event', function() {
      beforeEach(function() {
        var container = 'left';
        this.asset = new Backbone.Model({
           id: 'bef53407591f4fd8bd169f9cc02672f9',
           type: 'text',
           body: 'Test text asset body',
           content: 'Test text asset body'
        });
        this.dispatcher.trigger('do:add:sectionasset', this.section, this.asset, container); 
      });

      it('should add the asset to the assets collection', function() {
        expect(this.view.assets.size()).toEqual(1);
        expect(this.view.assets.at(0)).toEqual(this.asset);
      });
    });
  });
});

describe('BuilderView view', function() {
  beforeEach(function() {
    this.dispatcher = _.clone(Backbone.Events);
    this.view = new storybase.builder.views.BuilderView({
      dispatcher: this.dispatcher
    });
  });

  describe('when receiving the select:storytemplate signal via the dispatcher', function() {
    beforeEach(function() {
      // Mock a story template
      var StoryTemplate = Backbone.Model.extend({
        getStory: function(options) {
        }
      });
      this.storyTemplate = new StoryTemplate({
        "description": "Explain a complex issue simply",
        "story": "/api/0.1/stories/0b2b9e3f38e3422ea3899ee66d1e334b/",
        "tag_line": "it doesn't have to be so complicated",
        "template_id": "5586de9ad3674c7e926ca4f4f04da27b",
        "time_needed": "30 minutes", 
        "title": "Explainer"
      });
      spyOn(storybase.builder.views.BuilderView.prototype, 'setStoryTemplate');
      this.view = new storybase.builder.views.BuilderView({
        dispatcher: this.dispatcher
      });
    });

    it('calls the setStoryTemplate method', function() {
      this.dispatcher.trigger("select:template", this.storyTemplate);
      expect(this.view.setStoryTemplate).toHaveBeenCalledWith(this.storyTemplate);
    });
  });
});

describe('SectionAssetEditView view', function() {
  beforeEach(function() {
    this.assetTypes = [
      {
        'name': 'image',
        'type': 'image'
      },
      {
        'name': 'text',
        'type': 'text'
      }
    ];
    this.dispatcher = _.clone(Backbone.Events);
    this.view = new storybase.builder.views.SectionAssetEditView({
       dispatcher: this.dispatcher,
       assetTypes: this.assetTypes,
    });
  });

  describe('when initializing', function() {
    it('should have a model property', function() {
      expect(this.view.model).toBeDefined();
    });

    it('should have a form property', function() {<commit_msg>Fix jasmine tests<commit_after>var initializeGlobals = function() {
  storybase.globals.API_ROOT = '/api/0.1/';
  storybase.globals.MAP_CENTER = [39.74151, -104.98672];
  storybase.globals.MAP_ZOOM_LEVEL = 11;
  storybase.globals.MAP_POINT_ZOOM_LEVEL = 14; 
};

describe('AppView', function() {
  beforeEach(function() {
    initializeGlobals();
    this.dispatcher = _.clone(Backbone.Events);
    this.view = new storybase.builder.views.AppView({
      dispatcher: this.dispatcher
    });
  });

  describe('when receiving the "error" event', function() {
    beforeEach(function() {
      // Binding event handlers to the dispatcher happens in the view's
      // initialize method, so we have to spy on the prototype so the
      // spied method will get bound.
      spyOn(storybase.builder.views.AppView.prototype, 'error');
      this.view = new storybase.builder.views.AppView({
        dispatcher: this.dispatcher
      });
    });

    it('calls the error method', function() {
      var errMsg = 'An error message';
      this.dispatcher.trigger('error', errMsg);
      expect(this.view.error).toHaveBeenCalledWith(errMsg);
    });
  });
});

describe('SectionEditView view', function() {
  beforeEach(function() {
    this.dispatcher = _.clone(Backbone.Events);
  });

  describe('when initialized with an existing story and section', function () {
    beforeEach(function() {
      var Section = Backbone.Model.extend({
        url: function() {
          return '/api/0.1/stories/357c5885c4e844cb8a4cd4eebe912a1c/sections/dc044f23e93649d6b1bd48625fc301cd/'
        }
      });
      var SectionAssets = Backbone.Collection.extend({
        url: function() {
          return '/api/0.1/stories/357c5885c4e844cb8a4cd4eebe912a1c/sections/dc044f23e93649d6b1bd48625fc301cd/assets/'
        },

        parse: function(response) {
          return response.objects;
        }
      });
      var Story = Backbone.Model.extend({
        assets: new Backbone.Collection,
        url: function() {
          return '/api/0.1/stories/357c5885c4e844cb8a4cd4eebe912a1c/';
        }
      });
      this.section = new Section({
        id: "dc044f23e93649d6b1bd48625fc301cd",
        layout_template: "<div class=\"section-layout side-by-side\">\n    <div class=\"left\">\n        <div class=\"storybase-container-placeholder\" id=\"left\"></div>\n    </div>\n    <div class=\"right\">\n        <div class=\"storybase-container-placeholder\" id=\"right\"></div>\n    </div>\n</div>\n",
      }); 
      this.section.assets = new SectionAssets;
      this.view = new storybase.builder.views.SectionEditView({
        dispatcher: this.dispatcher,
        model: this.section,
        story: new Story(), 
        templateSource: $('#section-edit-template').html()
      });
    });

    describe('when receiving the "do:add:sectionasset" event', function() {
      beforeEach(function() {
        var container = 'left';
        this.asset = new Backbone.Model({
           id: 'bef53407591f4fd8bd169f9cc02672f9',
           type: 'text',
           body: 'Test text asset body',
           content: 'Test text asset body'
        });
        this.dispatcher.trigger('do:add:sectionasset', this.section, this.asset, container); 
      });

      it('should add the asset to the assets collection', function() {
        expect(this.view.assets.size()).toEqual(1);
        expect(this.view.assets.at(0)).toEqual(this.asset);
      });
    });
  });
});

describe('BuilderView view', function() {
  beforeEach(function() {
    this.dispatcher = _.clone(Backbone.Events);
    this.view = new storybase.builder.views.BuilderView({
      dispatcher: this.dispatcher
    });
  });

  describe('when receiving the select:storytemplate signal via the dispatcher', function() {
    beforeEach(function() {
      // Mock a story template
      var StoryTemplate = Backbone.Model.extend({
        getStory: function(options) {
        }
      });
      this.storyTemplate = new StoryTemplate({
        "description": "Explain a complex issue simply",
        "story": "/api/0.1/stories/0b2b9e3f38e3422ea3899ee66d1e334b/",
        "tag_line": "it doesn't have to be so complicated",
        "template_id": "5586de9ad3674c7e926ca4f4f04da27b",
        "time_needed": "30 minutes", 
        "title": "Explainer"
      });
      spyOn(storybase.builder.views.BuilderView.prototype, 'setStoryTemplate');
      this.view = new storybase.builder.views.BuilderView({
        dispatcher: this.dispatcher
      });
    });

    it('calls the setStoryTemplate method', function() {
      this.dispatcher.trigger("select:template", this.storyTemplate);
      expect(this.view.setStoryTemplate).toHaveBeenCalledWith(this.storyTemplate);
    });
  });
});

describe('SectionAssetEditView view', function() {
  beforeEach(function() {
    this.assetTypes = [
      {
        'name': 'image',
        'type': 'image'
      },
      {
        'name': 'text',
        'type': 'text'
      }
    ];
    this.dispatcher = _.clone(Backbone.Events);
    this.view = new storybase.builder.views.SectionAssetEditView({
       assetTypes: this.assetTypes,
       dispatcher: this.dispatcher,
       story: new Backbone.Model
    });
  });

  describe('when initializing', function() {
    it('should have a model property', function() {
      expect(this.view.model).toBeDefined();
    });

    it('should have a form property', function() {
{'fraction_non_alphanumeric': 0.14313688922044013, 'fraction_numerical': 0.038418500559492724, 'mean_word_length': 2.7844036697247705, 'pattern_counts': {'":': 12, '<': 23, '<?xml version=': 0, '>': 23, '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': '4205338', 'n_tokens_mistral': 3526, 'n_tokens_neox': 3302, 'n_words': 618}