2009-11-21 03:33:06 +01:00
|
|
|
|
2010-04-13 07:45:29 +02:00
|
|
|
describe 'Entwine'
|
2009-11-21 03:33:06 +01:00
|
|
|
describe 'Basics'
|
|
|
|
before
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE;
|
2009-11-21 03:33:26 +01:00
|
|
|
$('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
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine.clear_all_rules();
|
|
|
|
$('#dom_test').html('<div id="a" class="a b c" data-fieldtype="foo"></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'
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a').entwine({
|
|
|
|
foo: function(){return this.attr('id');}
|
|
|
|
});
|
|
|
|
$('.a').foo().should.equal 'a'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can attach and call a base function on a selector using a data attribute selection'
|
|
|
|
$('[data-fieldtype=foo]').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
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'
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
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'
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine('bar', function($){
|
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:26 +01:00
|
|
|
foo: function(){return this.attr('id');}
|
|
|
|
});
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('.a').entwine('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'
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine('qux.baz.bar', function($){
|
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:26 +01:00
|
|
|
foo: function(){return this.attr('id');}
|
|
|
|
});
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('.a').entwine('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 = []
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:26 +01:00
|
|
|
foo: function(){res.push(this.attr('id'));}
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#b.c').entwine({
|
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 = []
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine('bar', function($){
|
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:26 +01:00
|
|
|
foo: function(){res.push(this.attr('id'));}
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#b.c').entwine({
|
2009-11-21 03:33:26 +01:00
|
|
|
foo: function(){res.push(this.attr('id'));}
|
|
|
|
});
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#dom_test div').entwine('bar').foo();
|
2009-11-21 03:33:06 +01:00
|
|
|
res.should.eql ['b', 'a']
|
|
|
|
end
|
2009-11-21 03:33:26 +01:00
|
|
|
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
end
|