| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"./helper", |
| 5 |
"ui/widgets/tooltip" |
| 6 |
], function( QUnit, $, testHelper ) { |
| 7 |
"use strict"; |
| 8 |
|
| 9 |
var beforeAfterEach = testHelper.beforeAfterEach; |
| 10 |
|
| 11 |
QUnit.module( "tooltip: methods", beforeAfterEach() ); |
| 12 |
|
| 13 |
QUnit.test( "destroy", function( assert ) { |
| 14 |
assert.expect( 3 ); |
| 15 |
var element = $( "#tooltipped1" ); |
| 16 |
|
| 17 |
assert.domEqual( "#tooltipped1", function() { |
| 18 |
element.tooltip().tooltip( "destroy" ); |
| 19 |
} ); |
| 20 |
|
| 21 |
|
| 22 |
assert.domEqual( "#tooltipped1", function() { |
| 23 |
element |
| 24 |
.tooltip() |
| 25 |
.tooltip( "open", $.Event( "mouseover", { target: element[ 0 ] } ) ) |
| 26 |
.tooltip( "destroy" ); |
| 27 |
} ); |
| 28 |
assert.equal( $( ".ui-tooltip" ).length, 0 ); |
| 29 |
} ); |
| 30 |
|
| 31 |
QUnit.test( "open/close", function( assert ) { |
| 32 |
assert.expect( 3 ); |
| 33 |
$.fx.off = true; |
| 34 |
var tooltip, |
| 35 |
element = $( "#tooltipped1" ).tooltip(); |
| 36 |
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); |
| 37 |
|
| 38 |
element.tooltip( "open" ); |
| 39 |
tooltip = $( "#" + element.data( "ui-tooltip-id" ) ); |
| 40 |
assert.ok( tooltip.is( ":visible" ) ); |
| 41 |
|
| 42 |
element.tooltip( "close" ); |
| 43 |
assert.ok( tooltip.is( ":hidden" ) ); |
| 44 |
$.fx.off = false; |
| 45 |
} ); |
| 46 |
|
| 47 |
|
| 48 |
QUnit.test( "open/close with tracking", function( assert ) { |
| 49 |
assert.expect( 3 ); |
| 50 |
$.fx.off = true; |
| 51 |
var tooltip, |
| 52 |
element = $( "#tooltipped1" ).tooltip( { track: true } ); |
| 53 |
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); |
| 54 |
|
| 55 |
element.tooltip( "open" ); |
| 56 |
tooltip = $( "#" + element.data( "ui-tooltip-id" ) ); |
| 57 |
assert.ok( tooltip.is( ":visible" ) ); |
| 58 |
|
| 59 |
element.tooltip( "close" ); |
| 60 |
assert.ok( tooltip.is( ":hidden" ) ); |
| 61 |
$.fx.off = false; |
| 62 |
} ); |
| 63 |
|
| 64 |
QUnit.test( "enable/disable", function( assert ) { |
| 65 |
assert.expect( 11 ); |
| 66 |
$.fx.off = true; |
| 67 |
var tooltip, |
| 68 |
element = $( "#tooltipped1" ).tooltip(); |
| 69 |
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); |
| 70 |
|
| 71 |
element.tooltip( "open" ); |
| 72 |
tooltip = $( "#" + element.data( "ui-tooltip-id" ) ); |
| 73 |
assert.ok( tooltip.is( ":visible" ) ); |
| 74 |
|
| 75 |
element.tooltip( "disable" ); |
| 76 |
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip when disabled" ); |
| 77 |
|
| 78 |
assert.lacksClasses( element.tooltip( "widget" ), "ui-state-disabled" ); |
| 79 |
assert.ok( !element.tooltip( "widget" ).attr( "aria-disabled" ), "element doesn't get aria-disabled" ); |
| 80 |
assert.lacksClasses( element.tooltip( "widget" ), "ui-tooltip-disabled" ); |
| 81 |
assert.equal( tooltip.attr( "title" ), null, "title removed on disable" ); |
| 82 |
|
| 83 |
element.tooltip( "open" ); |
| 84 |
assert.equal( $( ".ui-tooltip" ).length, 0, "open does nothing when disabled" ); |
| 85 |
|
| 86 |
element.tooltip( "enable" ); |
| 87 |
assert.equal( element.attr( "title" ), "anchortitle", "title restored on enable" ); |
| 88 |
|
| 89 |
|
| 90 |
element.tooltip( "disable" ); |
| 91 |
element.tooltip( "disable" ); |
| 92 |
element.tooltip( "enable" ); |
| 93 |
assert.equal( element.attr( "title" ), "anchortitle", "title restored on enable after being disabled twice" ); |
| 94 |
|
| 95 |
element.tooltip( "open" ); |
| 96 |
tooltip = $( "#" + element.data( "ui-tooltip-id" ) ); |
| 97 |
assert.ok( tooltip.is( ":visible" ) ); |
| 98 |
$.fx.off = false; |
| 99 |
|
| 100 |
element.tooltip( "destroy" ); |
| 101 |
} ); |
| 102 |
|
| 103 |
QUnit.test( "enable/disable delegated", function( assert ) { |
| 104 |
assert.expect( 1 ); |
| 105 |
var element = $( "#qunit-fixture" ).tooltip(); |
| 106 |
var tooltipped = $( "#tooltipped1" ); |
| 107 |
|
| 108 |
element.tooltip( "disable" ); |
| 109 |
element.tooltip( "enable" ); |
| 110 |
|
| 111 |
tooltipped.trigger( "mouseover" ); |
| 112 |
assert.equal( $( ".ui-tooltip" ).length, 1, "open" ); |
| 113 |
|
| 114 |
element.tooltip( "destroy" ); |
| 115 |
} ); |
| 116 |
|
| 117 |
QUnit.test( "widget", function( assert ) { |
| 118 |
assert.expect( 2 ); |
| 119 |
var element = $( "#tooltipped1" ).tooltip(), |
| 120 |
widgetElement = element.tooltip( "widget" ); |
| 121 |
assert.equal( widgetElement.length, 1, "one element" ); |
| 122 |
assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" ); |
| 123 |
|
| 124 |
element.tooltip( "destroy" ); |
| 125 |
} ); |
| 126 |
|
| 127 |
QUnit.test( "preserve changes to title attributes on close and destroy", function( assert ) { |
| 128 |
assert.expect( 6 ); |
| 129 |
var element = $( "#tooltipped1" ), |
| 130 |
changed = "changed title text", |
| 131 |
original = "original title text", |
| 132 |
tests = []; |
| 133 |
|
| 134 |
|
| 135 |
tests[ 0 ] = { title: changed, expected: changed, method: "close" }; |
| 136 |
|
| 137 |
|
| 138 |
tests[ 1 ] = { title: changed, expected: changed, method: "destroy" }; |
| 139 |
|
| 140 |
|
| 141 |
tests[ 2 ] = { title: "", expected: original, method: "close" }; |
| 142 |
|
| 143 |
|
| 144 |
tests[ 3 ] = { title: "", expected: original, method: "destroy" }; |
| 145 |
|
| 146 |
|
| 147 |
tests[ 4 ] = { expected: original, method: "close" }; |
| 148 |
|
| 149 |
|
| 150 |
tests[ 5 ] = { expected: original, method: "destroy" }; |
| 151 |
|
| 152 |
$.each( tests, function( index, test ) { |
| 153 |
|
| 154 |
element.attr( "title", original ).tooltip() |
| 155 |
.tooltip( "open", $.Event( "mouseover", { target: element[ 0 ] } ) ); |
| 156 |
if ( test.title ) { |
| 157 |
element.attr( "title", test.title ); |
| 158 |
} else { |
| 159 |
element.removeAttr( "title" ); |
| 160 |
} |
| 161 |
element.tooltip( test.method ); |
| 162 |
assert.equal( $( "#tooltipped1" ).attr( "title" ), test.expected ); |
| 163 |
|
| 164 |
} ); |
| 165 |
} ); |
| 166 |
|
| 167 |
} ); |