annotate static/bootstrap/js/tests/unit/bootstrap-alert.js @ 95:ddd9f7efe80c

Fixed a bug where meta values would be duplicated during resolve.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 17 Apr 2013 20:49:30 -0700
parents a5a3d454eac9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 $(function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 module("bootstrap-alerts")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 test("should provide no conflict", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 var alert = $.fn.alert.noConflict()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 ok(!$.fn.alert, 'alert was set back to undefined (org value)')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 $.fn.alert = alert
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 test("should be defined on jquery object", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 ok($(document.body).alert, 'alert method is defined')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 test("should return element", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 ok($(document.body).alert()[0] == document.body, 'document.body returned')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 test("should fade element out on clicking .close", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 var alertHTML = '<div class="alert-message warning fade in">'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 + '<a class="close" href="#" data-dismiss="alert">×</a>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 + '</div>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 , alert = $(alertHTML).alert()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 alert.find('.close').click()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 ok(!alert.hasClass('in'), 'remove .in class on .close click')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 test("should remove element when clicking .close", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 var alertHTML = '<div class="alert-message warning fade in">'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 + '<a class="close" href="#" data-dismiss="alert">×</a>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 + '</div>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 , alert = $(alertHTML).appendTo('#qunit-fixture').alert()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 alert.find('.close').click()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 test("should not fire closed when close is prevented", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 stop();
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 $('<div class="alert"/>')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 .bind('close', function (e) {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 e.preventDefault();
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 ok(true);
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 start();
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 .bind('closed', function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 ok(false);
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 .alert('close')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 })