aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/tooltip/tooltip_options.js
blob: 04bb4c6a4f8bce74c7530474cb1e6ab9b114bf0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function( $ ) {

module( "tooltip: options" );

test( "content: default", function() {
	var element = $( "#tooltipped1" ).tooltip().tooltip( "open" );
	same( $( "#" + element.attr( "aria-describedby" ) ).text(), "anchortitle" );
});

test( "content: return string", function() {
	var element = $( "#tooltipped1" ).tooltip({
		content: function() {
			return "customstring";
		}
	}).tooltip( "open" );
	same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" );
});

test( "content: return jQuery", function() {
	var element = $( "#tooltipped1" ).tooltip({
		content: function() {
			return $( "<div>" ).html( "cu<b>s</b>tomstring" );
		}
	}).tooltip( "open" );
	same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" );
});

asyncTest( "content: sync + async callback", function() {
	expect( 2 );
	var element = $( "#tooltipped1" ).tooltip({
		content: function( response ) {
			setTimeout(function() {
				same( $( "#" + element.attr("aria-describedby") ).text(), "loading..." );

				response( "customstring2" );
				setTimeout(function() {
					same( $( "#" + element.attr("aria-describedby") ).text(), "customstring2" );
					start();
				}, 13 );
			}, 13 );
			return "loading...";
		}
	}).tooltip( "open" );
});

test( "items", function() {
	expect( 2 );
	var element = $( "#qunit-fixture" ).tooltip({
		items: "#fixture-span"
	});

	var event = $.Event( "mouseenter" );
	event.target = $( "#fixture-span" )[ 0 ];
	element.tooltip( "open", event );
	same( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "title-text" );

	// make sure default [title] doesn't get used
	event.target = $( "#tooltipped1" )[ 0 ];
	element.tooltip( "open", event );
	same( $( "#tooltipped1" ).attr( "aria-describedby" ), undefined );

	element.tooltip( "destroy" );
});

test( "tooltipClass", function() {
	expect( 1 )
	var element = $( "#tooltipped1" ).tooltip({
		tooltipClass: "custom"
	}).tooltip( "open" );
	ok( $( "#" + element.attr( "aria-describedby" ) ).hasClass( "custom" ) );
});

}( jQuery ) );