Browse Source

Add ComponentImageView tests

pull/36/head
Artur Arseniev 10 years ago
parent
commit
6ed4bce6ae
  1. 11
      src/dom_components/view/ComponentImageView.js
  2. 2
      test/runner/main.js
  3. 7
      test/specs/dom_components/main.js
  4. 57
      test/specs/dom_components/view/ComponentImageView.js
  5. 1
      test/specs/dom_components/view/ComponentTextView.js

11
src/dom_components/view/ComponentImageView.js

@ -13,22 +13,21 @@ define(['backbone', './ComponentView'],
ComponentView.prototype.initialize.apply(this, arguments);
this.listenTo( this.model, 'change:src', this.updateSrc);
this.listenTo( this.model, 'dblclick', this.openModal);
this.classEmpty = this.config.stylePrefix + 'image-placeholder ' + this.config.imageCompClass;
var compCls = this.config.imageCompClass || '';
this.classEmpty = this.pfx + 'image-placeholder' + (compCls ? ' ' + compCls : '');
if(!this.model.get('src'))
this.$el.attr('class', this.classEmpty);
if(this.config.modal)
this.modal = this.config.modal;
this.modal = this.config.modal;
if(this.config.am)
this.am = this.config.am;
this.am = this.config.am;
},
/**
* Update src attribute
*
* @return void
* @private
* */
updateSrc: function(){
@ -38,8 +37,6 @@ define(['backbone', './ComponentView'],
/**
* Open dialog for image changing
* @param {Object} e Event
*
* @return void
* @private
* */
openModal: function(e){

2
test/runner/main.js

@ -16,7 +16,7 @@ require(['../src/config/require-config.js', 'config/config.js'], function() {
'specs/css_composer/main.js',
'specs/code_manager/main.js',
'specs/panels/main.js',
'specs/commands/main.js',
'specs/commands/main.js'
], function(chai)
{
var should = chai.should(),

7
test/specs/dom_components/main.js

@ -5,13 +5,15 @@ define([
modulePath + '/model/Component',
modulePath + '/view/ComponentView',
modulePath + '/view/ComponentsView',
modulePath + '/view/ComponentTextView'
modulePath + '/view/ComponentTextView',
modulePath + '/view/ComponentImageView'
],
function(DomComponents,
ComponentModels,
ComponentView,
ComponentsView,
ComponentTextView
ComponentTextView,
ComponentImageView
) {
describe('DOM Components', function() {
@ -67,6 +69,7 @@ define([
ComponentView.run();
ComponentsView.run();
ComponentTextView.run();
ComponentImageView.run();
});
});

57
test/specs/dom_components/view/ComponentImageView.js

@ -0,0 +1,57 @@
var path = 'DomComponents/view/';
define([path + 'ComponentImageView', 'DomComponents/model/Component'],
function(ComponentImageView, Component) {
return {
run : function(){
describe('ComponentImageView', function() {
var $fixtures;
var $fixture;
var model;
var view;
before(function () {
$fixtures = $("#fixtures");
$fixture = $('<div class="components-fixture"></div>');
});
beforeEach(function () {
model = new Component();
view = new ComponentImageView({
model: model
});
$fixture.empty().appendTo($fixtures);
$fixture.html(view.render().el);
});
afterEach(function () {
view.remove();
});
after(function () {
$fixture.remove();
});
it('Component empty', function() {
$fixture.html().should.equal('<img class="image-placeholder">');
});
it('TagName is <img>', function() {
view.el.tagName.should.equal('IMG');
});
it('Update src attribute', function() {
model.set('src','./');
view.el.getAttribute('src').should.equal('./');
});
it('Renders correctly', function() {
view.render().should.be.ok;
});
});
}
};
});

1
test/specs/dom_components/view/ComponentTextView.js

@ -11,7 +11,6 @@ define([path + 'ComponentTextView', 'DomComponents/model/Component'],
var $fixture;
var model;
var view;
var hClass = 'hc-state';
before(function () {
$fixtures = $("#fixtures");

Loading…
Cancel
Save