tooltip.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. $(function () {
  2. 'use strict'
  3. QUnit.module('tooltip plugin')
  4. QUnit.test('should be defined on jquery object', function (assert) {
  5. assert.expect(1)
  6. assert.ok($(document.body).tooltip, 'tooltip method is defined')
  7. })
  8. QUnit.module('tooltip', {
  9. beforeEach: function () {
  10. // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
  11. $.fn.bootstrapTooltip = $.fn.tooltip.noConflict()
  12. },
  13. afterEach: function () {
  14. $.fn.tooltip = $.fn.bootstrapTooltip
  15. delete $.fn.bootstrapTooltip
  16. $('.tooltip').remove()
  17. $('#qunit-fixture').html('')
  18. }
  19. })
  20. QUnit.test('should provide no conflict', function (assert) {
  21. assert.expect(1)
  22. assert.strictEqual(typeof $.fn.tooltip, 'undefined', 'tooltip was set back to undefined (org value)')
  23. })
  24. QUnit.test('should throw explicit error on undefined method', function (assert) {
  25. assert.expect(1)
  26. var $el = $('<div/>')
  27. $el.bootstrapTooltip()
  28. try {
  29. $el.bootstrapTooltip('noMethod')
  30. } catch (err) {
  31. assert.strictEqual(err.message, 'No method named "noMethod"')
  32. }
  33. })
  34. QUnit.test('should return jquery collection containing the element', function (assert) {
  35. assert.expect(2)
  36. var $el = $('<div/>')
  37. var $tooltip = $el.bootstrapTooltip()
  38. assert.ok($tooltip instanceof $, 'returns jquery collection')
  39. assert.strictEqual($tooltip[0], $el[0], 'collection contains element')
  40. })
  41. QUnit.test('should expose default settings', function (assert) {
  42. assert.expect(1)
  43. assert.ok($.fn.bootstrapTooltip.Constructor.Default, 'defaults is defined')
  44. })
  45. QUnit.test('should empty title attribute', function (assert) {
  46. assert.expect(1)
  47. var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip()
  48. assert.strictEqual($trigger.attr('title'), '', 'title attribute was emptied')
  49. })
  50. QUnit.test('should add data attribute for referencing original title', function (assert) {
  51. assert.expect(1)
  52. var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip()
  53. assert.strictEqual($trigger.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
  54. })
  55. QUnit.test('should add aria-describedby to the trigger on show', function (assert) {
  56. assert.expect(3)
  57. var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  58. .bootstrapTooltip()
  59. .appendTo('#qunit-fixture')
  60. .bootstrapTooltip('show')
  61. var id = $('.tooltip').attr('id')
  62. assert.strictEqual($('#' + id).length, 1, 'has a unique id')
  63. assert.strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match')
  64. assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
  65. })
  66. QUnit.test('should remove aria-describedby from trigger on hide', function (assert) {
  67. assert.expect(2)
  68. var done = assert.async()
  69. var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  70. .bootstrapTooltip()
  71. .appendTo('#qunit-fixture')
  72. $trigger
  73. .one('shown.bs.tooltip', function () {
  74. assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
  75. $trigger.bootstrapTooltip('hide')
  76. })
  77. .one('hidden.bs.tooltip', function () {
  78. assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby')
  79. done()
  80. })
  81. .bootstrapTooltip('show')
  82. })
  83. QUnit.test('should assign a unique id tooltip element', function (assert) {
  84. assert.expect(2)
  85. $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  86. .appendTo('#qunit-fixture')
  87. .bootstrapTooltip('show')
  88. var id = $('.tooltip').attr('id')
  89. assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id')
  90. assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix')
  91. })
  92. QUnit.test('should place tooltips relative to placement option', function (assert) {
  93. assert.expect(2)
  94. var done = assert.async()
  95. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  96. .appendTo('#qunit-fixture')
  97. .bootstrapTooltip({
  98. placement: 'bottom'
  99. })
  100. $tooltip
  101. .one('shown.bs.tooltip', function () {
  102. assert.ok($('.tooltip')
  103. .is('.fade.bs-tooltip-bottom.show'), 'has correct classes applied')
  104. $tooltip.bootstrapTooltip('hide')
  105. })
  106. .one('hidden.bs.tooltip', function () {
  107. assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
  108. done()
  109. })
  110. .bootstrapTooltip('show')
  111. })
  112. QUnit.test('should allow html entities', function (assert) {
  113. assert.expect(2)
  114. var done = assert.async()
  115. var $tooltip = $('<a href="#" rel="tooltip" title="&lt;b&gt;@fat&lt;/b&gt;"/>')
  116. .appendTo('#qunit-fixture')
  117. .bootstrapTooltip({
  118. html: true
  119. })
  120. $tooltip
  121. .one('shown.bs.tooltip', function () {
  122. assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted')
  123. $tooltip.bootstrapTooltip('hide')
  124. })
  125. .one('hidden.bs.tooltip', function () {
  126. assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
  127. done()
  128. })
  129. .bootstrapTooltip('show')
  130. })
  131. QUnit.test('should allow DOMElement title (html: false)', function (assert) {
  132. assert.expect(3)
  133. var done = assert.async()
  134. var title = document.createTextNode('<3 writing tests')
  135. var $tooltip = $('<a href="#" rel="tooltip"/>')
  136. .appendTo('#qunit-fixture')
  137. .bootstrapTooltip({
  138. title: title
  139. })
  140. $tooltip
  141. .one('shown.bs.tooltip', function () {
  142. assert.notEqual($('.tooltip').length, 0, 'tooltip inserted')
  143. assert.strictEqual($('.tooltip').text(), '<3 writing tests', 'title inserted')
  144. assert.ok(!$.contains($('.tooltip').get(0), title), 'title node copied, not moved')
  145. done()
  146. })
  147. .bootstrapTooltip('show')
  148. })
  149. QUnit.test('should allow DOMElement title (html: true)', function (assert) {
  150. assert.expect(3)
  151. var done = assert.async()
  152. var title = document.createTextNode('<3 writing tests')
  153. var $tooltip = $('<a href="#" rel="tooltip"/>')
  154. .appendTo('#qunit-fixture')
  155. .bootstrapTooltip({
  156. html: true,
  157. title: title
  158. })
  159. $tooltip
  160. .one('shown.bs.tooltip', function () {
  161. assert.notEqual($('.tooltip').length, 0, 'tooltip inserted')
  162. assert.strictEqual($('.tooltip').text(), '<3 writing tests', 'title inserted')
  163. assert.ok($.contains($('.tooltip').get(0), title), 'title node moved, not copied')
  164. done()
  165. })
  166. .bootstrapTooltip('show')
  167. })
  168. QUnit.test('should respect custom classes', function (assert) {
  169. assert.expect(2)
  170. var done = assert.async()
  171. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  172. .appendTo('#qunit-fixture')
  173. .bootstrapTooltip({
  174. template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>'
  175. })
  176. $tooltip
  177. .one('shown.bs.tooltip', function () {
  178. assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present')
  179. $tooltip.bootstrapTooltip('hide')
  180. })
  181. .one('hidden.bs.tooltip', function () {
  182. assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
  183. done()
  184. })
  185. .bootstrapTooltip('show')
  186. })
  187. QUnit.test('should fire show event', function (assert) {
  188. assert.expect(1)
  189. var done = assert.async()
  190. $('<div title="tooltip title"/>')
  191. .on('show.bs.tooltip', function () {
  192. assert.ok(true, 'show event fired')
  193. done()
  194. })
  195. .bootstrapTooltip('show')
  196. })
  197. QUnit.test('should throw an error when show is called on hidden elements', function (assert) {
  198. assert.expect(1)
  199. var done = assert.async()
  200. try {
  201. $('<div title="tooltip title" style="display: none"/>').bootstrapTooltip('show')
  202. } catch (err) {
  203. assert.strictEqual(err.message, 'Please use show on visible elements')
  204. done()
  205. }
  206. })
  207. QUnit.test('should fire inserted event', function (assert) {
  208. assert.expect(2)
  209. var done = assert.async()
  210. $('<div title="tooltip title"/>')
  211. .appendTo('#qunit-fixture')
  212. .on('inserted.bs.tooltip', function () {
  213. assert.notEqual($('.tooltip').length, 0, 'tooltip was inserted')
  214. assert.ok(true, 'inserted event fired')
  215. done()
  216. })
  217. .bootstrapTooltip('show')
  218. })
  219. QUnit.test('should fire shown event', function (assert) {
  220. assert.expect(1)
  221. var done = assert.async()
  222. $('<div title="tooltip title"></div>')
  223. .appendTo('#qunit-fixture')
  224. .on('shown.bs.tooltip', function () {
  225. assert.ok(true, 'shown was called')
  226. done()
  227. })
  228. .bootstrapTooltip('show')
  229. })
  230. QUnit.test('should not fire shown event when show was prevented', function (assert) {
  231. assert.expect(1)
  232. var done = assert.async()
  233. $('<div title="tooltip title"/>')
  234. .on('show.bs.tooltip', function (e) {
  235. e.preventDefault()
  236. assert.ok(true, 'show event fired')
  237. done()
  238. })
  239. .on('shown.bs.tooltip', function () {
  240. assert.ok(false, 'shown event fired')
  241. })
  242. .bootstrapTooltip('show')
  243. })
  244. QUnit.test('should fire hide event', function (assert) {
  245. assert.expect(1)
  246. var done = assert.async()
  247. $('<div title="tooltip title"/>')
  248. .appendTo('#qunit-fixture')
  249. .on('shown.bs.tooltip', function () {
  250. $(this).bootstrapTooltip('hide')
  251. })
  252. .on('hide.bs.tooltip', function () {
  253. assert.ok(true, 'hide event fired')
  254. done()
  255. })
  256. .bootstrapTooltip('show')
  257. })
  258. QUnit.test('should fire hidden event', function (assert) {
  259. assert.expect(1)
  260. var done = assert.async()
  261. $('<div title="tooltip title"/>')
  262. .appendTo('#qunit-fixture')
  263. .on('shown.bs.tooltip', function () {
  264. $(this).bootstrapTooltip('hide')
  265. })
  266. .on('hidden.bs.tooltip', function () {
  267. assert.ok(true, 'hidden event fired')
  268. done()
  269. })
  270. .bootstrapTooltip('show')
  271. })
  272. QUnit.test('should not fire hidden event when hide was prevented', function (assert) {
  273. assert.expect(1)
  274. var done = assert.async()
  275. $('<div title="tooltip title"/>')
  276. .appendTo('#qunit-fixture')
  277. .on('shown.bs.tooltip', function () {
  278. $(this).bootstrapTooltip('hide')
  279. })
  280. .on('hide.bs.tooltip', function (e) {
  281. e.preventDefault()
  282. assert.ok(true, 'hide event fired')
  283. done()
  284. })
  285. .on('hidden.bs.tooltip', function () {
  286. assert.ok(false, 'hidden event fired')
  287. })
  288. .bootstrapTooltip('show')
  289. })
  290. QUnit.test('should destroy tooltip', function (assert) {
  291. assert.expect(7)
  292. var $tooltip = $('<div/>')
  293. .bootstrapTooltip()
  294. .on('click.foo', function () {}) // eslint-disable-line no-empty-function
  295. assert.ok($tooltip.data('bs.tooltip'), 'tooltip has data')
  296. assert.ok($._data($tooltip[0], 'events').mouseover && $._data($tooltip[0], 'events').mouseout, 'tooltip has hover events')
  297. assert.strictEqual($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip has extra click.foo event')
  298. $tooltip.bootstrapTooltip('show')
  299. $tooltip.bootstrapTooltip('dispose')
  300. assert.ok(!$tooltip.hasClass('show'), 'tooltip is hidden')
  301. assert.ok(!$._data($tooltip[0], 'bs.tooltip'), 'tooltip does not have data')
  302. assert.strictEqual($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip still has click.foo')
  303. assert.ok(!$._data($tooltip[0], 'events').mouseover && !$._data($tooltip[0], 'events').mouseout, 'tooltip does not have hover events')
  304. })
  305. // QUnit.test('should show tooltip with delegate selector on click', function (assert) {
  306. // assert.expect(2)
  307. // var $div = $('<div><a href="#" rel="tooltip" title="Another tooltip"/></div>')
  308. // .appendTo('#qunit-fixture')
  309. // .bootstrapTooltip({
  310. // selector: 'a[rel="tooltip"]',
  311. // trigger: 'click'
  312. // })
  313. // $div.find('a').trigger('click')
  314. // assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
  315. // $div.find('a').trigger('click')
  316. // assert.strictEqual($div.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
  317. // })
  318. QUnit.test('should show tooltip when toggle is called', function (assert) {
  319. assert.expect(1)
  320. $('<a href="#" rel="tooltip" title="tooltip on toggle"/>')
  321. .appendTo('#qunit-fixture')
  322. .bootstrapTooltip({
  323. trigger: 'manual'
  324. })
  325. .bootstrapTooltip('toggle')
  326. assert.ok($('.tooltip').is('.fade.show'), 'tooltip is faded active')
  327. })
  328. QUnit.test('should hide previously shown tooltip when toggle is called on tooltip', function (assert) {
  329. assert.expect(1)
  330. $('<a href="#" rel="tooltip" title="tooltip on toggle">@ResentedHook</a>')
  331. .appendTo('#qunit-fixture')
  332. .bootstrapTooltip({
  333. trigger: 'manual'
  334. })
  335. .bootstrapTooltip('show')
  336. $('.tooltip').bootstrapTooltip('toggle')
  337. assert.ok($('.tooltip').not('.fade.show'), 'tooltip was faded out')
  338. })
  339. QUnit.test('should place tooltips inside body when container is body', function (assert) {
  340. assert.expect(3)
  341. var done = assert.async()
  342. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  343. .appendTo('#qunit-fixture')
  344. .bootstrapTooltip({
  345. container: 'body'
  346. })
  347. $tooltip
  348. .one('shown.bs.tooltip', function () {
  349. assert.notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body')
  350. assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
  351. $tooltip.bootstrapTooltip('hide')
  352. })
  353. .one('hidden.bs.tooltip', function () {
  354. assert.strictEqual($('body > .tooltip').length, 0, 'tooltip was removed from dom')
  355. done()
  356. })
  357. .bootstrapTooltip('show')
  358. })
  359. QUnit.test('should place tooltips inside a specific container when container is an element', function (assert) {
  360. assert.expect(3)
  361. var done = assert.async()
  362. var $container = $('<div></div>').appendTo('#qunit-fixture')
  363. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  364. .appendTo('#qunit-fixture')
  365. .bootstrapTooltip({
  366. container: $container[0]
  367. })
  368. $tooltip
  369. .one('shown.bs.tooltip', function () {
  370. assert.strictEqual($container.find('.tooltip').length, 1)
  371. assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
  372. $tooltip.bootstrapTooltip('hide')
  373. })
  374. .one('hidden.bs.tooltip', function () {
  375. assert.strictEqual($container.find('.tooltip').length, 0, 'tooltip was removed from dom')
  376. done()
  377. })
  378. .bootstrapTooltip('show')
  379. })
  380. QUnit.test('should place tooltips inside a specific container when container is a selector', function (assert) {
  381. assert.expect(3)
  382. var done = assert.async()
  383. var $container = $('<div id="container"></div>').appendTo('#qunit-fixture')
  384. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  385. .appendTo('#qunit-fixture')
  386. .bootstrapTooltip({
  387. container: '#container'
  388. })
  389. $tooltip
  390. .one('shown.bs.tooltip', function () {
  391. assert.strictEqual($container.find('.tooltip').length, 1)
  392. assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
  393. $tooltip.bootstrapTooltip('hide')
  394. })
  395. .one('hidden.bs.tooltip', function () {
  396. assert.strictEqual($container.find('.tooltip').length, 0, 'tooltip was removed from dom')
  397. done()
  398. })
  399. .bootstrapTooltip('show')
  400. })
  401. QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) {
  402. assert.expect(2)
  403. var done = assert.async()
  404. var styles = '<style>' +
  405. '.bs-tooltip-right { white-space: nowrap; }' +
  406. '.bs-tooltip-right .tooltip-inner { max-width: none; }' +
  407. '</style>'
  408. var $styles = $(styles).appendTo('head')
  409. var $container = $('<div/>').appendTo('#qunit-fixture')
  410. $('<a href="#" rel="tooltip" title="very very very very very very very very long tooltip in one line"/>')
  411. .appendTo($container)
  412. .bootstrapTooltip({
  413. placement: 'right',
  414. trigger: 'manual'
  415. })
  416. .on('inserted.bs.tooltip', function () {
  417. var $tooltip = $($(this).data('bs.tooltip').tip)
  418. assert.ok($tooltip.hasClass('bs-tooltip-right'))
  419. assert.ok(typeof $tooltip.attr('style') === 'undefined')
  420. $styles.remove()
  421. done()
  422. })
  423. .bootstrapTooltip('show')
  424. })
  425. QUnit.test('should use title attribute for tooltip text', function (assert) {
  426. assert.expect(2)
  427. var done = assert.async()
  428. var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
  429. .appendTo('#qunit-fixture')
  430. .bootstrapTooltip()
  431. $tooltip
  432. .one('shown.bs.tooltip', function () {
  433. assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
  434. $tooltip.bootstrapTooltip('hide')
  435. })
  436. .one('hidden.bs.tooltip', function () {
  437. assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
  438. done()
  439. })
  440. .bootstrapTooltip('show')
  441. })
  442. QUnit.test('should prefer title attribute over title option', function (assert) {
  443. assert.expect(2)
  444. var done = assert.async()
  445. var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
  446. .appendTo('#qunit-fixture')
  447. .bootstrapTooltip({
  448. title: 'This is a tooltip with some content'
  449. })
  450. $tooltip
  451. .one('shown.bs.tooltip', function () {
  452. assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while preferred over title option')
  453. $tooltip.bootstrapTooltip('hide')
  454. })
  455. .one('hidden.bs.tooltip', function () {
  456. assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
  457. done()
  458. })
  459. .bootstrapTooltip('show')
  460. })
  461. QUnit.test('should use title option', function (assert) {
  462. assert.expect(2)
  463. var done = assert.async()
  464. var $tooltip = $('<a href="#" rel="tooltip"/>')
  465. .appendTo('#qunit-fixture')
  466. .bootstrapTooltip({
  467. title: 'This is a tooltip with some content'
  468. })
  469. $tooltip
  470. .one('shown.bs.tooltip', function () {
  471. assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
  472. $tooltip.bootstrapTooltip('hide')
  473. })
  474. .one('hidden.bs.tooltip', function () {
  475. assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
  476. done()
  477. })
  478. .bootstrapTooltip('show')
  479. })
  480. QUnit.test('should not error when trying to show an top-placed tooltip that has been removed from the dom', function (assert) {
  481. assert.expect(1)
  482. var passed = true
  483. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  484. .appendTo('#qunit-fixture')
  485. .one('show.bs.tooltip', function () {
  486. $(this).remove()
  487. })
  488. .bootstrapTooltip({
  489. placement: 'top'
  490. })
  491. try {
  492. $tooltip.bootstrapTooltip('show')
  493. } catch (err) {
  494. passed = false
  495. }
  496. assert.ok(passed, '.tooltip(\'show\') should not throw an error if element no longer is in dom')
  497. })
  498. QUnit.test('should show tooltip if leave event hasn\'t occurred before delay expires', function (assert) {
  499. assert.expect(2)
  500. var done = assert.async()
  501. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  502. .appendTo('#qunit-fixture')
  503. .bootstrapTooltip({
  504. delay: 150
  505. })
  506. setTimeout(function () {
  507. assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip is not faded active')
  508. }, 100)
  509. setTimeout(function () {
  510. assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip is faded active')
  511. done()
  512. }, 200)
  513. $tooltip.trigger('mouseenter')
  514. })
  515. QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) {
  516. assert.expect(2)
  517. var done = assert.async()
  518. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  519. .appendTo('#qunit-fixture')
  520. .bootstrapTooltip({
  521. delay: 150
  522. })
  523. setTimeout(function () {
  524. assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active')
  525. $tooltip.trigger('mouseout')
  526. }, 100)
  527. setTimeout(function () {
  528. assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active')
  529. done()
  530. }, 200)
  531. $tooltip.trigger('mouseenter')
  532. })
  533. QUnit.test('should not hide tooltip if leave event occurs and enter event occurs within the hide delay', function (assert) {
  534. assert.expect(3)
  535. var done = assert.async()
  536. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  537. .appendTo('#qunit-fixture')
  538. .bootstrapTooltip({
  539. delay: {
  540. show: 0,
  541. hide: 150
  542. }
  543. })
  544. setTimeout(function () {
  545. assert.ok($('.tooltip').is('.fade.show'), '1ms: tooltip faded active')
  546. $tooltip.trigger('mouseout')
  547. setTimeout(function () {
  548. assert.ok($('.tooltip').is('.fade.show'), '100ms: tooltip still faded active')
  549. $tooltip.trigger('mouseenter')
  550. }, 100)
  551. setTimeout(function () {
  552. assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip still faded active')
  553. done()
  554. }, 200)
  555. }, 0)
  556. $tooltip.trigger('mouseenter')
  557. })
  558. QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) {
  559. assert.expect(2)
  560. var done = assert.async()
  561. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  562. .appendTo('#qunit-fixture')
  563. .bootstrapTooltip({
  564. delay: 150
  565. })
  566. setTimeout(function () {
  567. assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active')
  568. $tooltip.trigger('mouseout')
  569. }, 100)
  570. setTimeout(function () {
  571. assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active')
  572. done()
  573. }, 200)
  574. $tooltip.trigger('mouseenter')
  575. })
  576. QUnit.test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function (assert) {
  577. assert.expect(2)
  578. var done = assert.async()
  579. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  580. .appendTo('#qunit-fixture')
  581. .bootstrapTooltip({
  582. delay: {
  583. show: 150,
  584. hide: 0
  585. }
  586. })
  587. setTimeout(function () {
  588. assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active')
  589. $tooltip.trigger('mouseout')
  590. }, 100)
  591. setTimeout(function () {
  592. assert.ok(!$('.tooltip').is('.fade.show'), '250ms: tooltip not faded active')
  593. done()
  594. }, 250)
  595. $tooltip.trigger('mouseenter')
  596. })
  597. QUnit.test('should wait 200ms before hiding the tooltip', function (assert) {
  598. assert.expect(3)
  599. var done = assert.async()
  600. var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
  601. .appendTo('#qunit-fixture')
  602. .bootstrapTooltip({
  603. delay: {
  604. show: 0,
  605. hide: 150
  606. }
  607. })
  608. setTimeout(function () {
  609. assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '1ms: tooltip faded active')
  610. $tooltip.trigger('mouseout')
  611. setTimeout(function () {
  612. assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '100ms: tooltip still faded active')
  613. }, 100)
  614. setTimeout(function () {
  615. assert.ok(!$($tooltip.data('bs.tooltip').tip).is('.show'), '200ms: tooltip removed')
  616. done()
  617. }, 200)
  618. }, 0)
  619. $tooltip.trigger('mouseenter')
  620. })
  621. QUnit.test('should not reload the tooltip on subsequent mouseenter events', function (assert) {
  622. assert.expect(1)
  623. var titleHtml = function () {
  624. var uid = Util.getUID('tooltip')
  625. return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>'
  626. }
  627. var $tooltip = $('<span id="tt-outer" rel="tooltip" data-trigger="hover" data-placement="top">some text</span>')
  628. .appendTo('#qunit-fixture')
  629. $tooltip.bootstrapTooltip({
  630. html: true,
  631. animation: false,
  632. trigger: 'hover',
  633. delay: {
  634. show: 0,
  635. hide: 500
  636. },
  637. container: $tooltip,
  638. title: titleHtml
  639. })
  640. $('#tt-outer').trigger('mouseenter')
  641. var currentUid = $('#tt-content').text()
  642. $('#tt-content').trigger('mouseenter')
  643. assert.strictEqual(currentUid, $('#tt-content').text())
  644. })
  645. QUnit.test('should not reload the tooltip if the mouse leaves and re-enters before hiding', function (assert) {
  646. assert.expect(4)
  647. var titleHtml = function () {
  648. var uid = Util.getUID('tooltip')
  649. return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>'
  650. }
  651. var $tooltip = $('<span id="tt-outer" rel="tooltip" data-trigger="hover" data-placement="top">some text</span>')
  652. .appendTo('#qunit-fixture')
  653. $tooltip.bootstrapTooltip({
  654. html: true,
  655. animation: false,
  656. trigger: 'hover',
  657. delay: {
  658. show: 0,
  659. hide: 500
  660. },
  661. title: titleHtml
  662. })
  663. var obj = $tooltip.data('bs.tooltip')
  664. $('#tt-outer').trigger('mouseenter')
  665. var currentUid = $('#tt-content').text()
  666. $('#tt-outer').trigger('mouseleave')
  667. assert.strictEqual(currentUid, $('#tt-content').text())
  668. assert.ok(obj._hoverState === 'out', 'the tooltip hoverState should be set to "out"')
  669. $('#tt-outer').trigger('mouseenter')
  670. assert.ok(obj._hoverState === 'show', 'the tooltip hoverState should be set to "show"')
  671. assert.strictEqual(currentUid, $('#tt-content').text())
  672. })
  673. QUnit.test('should do nothing when an attempt is made to hide an uninitialized tooltip', function (assert) {
  674. assert.expect(1)
  675. var $tooltip = $('<span data-toggle="tooltip" title="some tip">some text</span>')
  676. .appendTo('#qunit-fixture')
  677. .on('hidden.bs.tooltip shown.bs.tooltip', function () {
  678. assert.ok(false, 'should not fire any tooltip events')
  679. })
  680. .bootstrapTooltip('hide')
  681. assert.strictEqual(typeof $tooltip.data('bs.tooltip'), 'undefined', 'should not initialize the tooltip')
  682. })
  683. QUnit.test('should not remove tooltip if multiple triggers are set and one is still active', function (assert) {
  684. assert.expect(41)
  685. var $el = $('<button>Trigger</button>')
  686. .appendTo('#qunit-fixture')
  687. .bootstrapTooltip({
  688. trigger: 'click hover focus',
  689. animation: false
  690. })
  691. var tooltip = $el.data('bs.tooltip')
  692. var $tooltip = $(tooltip.getTipElement())
  693. function showingTooltip() {
  694. return $tooltip.hasClass('show') || tooltip._hoverState === 'show'
  695. }
  696. var tests = [
  697. ['mouseenter', 'mouseleave'],
  698. ['focusin', 'focusout'],
  699. ['click', 'click'],
  700. ['mouseenter', 'focusin', 'focusout', 'mouseleave'],
  701. ['mouseenter', 'focusin', 'mouseleave', 'focusout'],
  702. ['focusin', 'mouseenter', 'mouseleave', 'focusout'],
  703. ['focusin', 'mouseenter', 'focusout', 'mouseleave'],
  704. ['click', 'focusin', 'mouseenter', 'focusout', 'mouseleave', 'click'],
  705. ['mouseenter', 'click', 'focusin', 'focusout', 'mouseleave', 'click'],
  706. ['mouseenter', 'focusin', 'click', 'click', 'mouseleave', 'focusout']
  707. ]
  708. assert.ok(!showingTooltip())
  709. $.each(tests, function (idx, triggers) {
  710. for (var i = 0, len = triggers.length; i < len; i++) {
  711. $el.trigger(triggers[i])
  712. assert.equal(i < len - 1, showingTooltip())
  713. }
  714. })
  715. })
  716. QUnit.test('should show on first trigger after hide', function (assert) {
  717. assert.expect(3)
  718. var $el = $('<a href="#" rel="tooltip" title="Test tooltip"/>')
  719. .appendTo('#qunit-fixture')
  720. .bootstrapTooltip({
  721. trigger: 'click hover focus',
  722. animation: false
  723. })
  724. var tooltip = $el.data('bs.tooltip')
  725. var $tooltip = $(tooltip.getTipElement())
  726. function showingTooltip() {
  727. return $tooltip.hasClass('show') || tooltip._hoverState === 'show'
  728. }
  729. $el.trigger('click')
  730. assert.ok(showingTooltip(), 'tooltip is faded in')
  731. $el.bootstrapTooltip('hide')
  732. assert.ok(!showingTooltip(), 'tooltip was faded out')
  733. $el.trigger('click')
  734. assert.ok(showingTooltip(), 'tooltip is faded in again')
  735. })
  736. QUnit.test('should hide tooltip when their containing modal is closed', function (assert) {
  737. assert.expect(1)
  738. var done = assert.async()
  739. var templateHTML = '<div id="modal-test" class="modal">' +
  740. '<div class="modal-dialog" role="document">' +
  741. '<div class="modal-content">' +
  742. '<div class="modal-body">' +
  743. '<a id="tooltipTest" href="#" data-toggle="tooltip" title="Some tooltip text!">Tooltip</a>' +
  744. '</div>' +
  745. '</div>' +
  746. '</div>' +
  747. '</div>'
  748. $(templateHTML).appendTo('#qunit-fixture')
  749. $('#tooltipTest')
  750. .bootstrapTooltip({
  751. trigger: 'manuel'
  752. })
  753. .on('shown.bs.tooltip', function () {
  754. $('#modal-test').modal('hide')
  755. })
  756. .on('hide.bs.tooltip', function () {
  757. assert.ok(true, 'tooltip hide')
  758. done()
  759. })
  760. $('#modal-test')
  761. .on('shown.bs.modal', function () {
  762. $('#tooltipTest').bootstrapTooltip('show')
  763. })
  764. .modal('show')
  765. })
  766. QUnit.test('should allow to close modal if the tooltip element is detached', function (assert) {
  767. assert.expect(1)
  768. var done = assert.async()
  769. var templateHTML = [
  770. '<div id="modal-test" class="modal">',
  771. ' <div class="modal-dialog" role="document">',
  772. ' <div class="modal-content">',
  773. ' <div class="modal-body">',
  774. ' <a id="tooltipTest" href="#" data-toggle="tooltip" title="Some tooltip text!">Tooltip</a>',
  775. ' </div>',
  776. ' </div>',
  777. ' </div>',
  778. '</div>'
  779. ].join('')
  780. $(templateHTML).appendTo('#qunit-fixture')
  781. var $tooltip = $('#tooltipTest')
  782. var $modal = $('#modal-test')
  783. $tooltip.on('shown.bs.tooltip', function () {
  784. $tooltip.detach()
  785. $tooltip.bootstrapTooltip('dispose')
  786. $modal.modal('hide')
  787. })
  788. $modal.on('shown.bs.modal', function () {
  789. $tooltip.bootstrapTooltip({
  790. trigger: 'manuel'
  791. })
  792. .bootstrapTooltip('show')
  793. })
  794. .on('hidden.bs.modal', function () {
  795. assert.ok(true, 'modal hidden')
  796. done()
  797. })
  798. .modal('show')
  799. })
  800. QUnit.test('should reset tip classes when hidden event triggered', function (assert) {
  801. assert.expect(2)
  802. var done = assert.async()
  803. var $el = $('<a href="#" rel="tooltip" title="Test tooltip"/>')
  804. .appendTo('#qunit-fixture')
  805. .bootstrapTooltip('show')
  806. .on('hidden.bs.tooltip', function () {
  807. var tooltip = $el.data('bs.tooltip')
  808. var $tooltip = $(tooltip.getTipElement())
  809. assert.ok($tooltip.hasClass('tooltip'))
  810. assert.ok($tooltip.hasClass('fade'))
  811. done()
  812. })
  813. $el.bootstrapTooltip('hide')
  814. })
  815. QUnit.test('should convert number in title to string', function (assert) {
  816. assert.expect(1)
  817. var done = assert.async()
  818. var $el = $('<a href="#" rel="tooltip" title="7"/>')
  819. .appendTo('#qunit-fixture')
  820. .on('shown.bs.tooltip', function () {
  821. var tooltip = $el.data('bs.tooltip')
  822. var $tooltip = $(tooltip.getTipElement())
  823. assert.strictEqual($tooltip.children().text(), '7')
  824. done()
  825. })
  826. $el.bootstrapTooltip('show')
  827. })
  828. QUnit.test('tooltip should be shown right away after the call of disable/enable', function (assert) {
  829. assert.expect(2)
  830. var done = assert.async()
  831. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  832. .appendTo('#qunit-fixture')
  833. .bootstrapTooltip()
  834. .on('shown.bs.tooltip', function () {
  835. assert.strictEqual($('.tooltip').hasClass('show'), true)
  836. done()
  837. })
  838. $trigger.bootstrapTooltip('disable')
  839. $trigger.trigger($.Event('click'))
  840. setTimeout(function () {
  841. assert.strictEqual($('.tooltip').length === 0, true)
  842. $trigger.bootstrapTooltip('enable')
  843. $trigger.trigger($.Event('click'))
  844. }, 200)
  845. })
  846. QUnit.test('should call Popper.js to update', function (assert) {
  847. assert.expect(2)
  848. var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  849. .appendTo('#qunit-fixture')
  850. .bootstrapTooltip()
  851. var tooltip = $tooltip.data('bs.tooltip')
  852. tooltip.show()
  853. assert.ok(tooltip._popper)
  854. var spyPopper = sinon.spy(tooltip._popper, 'scheduleUpdate')
  855. tooltip.update()
  856. assert.ok(spyPopper.called)
  857. })
  858. QUnit.test('should not call Popper.js to update', function (assert) {
  859. assert.expect(1)
  860. var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  861. .appendTo('#qunit-fixture')
  862. .bootstrapTooltip()
  863. var tooltip = $tooltip.data('bs.tooltip')
  864. tooltip.update()
  865. assert.ok(tooltip._popper === null)
  866. })
  867. QUnit.test('should use Popper.js to get the tip on placement change', function (assert) {
  868. assert.expect(1)
  869. var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  870. .appendTo('#qunit-fixture')
  871. .bootstrapTooltip()
  872. var $tipTest = $('<div class="bs-tooltip" />')
  873. .appendTo('#qunit-fixture')
  874. var tooltip = $tooltip.data('bs.tooltip')
  875. tooltip.tip = null
  876. tooltip._handlePopperPlacementChange({
  877. instance: {
  878. popper: $tipTest[0]
  879. },
  880. placement: 'auto'
  881. })
  882. assert.ok(tooltip.tip === $tipTest[0])
  883. })
  884. QUnit.test('should toggle enabled', function (assert) {
  885. assert.expect(3)
  886. var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  887. .appendTo('#qunit-fixture')
  888. .bootstrapTooltip()
  889. var tooltip = $tooltip.data('bs.tooltip')
  890. assert.strictEqual(tooltip._isEnabled, true)
  891. tooltip.toggleEnabled()
  892. assert.strictEqual(tooltip._isEnabled, false)
  893. tooltip.toggleEnabled()
  894. assert.strictEqual(tooltip._isEnabled, true)
  895. })
  896. QUnit.test('should create offset modifier correctly when offset option is a function', function (assert) {
  897. assert.expect(2)
  898. var getOffset = function (offsets) {
  899. return offsets
  900. }
  901. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  902. .appendTo('#qunit-fixture')
  903. .bootstrapTooltip({
  904. offset: getOffset
  905. })
  906. var tooltip = $trigger.data('bs.tooltip')
  907. var offset = tooltip._getOffset()
  908. assert.ok(typeof offset.offset === 'undefined')
  909. assert.ok(typeof offset.fn === 'function')
  910. })
  911. QUnit.test('should create offset modifier correctly when offset option is not a function', function (assert) {
  912. assert.expect(2)
  913. var myOffset = 42
  914. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  915. .appendTo('#qunit-fixture')
  916. .bootstrapTooltip({
  917. offset: myOffset
  918. })
  919. var tooltip = $trigger.data('bs.tooltip')
  920. var offset = tooltip._getOffset()
  921. assert.strictEqual(offset.offset, myOffset)
  922. assert.ok(typeof offset.fn === 'undefined')
  923. })
  924. QUnit.test('should disable sanitizer', function (assert) {
  925. assert.expect(1)
  926. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  927. .appendTo('#qunit-fixture')
  928. .bootstrapTooltip({
  929. sanitize: false
  930. })
  931. var tooltip = $trigger.data('bs.tooltip')
  932. assert.strictEqual(tooltip.config.sanitize, false)
  933. })
  934. QUnit.test('should sanitize template by removing disallowed tags', function (assert) {
  935. assert.expect(1)
  936. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  937. .appendTo('#qunit-fixture')
  938. .bootstrapTooltip({
  939. template: [
  940. '<div>',
  941. ' <script>console.log("oups script inserted")</script>',
  942. ' <span>Some content</span>',
  943. '</div>'
  944. ].join('')
  945. })
  946. var tooltip = $trigger.data('bs.tooltip')
  947. assert.strictEqual(tooltip.config.template.indexOf('script'), -1)
  948. })
  949. QUnit.test('should sanitize template by removing disallowed attributes', function (assert) {
  950. assert.expect(1)
  951. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  952. .appendTo('#qunit-fixture')
  953. .bootstrapTooltip({
  954. template: [
  955. '<div>',
  956. ' <img src="x" onError="alert(\'test\')">Some content</img>',
  957. '</div>'
  958. ].join('')
  959. })
  960. var tooltip = $trigger.data('bs.tooltip')
  961. assert.strictEqual(tooltip.config.template.indexOf('onError'), -1)
  962. })
  963. QUnit.test('should sanitize template by removing tags with XSS', function (assert) {
  964. assert.expect(1)
  965. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  966. .appendTo('#qunit-fixture')
  967. .bootstrapTooltip({
  968. template: [
  969. '<div>',
  970. ' <a href="javascript:alert(7)">Click me</a>',
  971. ' <span>Some content</span>',
  972. '</div>'
  973. ].join('')
  974. })
  975. var tooltip = $trigger.data('bs.tooltip')
  976. assert.strictEqual(tooltip.config.template.indexOf('script'), -1)
  977. })
  978. QUnit.test('should allow custom sanitization rules', function (assert) {
  979. assert.expect(2)
  980. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  981. .appendTo('#qunit-fixture')
  982. .bootstrapTooltip({
  983. template: [
  984. '<a href="javascript:alert(7)">Click me</a>',
  985. '<span>Some content</span>'
  986. ].join(''),
  987. whiteList: {
  988. span: null
  989. }
  990. })
  991. var tooltip = $trigger.data('bs.tooltip')
  992. assert.strictEqual(tooltip.config.template.indexOf('<a'), -1)
  993. assert.ok(tooltip.config.template.indexOf('span') !== -1)
  994. })
  995. QUnit.test('should allow passing a custom function for sanitization', function (assert) {
  996. assert.expect(1)
  997. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  998. .appendTo('#qunit-fixture')
  999. .bootstrapTooltip({
  1000. template: [
  1001. '<span>Some content</span>'
  1002. ].join(''),
  1003. sanitizeFn: function (input) {
  1004. return input
  1005. }
  1006. })
  1007. var tooltip = $trigger.data('bs.tooltip')
  1008. assert.ok(tooltip.config.template.indexOf('span') !== -1)
  1009. })
  1010. QUnit.test('should allow passing aria attributes', function (assert) {
  1011. assert.expect(1)
  1012. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  1013. .appendTo('#qunit-fixture')
  1014. .bootstrapTooltip({
  1015. template: [
  1016. '<span aria-pressed="true">Some content</span>'
  1017. ].join('')
  1018. })
  1019. var tooltip = $trigger.data('bs.tooltip')
  1020. assert.ok(tooltip.config.template.indexOf('aria-pressed') !== -1)
  1021. })
  1022. QUnit.test('should not sanitize element content', function (assert) {
  1023. assert.expect(1)
  1024. var $element = $('<div />').appendTo('#qunit-fixture')
  1025. var content = '<script>var test = 1;</script>'
  1026. var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
  1027. .appendTo('#qunit-fixture')
  1028. .bootstrapTooltip({
  1029. template: [
  1030. '<span aria-pressed="true">Some content</span>'
  1031. ].join(''),
  1032. html: true,
  1033. sanitize: false
  1034. })
  1035. var tooltip = $trigger.data('bs.tooltip')
  1036. tooltip.setElementContent($element, content)
  1037. assert.strictEqual($element[0].innerHTML, content)
  1038. })
  1039. QUnit.test('should not take into account sanitize in data attributes', function (assert) {
  1040. assert.expect(1)
  1041. var $trigger = $('<a href="#" rel="tooltip" data-sanitize="false" data-trigger="click" title="Another tooltip"/>')
  1042. .appendTo('#qunit-fixture')
  1043. .bootstrapTooltip({
  1044. template: [
  1045. '<span aria-pressed="true">Some content</span>'
  1046. ].join('')
  1047. })
  1048. var tooltip = $trigger.data('bs.tooltip')
  1049. assert.strictEqual(tooltip.config.sanitize, true)
  1050. })
  1051. })