mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
83267cdd45
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92560 467b73ca-7a2a-4603-9d3b-597d59a354a9
79 lines
2.1 KiB
JavaScript
79 lines
2.1 KiB
JavaScript
|
|
describe 'Concrete'
|
|
describe 'Basics'
|
|
before
|
|
$.concrete.warningLevel = $.concrete.WARN_LEVEL_BESTPRACTISE;
|
|
$('body').append('<div id="dom_test"></div>');
|
|
end
|
|
after
|
|
$('#dom_test').remove();
|
|
end
|
|
|
|
before_each
|
|
$.concrete.clear_all_rules();
|
|
$('#dom_test').html('<div id="a" class="a b c"></div><div id="b" class="c d e"></div>');
|
|
end
|
|
|
|
it 'can attach and call a base function'
|
|
$('#a').concrete({
|
|
foo: function(){return this.attr('id');}
|
|
});
|
|
$('.a').foo().should.equal 'a'
|
|
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');}
|
|
});
|
|
$('.a').foo().should.equal 'foo_a'
|
|
$('.a').bar().should.equal 'bar_a'
|
|
end
|
|
|
|
it 'can attach and call a namespaced function'
|
|
$.concrete('bar', function($){
|
|
$('#a').concrete({
|
|
foo: function(){return this.attr('id');}
|
|
});
|
|
});
|
|
$('.a').concrete('bar').foo().should.equal 'a'
|
|
end
|
|
|
|
it 'can attach and call a nested namespaced function'
|
|
$.concrete('qux.baz.bar', function($){
|
|
$('#a').concrete({
|
|
foo: function(){return this.attr('id');}
|
|
});
|
|
});
|
|
$('.a').concrete('qux.baz.bar').foo().should.equal 'a'
|
|
end
|
|
|
|
it 'can call two functions on two elements'
|
|
var res = []
|
|
$('#a').concrete({
|
|
foo: function(){res.push(this.attr('id'));}
|
|
});
|
|
$('#b.c').concrete({
|
|
foo: function(){res.push(this.attr('id'));}
|
|
});
|
|
$('#dom_test div').foo();
|
|
res.should.eql ['b', 'a']
|
|
end
|
|
|
|
it 'can call two namespaced functions on two elements'
|
|
var res = []
|
|
$.concrete('bar', function($){
|
|
$('#a').concrete({
|
|
foo: function(){res.push(this.attr('id'));}
|
|
});
|
|
$('#b.c').concrete({
|
|
foo: function(){res.push(this.attr('id'));}
|
|
});
|
|
});
|
|
$('#dom_test div').concrete('bar').foo();
|
|
res.should.eql ['b', 'a']
|
|
end
|
|
|
|
end
|
|
end
|