Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / CSS / bootstrap / js / tests / unit / alert.js
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 in">'
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     var $alert = $(alertHTML).bootstrapAlert()
42
43     $alert.find('.close').trigger('click')
44
45     assert.strictEqual($alert.hasClass('in'), false, 'remove .in class on .close click')
46   })
47
48   QUnit.test('should remove element when clicking .close', function (assert) {
49     assert.expect(2)
50     var alertHTML = '<div class="alert alert-danger fade in">'
51         + '<a class="close" href="#" data-dismiss="alert">×</a>'
52         + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
53         + '</div>'
54     var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert()
55
56     assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom')
57
58     $alert.find('.close').trigger('click')
59
60     assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
61   })
62
63   QUnit.test('should not fire closed when close is prevented', function (assert) {
64     assert.expect(1)
65     var done = assert.async()
66     $('<div class="alert"/>')
67       .on('close.bs.alert', function (e) {
68         e.preventDefault()
69         assert.ok(true, 'close event fired')
70         done()
71       })
72       .on('closed.bs.alert', function () {
73         assert.ok(false, 'closed event fired')
74       })
75       .bootstrapAlert('close')
76   })
77
78 })