2011-09-10 07:47:49 +02:00
|
|
|
|
$(function () {
|
|
|
|
|
|
2013-09-18 18:50:02 +02:00
|
|
|
|
module('alert')
|
2011-09-10 07:47:49 +02:00
|
|
|
|
|
2013-09-18 18:50:02 +02:00
|
|
|
|
test('should provide no conflict', function () {
|
2012-12-07 23:06:01 +01:00
|
|
|
|
var alert = $.fn.alert.noConflict()
|
|
|
|
|
ok(!$.fn.alert, 'alert was set back to undefined (org value)')
|
|
|
|
|
$.fn.alert = alert
|
|
|
|
|
})
|
|
|
|
|
|
2013-09-18 18:50:02 +02:00
|
|
|
|
test('should be defined on jquery object', function () {
|
2011-09-10 07:47:49 +02:00
|
|
|
|
ok($(document.body).alert, 'alert method is defined')
|
|
|
|
|
})
|
|
|
|
|
|
2013-09-18 18:50:02 +02:00
|
|
|
|
test('should return element', function () {
|
2011-09-10 07:47:49 +02:00
|
|
|
|
ok($(document.body).alert()[0] == document.body, 'document.body returned')
|
|
|
|
|
})
|
|
|
|
|
|
2013-09-18 18:50:02 +02:00
|
|
|
|
test('should fade element out on clicking .close', function () {
|
2013-12-19 15:32:37 +01:00
|
|
|
|
var alertHTML = '<div class="alert-message warning fade in">' +
|
|
|
|
|
'<a class="close" href="#" data-dismiss="alert">×</a>' +
|
|
|
|
|
'<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' +
|
|
|
|
|
'</div>',
|
2013-12-15 20:04:32 +01:00
|
|
|
|
alert = $(alertHTML).alert()
|
2011-09-10 07:47:49 +02:00
|
|
|
|
|
|
|
|
|
alert.find('.close').click()
|
|
|
|
|
|
|
|
|
|
ok(!alert.hasClass('in'), 'remove .in class on .close click')
|
|
|
|
|
})
|
|
|
|
|
|
2013-09-18 18:50:02 +02:00
|
|
|
|
test('should remove element when clicking .close', function () {
|
2011-09-10 07:47:49 +02:00
|
|
|
|
$.support.transition = false
|
|
|
|
|
|
2013-12-19 15:32:37 +01:00
|
|
|
|
var alertHTML = '<div class="alert-message warning fade in">' +
|
|
|
|
|
'<a class="close" href="#" data-dismiss="alert">×</a>' +
|
|
|
|
|
'<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' +
|
|
|
|
|
'</div>',
|
2013-12-15 20:04:32 +01:00
|
|
|
|
alert = $(alertHTML).appendTo('#qunit-fixture').alert()
|
2011-09-10 07:47:49 +02:00
|
|
|
|
|
2011-12-21 03:02:47 +01:00
|
|
|
|
ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom')
|
2011-09-10 07:47:49 +02:00
|
|
|
|
|
|
|
|
|
alert.find('.close').click()
|
|
|
|
|
|
2011-12-21 03:02:47 +01:00
|
|
|
|
ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
|
2011-09-10 07:47:49 +02:00
|
|
|
|
})
|
|
|
|
|
|
2013-09-18 18:50:02 +02:00
|
|
|
|
test('should not fire closed when close is prevented', function () {
|
2012-03-25 03:20:09 +02:00
|
|
|
|
$.support.transition = false
|
|
|
|
|
stop();
|
|
|
|
|
$('<div class="alert"/>')
|
2013-05-17 05:19:51 +02:00
|
|
|
|
.on('close.bs.alert', function (e) {
|
2012-03-25 03:20:09 +02:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
ok(true);
|
|
|
|
|
start();
|
|
|
|
|
})
|
2013-05-17 05:19:51 +02:00
|
|
|
|
.on('closed.bs.alert', function () {
|
2012-03-25 03:20:09 +02:00
|
|
|
|
ok(false);
|
|
|
|
|
})
|
|
|
|
|
.alert('close')
|
|
|
|
|
})
|
|
|
|
|
|
2013-04-23 09:34:27 +02:00
|
|
|
|
})
|