]>
Commit | Line | Data |
---|---|---|
91e44d91 S |
1 | $(function () { |
2 | 'use strict' | |
3 | ||
4 | QUnit.module('alert plugin') | |
5 | ||
6 | QUnit.test('should be defined on jquery object', function (assert) { | |
7 | assert.expect(1) | |
8 | assert.ok($(document.body).alert, 'alert method is defined') | |
9 | }) | |
10 | ||
11 | QUnit.module('alert', { | |
12 | beforeEach: function () { | |
13 | // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode | |
14 | $.fn.bootstrapAlert = $.fn.alert.noConflict() | |
15 | }, | |
16 | afterEach: function () { | |
17 | $.fn.alert = $.fn.bootstrapAlert | |
18 | delete $.fn.bootstrapAlert | |
19 | } | |
20 | }) | |
21 | ||
22 | QUnit.test('should provide no conflict', function (assert) { | |
23 | assert.expect(1) | |
24 | assert.strictEqual($.fn.alert, undefined, 'alert was set back to undefined (org value)') | |
25 | }) | |
26 | ||
27 | QUnit.test('should return jquery collection containing the element', function (assert) { | |
28 | assert.expect(2) | |
29 | var $el = $('<div/>') | |
30 | var $alert = $el.bootstrapAlert() | |
31 | assert.ok($alert instanceof $, 'returns jquery collection') | |
32 | assert.strictEqual($alert[0], $el[0], 'collection contains element') | |
33 | }) | |
34 | ||
35 | QUnit.test('should fade element out on clicking .close', function (assert) { | |
36 | assert.expect(1) | |
37 | var alertHTML = '<div class="alert alert-danger fade show">' | |
38 | + '<a class="close" href="#" data-dismiss="alert">×</a>' | |
39 | + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' | |
40 | + '</div>' | |
41 | ||
42 | var $alert = $(alertHTML).bootstrapAlert().appendTo($('#qunit-fixture')) | |
43 | ||
44 | $alert.find('.close').trigger('click') | |
45 | ||
46 | assert.strictEqual($alert.hasClass('show'), false, 'remove .show class on .close click') | |
47 | }) | |
48 | ||
49 | QUnit.test('should remove element when clicking .close', function (assert) { | |
50 | assert.expect(2) | |
51 | var alertHTML = '<div class="alert alert-danger fade show">' | |
52 | + '<a class="close" href="#" data-dismiss="alert">×</a>' | |
53 | + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' | |
54 | + '</div>' | |
55 | var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() | |
56 | ||
57 | assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom') | |
58 | ||
59 | $alert.find('.close').trigger('click') | |
60 | ||
61 | assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom') | |
62 | }) | |
63 | ||
64 | QUnit.test('should not fire closed when close is prevented', function (assert) { | |
65 | assert.expect(1) | |
66 | var done = assert.async() | |
67 | $('<div class="alert"/>') | |
68 | .on('close.bs.alert', function (e) { | |
69 | e.preventDefault() | |
70 | assert.ok(true, 'close event fired') | |
71 | done() | |
72 | }) | |
73 | .on('closed.bs.alert', function () { | |
74 | assert.ok(false, 'closed event fired') | |
75 | }) | |
76 | .bootstrapAlert('close') | |
77 | }) | |
78 | ||
79 | }) |