[ADD] doc: new documentation, with training tutorials, and new scaffolding
[odoo/odoo.git] / doc / _themes / odoodoc / static / bootstrap / js / tests / unit / affix.js
1 $(function () {
2   'use strict';
3
4   module('affix plugin')
5
6   test('should be defined on jquery object', function () {
7     ok($(document.body).affix, 'affix method is defined')
8   })
9
10   module('affix', {
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.bootstrapAffix = $.fn.affix.noConflict()
14     },
15     teardown: function () {
16       $.fn.affix = $.fn.bootstrapAffix
17       delete $.fn.bootstrapAffix
18     }
19   })
20
21   test('should provide no conflict', function () {
22     ok(!$.fn.affix, 'affix was set back to undefined (org value)')
23   })
24
25   test('should return element', function () {
26     ok($(document.body).bootstrapAffix()[0] == document.body, 'document.body returned')
27   })
28
29   test('should exit early if element is not visible', function () {
30     var $affix = $('<div style="display: none"></div>').bootstrapAffix()
31     $affix.data('bs.affix').checkPosition()
32     ok(!$affix.hasClass('affix'), 'affix class was not added')
33   })
34
35   test('should trigger affixed event after affix', function () {
36     stop()
37
38     var template = $('<div id="affixTarget"><ul><li>Please affix</li><li>And unaffix</li></ul></div><div id="affixAfter" style="height: 20000px; display:block;"></div>')
39     template.appendTo('body')
40
41     $('#affixTarget').bootstrapAffix({
42       offset: $('#affixTarget ul').position()
43     })
44
45     $('#affixTarget')
46       .on('affix.bs.affix', function () {
47         ok(true, 'affix event triggered')
48       }).on('affixed.bs.affix', function () {
49         ok(true, 'affixed event triggered')
50         $('#affixTarget').remove()
51         $('#affixAfter').remove()
52         start()
53       })
54
55     setTimeout(function () {
56       window.scrollTo(0, document.body.scrollHeight)
57       setTimeout(function () {
58         window.scroll(0, 0)
59       }, 0)
60     }, 0)
61   })
62 })