Browse Source

Add ComponentImageView tests

pull/36/head
Artur Arseniev 11 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); ComponentView.prototype.initialize.apply(this, arguments);
this.listenTo( this.model, 'change:src', this.updateSrc); this.listenTo( this.model, 'change:src', this.updateSrc);
this.listenTo( this.model, 'dblclick', this.openModal); 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')) if(!this.model.get('src'))
this.$el.attr('class', this.classEmpty); this.$el.attr('class', this.classEmpty);
if(this.config.modal) if(this.config.modal)
this.modal = this.config.modal; this.modal = this.config.modal;
if(this.config.am) if(this.config.am)
this.am = this.config.am; this.am = this.config.am;
}, },
/** /**
* Update src attribute * Update src attribute
*
* @return void
* @private * @private
* */ * */
updateSrc: function(){ updateSrc: function(){
@ -38,8 +37,6 @@ define(['backbone', './ComponentView'],
/** /**
* Open dialog for image changing * Open dialog for image changing
* @param {Object} e Event * @param {Object} e Event
*
* @return void
* @private * @private
* */ * */
openModal: function(e){ 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/css_composer/main.js',
'specs/code_manager/main.js', 'specs/code_manager/main.js',
'specs/panels/main.js', 'specs/panels/main.js',
'specs/commands/main.js', 'specs/commands/main.js'
], function(chai) ], function(chai)
{ {
var should = chai.should(), var should = chai.should(),

7
test/specs/dom_components/main.js

@ -5,13 +5,15 @@ define([
modulePath + '/model/Component', modulePath + '/model/Component',
modulePath + '/view/ComponentView', modulePath + '/view/ComponentView',
modulePath + '/view/ComponentsView', modulePath + '/view/ComponentsView',
modulePath + '/view/ComponentTextView' modulePath + '/view/ComponentTextView',
modulePath + '/view/ComponentImageView'
], ],
function(DomComponents, function(DomComponents,
ComponentModels, ComponentModels,
ComponentView, ComponentView,
ComponentsView, ComponentsView,
ComponentTextView ComponentTextView,
ComponentImageView
) { ) {
describe('DOM Components', function() { describe('DOM Components', function() {
@ -67,6 +69,7 @@ define([
ComponentView.run(); ComponentView.run();
ComponentsView.run(); ComponentsView.run();
ComponentTextView.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 $fixture;
var model; var model;
var view; var view;
var hClass = 'hc-state';
before(function () { before(function () {
$fixtures = $("#fixtures"); $fixtures = $("#fixtures");

Loading…
Cancel
Save