[ADD] doc: new documentation, with training tutorials, and new scaffolding
[odoo/odoo.git] / doc / _themes / odoodoc / static / bootstrap / js / tests / unit / alert.js
1 $(function () {
2   'use strict';
3
4   module('alert plugin')
5
6   test('should be defined on jquery object', function () {
7     ok($(document.body).alert, 'alert method is defined')
8   })
9
10   module('alert', {
11     setup: function () {
12       // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
13       $.fn.bootstrapAlert = $.fn.alert.noConflict()
14     },
15     teardown: function () {
16       $.fn.alert = $.fn.bootstrapAlert
17       delete $.fn.bootstrapAlert
18     }
19   })
20
21   test('should provide no conflict', function () {
22     ok(!$.fn.alert, 'alert was set back to undefined (org value)')
23   })
24
25   test('should return element', function () {
26     ok($(document.body).bootstrapAlert()[0] == document.body, 'document.body returned')
27   })
28
29   test('should fade element out on clicking .close', function () {
30     var alertHTML = '<div class="alert-message warning fade in">' +
31         '<a class="close" href="#" data-dismiss="alert">×</a>' +
32         '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' +
33         '</div>'
34     var alert = $(alertHTML).bootstrapAlert()
35
36     alert.find('.close').click()
37
38     ok(!alert.hasClass('in'), 'remove .in class on .close click')
39   })
40
41   test('should remove element when clicking .close', function () {
42     $.support.transition = false
43
44     var alertHTML = '<div class="alert-message warning fade in">' +
45         '<a class="close" href="#" data-dismiss="alert">×</a>' +
46         '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' +
47         '</div>'
48     var alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert()
49
50     ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom')
51
52     alert.find('.close').click()
53
54     ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
55   })
56
57   test('should not fire closed when close is prevented', function () {
58     $.support.transition = false
59     stop()
60     $('<div class="alert"/>')
61       .on('close.bs.alert', function (e) {
62         e.preventDefault()
63         ok(true)
64         start()
65       })
66       .on('closed.bs.alert', function () {
67         ok(false)
68       })
69       .bootstrapAlert('close')
70   })
71
72 })