2009-11-21 03:33:06 +01:00
|
|
|
|
|
|
|
describe 'Concrete'
|
|
|
|
describe 'Basics'
|
|
|
|
before
|
2009-11-21 03:33:26 +01:00
|
|
|
$.concrete.warningLevel = $.concrete.WARN_LEVEL_BESTPRACTISE;
|
|
|
|
$('body').append('<div id="dom_test"></div>');
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
after
|
2009-11-21 03:33:26 +01:00
|
|
|
$('#dom_test').remove();
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
before_each
|
2009-11-21 03:33:26 +01:00
|
|
|
$.concrete.clear_all_rules();
|
|
|
|
$('#dom_test').html('<div id="a" class="a b c"></div><div id="b" class="c d e"></div>');
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can attach and call a base function'
|
|
|
|
$('#a').concrete({
|
|
|
|
foo: function(){return this.attr('id');}
|
|
|
|
});
|
2009-11-21 03:33:26 +01:00
|
|
|
$('.a').foo().should.equal 'a'
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can attach and call several base functions'
|
|
|
|
$('#a').concrete({
|
|
|
|
foo: function(){return 'foo_' + this.attr('id');},
|
|
|
|
bar: function(){return 'bar_' + this.attr('id');}
|
2009-11-21 03:33:26 +01:00
|
|
|
});
|
|
|
|
$('.a').foo().should.equal 'foo_a'
|
|
|
|
$('.a').bar().should.equal 'bar_a'
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
2009-11-21 03:33:26 +01:00
|
|
|
|
2009-11-21 03:33:06 +01:00
|
|
|
it 'can attach and call a namespaced function'
|
2009-11-21 03:33:26 +01:00
|
|
|
$.concrete('bar', function($){
|
|
|
|
$('#a').concrete({
|
|
|
|
foo: function(){return this.attr('id');}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$('.a').concrete('bar').foo().should.equal 'a'
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
2009-11-21 03:33:26 +01:00
|
|
|
|
2009-11-21 03:33:06 +01:00
|
|
|
it 'can attach and call a nested namespaced function'
|
2009-11-21 03:33:26 +01:00
|
|
|
$.concrete('qux.baz.bar', function($){
|
|
|
|
$('#a').concrete({
|
|
|
|
foo: function(){return this.attr('id');}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$('.a').concrete('qux.baz.bar').foo().should.equal 'a'
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
2009-11-21 03:33:26 +01:00
|
|
|
|
|
|
|
it 'can call two functions on two elements'
|
2009-11-21 03:33:06 +01:00
|
|
|
var res = []
|
|
|
|
$('#a').concrete({
|
2009-11-21 03:33:26 +01:00
|
|
|
foo: function(){res.push(this.attr('id'));}
|
|
|
|
});
|
2009-11-21 03:33:06 +01:00
|
|
|
$('#b.c').concrete({
|
2009-11-21 03:33:26 +01:00
|
|
|
foo: function(){res.push(this.attr('id'));}
|
|
|
|
});
|
2009-11-21 03:33:06 +01:00
|
|
|
$('#dom_test div').foo();
|
|
|
|
res.should.eql ['b', 'a']
|
|
|
|
end
|
2009-11-21 03:33:26 +01:00
|
|
|
|
|
|
|
it 'can call two namespaced functions on two elements'
|
2009-11-21 03:33:06 +01:00
|
|
|
var res = []
|
2009-11-21 03:33:26 +01:00
|
|
|
$.concrete('bar', function($){
|
|
|
|
$('#a').concrete({
|
|
|
|
foo: function(){res.push(this.attr('id'));}
|
|
|
|
});
|
|
|
|
$('#b.c').concrete({
|
|
|
|
foo: function(){res.push(this.attr('id'));}
|
|
|
|
});
|
|
|
|
});
|
2009-11-21 03:33:06 +01:00
|
|
|
$('#dom_test div').concrete('bar').foo();
|
|
|
|
res.should.eql ['b', 'a']
|
|
|
|
end
|
2009-11-21 03:33:26 +01:00
|
|
|
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
end
|