Debian Codegraph @

tests/unit/checkboxradio/methods.js

raw symbols SCIP
1 define( [
2 "qunit",
3 "jquery",
4 "lib/helper",
5 "ui/widgets/checkboxradio"
6 ], function( QUnit, $, helper ) {
7 "use strict";
8
9 QUnit.module( "Checkboxradio: methods", { afterEach: helper.moduleAfterEach } );
10
11 $.each( [ "checkbox", "radio" ], function( index, value ) {
12 QUnit.test( value + ": refresh", function( assert ) {
13 var widget, icon,
14 checkbox = value === "checkbox",
15 input = $( "#" + value + "-method-refresh" );
16
17 assert.expect( checkbox ? 11 : 8 );
18
19 input.checkboxradio();
20
21 widget = input.checkboxradio( "widget" );
22 icon = widget.find( ".ui-icon" );
23 assert.strictEqual( icon.length, 1,
24 "There is initally one icon" );
25
26 icon.remove();
27 input.checkboxradio( "refresh" );
28 icon = widget.find( ".ui-icon" );
29 assert.strictEqual( icon.length, 1,
30 "Icon is recreated on refresh if absent" );
31 assert.hasClasses( icon, "ui-icon-blank" );
32 if ( checkbox ) {
33 assert.lacksClasses( icon, "ui-icon-check" );
34 }
35 assert.lacksClasses( widget, "ui-checkboxradio-checked" );
36
37 input.prop( "checked", true );
38 input.checkboxradio( "refresh" );
39 if ( checkbox ) {
40 assert.hasClasses( icon, "ui-icon-check" );
41 }
42 assert[ !checkbox ? "hasClasses" : "lacksClasses" ]( icon, "ui-icon-blank" );
43 assert.hasClasses( widget, "ui-checkboxradio-checked" );
44
45 input.prop( "checked", false );
46 input.checkboxradio( "refresh" );
47 assert.hasClasses( icon, "ui-icon-blank" );
48 if ( checkbox ) {
49 assert.lacksClasses( icon, "ui-icon-check" );
50 }
51 assert.lacksClasses( widget, "ui-checkboxradio-checked" );
52 } );
53
54 QUnit.test( value + ": destroy", function( assert ) {
55 assert.expect( 1 );
56 assert.domEqual( "#" + value + "-method-destroy", function() {
57 $( "#" + value + "-method-destroy" ).checkboxradio().checkboxradio( "destroy" );
58 } );
59 } );
60
61 QUnit.test( value + ": disable / enable", function( assert ) {
62 assert.expect( 4 );
63 var input = $( "#" + value + "-method-disable" ),
64 widget = input.checkboxradio().checkboxradio( "widget" );
65
66 input.checkboxradio( "disable" );
67 assert.hasClasses( widget, "ui-state-disabled" );
68 assert.strictEqual( input.is( ":disabled" ), true,
69 value + " is disabled when disable is called" );
70
71 input.checkboxradio( "enable" );
72 assert.lacksClasses( widget, "ui-state-disabled" );
73 assert.strictEqual( input.is( ":disabled" ), false,
74 value + " has disabled prop removed when enable is called" );
75 } );
76
77 QUnit.test( value + ": widget returns the label", function( assert ) {
78 assert.expect( 1 );
79
80 var input = $( "#" + value + "-method-refresh" ),
81 label = $( "#" + value + "-method-refresh-label" );
82
83 input.checkboxradio();
84 assert.strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
85 "widget method returns label" );
86 } );
87 } );
88
89 QUnit.test( "Input wrapped in a label preserved on refresh", function( assert ) {
90 var input = $( "#label-with-no-for" ).checkboxradio(),
91 element = input.checkboxradio( "widget" );
92
93 assert.expect( 1 );
94
95 input.checkboxradio( "refresh" );
96 assert.strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" );
97 } );
98
99 QUnit.test( "Initial text label not turned to HTML on refresh", function( assert ) {
100 var tests = [
101 {
102 id: "label-with-no-for-with-html",
103 expectedLabel: "<strong>Hi</strong>, <em>I'm a label</em>"
104 },
105 {
106 id: "label-with-no-for-with-text",
107 expectedLabel: "Hi, I'm a label"
108 },
109 {
110 id: "label-with-no-for-with-html-like-text",
111 expectedLabel: "&lt;em&gt;Hi, I'm a label&lt;/em&gt;"
112 }
113 ];
114
115 assert.expect( tests.length );
116
117 tests.forEach( function( testData ) {
118 var id = testData.id;
119 var expectedLabel = testData.expectedLabel;
120 var inputElem = $( "#" + id );
121 var labelElem = inputElem.parent();
122
123 inputElem.checkboxradio( { icon: false } );
124 inputElem.checkboxradio( "refresh" );
125
126 var labelWithoutInput = labelElem.clone();
127 labelWithoutInput.find( "input" ).remove();
128
129 assert.strictEqual(
130 labelWithoutInput.html().trim(),
131 expectedLabel.trim(),
132 "Label correct [" + id + "]"
133 );
134 } );
135 } );
136
137 } );