Skip to content

Commit bb47aad

Browse files
committed
Tests: Replace resource loader with AMD
1 parent e3e5a9f commit bb47aad

14 files changed

+3297
-1161
lines changed

external/require.js

Lines changed: 2054 additions & 0 deletions
Large diffs are not rendered by default.

tests/jquery.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/unit/accordion/accordion.html

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,12 @@
44
<meta charset="utf-8">
55
<title>jQuery UI Accordion Test Suite</title>
66

7-
<script src="../../jquery.js"></script>
8-
<link rel="stylesheet" href="../../../external/qunit/qunit.css">
9-
<script src="../../../external/qunit/qunit.js"></script>
10-
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
11-
<script src="../testsuite.js"></script>
7+
<script src="../helper/css.js"></script>
128
<script>
13-
TestHelpers.loadResources({
14-
css: [ "core", "accordion" ],
15-
js: [
16-
"ui/core.js",
17-
"ui/widget.js",
18-
"ui/accordion.js"
19-
]
20-
});
9+
window.helper.loadCss([ "core", "accordion" ]);
2110
</script>
2211

23-
<script src="accordion_test_helpers.js"></script>
24-
<script src="accordion_common.js"></script>
25-
<script src="accordion_core.js"></script>
26-
<script src="accordion_events.js"></script>
27-
<script src="accordion_methods.js"></script>
28-
<script src="accordion_options.js"></script>
29-
30-
<script src="../swarminject.js"></script>
12+
<link rel="stylesheet" href="../../../external/qunit/qunit.css">
3113
<style>
3214
#list, #list1 *, #navigation, #navigation * {
3315
margin: 0;
@@ -134,6 +116,29 @@ <h2><a href="?p=1.1.3">Drums</a></h2>
134116
</dd>
135117
</dl>
136118

119+
<script src="../../../external/requirejs/require.js"></script>
120+
<script src="../../../external/qunit/qunit.js"></script>
121+
<script src="../swarminject.js"></script>
122+
<script src="../helper/jquery.js"></script>
123+
<script>
124+
QUnit.config.autostart = false;
125+
require.config({
126+
paths: {
127+
"helper": "../helper",
128+
"jquery": window.helper.jqueryUrl(),
129+
"jquery.simulate": "../../../external/jquery-simulate/jquery.simulate",
130+
"jshint": "../../../external/jshint/jshint",
131+
"ui": "../../../ui"
132+
},
133+
shim: {
134+
"jquery.simulate": [ "jquery" ]
135+
}
136+
});
137+
require([ "./accordion" ], function() {
138+
QUnit.start();
139+
});
140+
</script>
141+
137142
</div>
138143
</body>
139144
</html>

tests/unit/accordion/accordion.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
define([
2+
"./accordion_common",
3+
"./accordion_core",
4+
"./accordion_events" ,
5+
"./accordion_methods",
6+
"./accordion_options"
7+
], function( common, core, events, methods, options ) {
8+
9+
common();
10+
core();
11+
events();
12+
methods();
13+
options();
14+
15+
});
Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
TestHelpers.commonWidgetTests( "accordion", {
2-
defaults: {
3-
active: 0,
4-
animate: {},
5-
collapsible: false,
6-
disabled: false,
7-
event: "click",
8-
header: "> li > :first-child,> :not(li):even",
9-
heightStyle: "auto",
10-
icons: {
11-
"activeHeader": "ui-icon-triangle-1-s",
12-
"header": "ui-icon-triangle-1-e"
13-
},
1+
define([
2+
"helper/testsuite",
3+
"ui/accordion"
4+
], function( testHelper ) {
5+
6+
return function() {
7+
8+
testHelper.commonWidgetTests( "accordion", {
9+
defaults: {
10+
active: 0,
11+
animate: {},
12+
collapsible: false,
13+
disabled: false,
14+
event: "click",
15+
header: "> li > :first-child,> :not(li):even",
16+
heightStyle: "auto",
17+
icons: {
18+
"activeHeader": "ui-icon-triangle-1-s",
19+
"header": "ui-icon-triangle-1-e"
20+
},
21+
22+
// callbacks
23+
activate: null,
24+
beforeActivate: null,
25+
create: null
26+
}
27+
});
28+
29+
};
1430

15-
// callbacks
16-
activate: null,
17-
beforeActivate: null,
18-
create: null
19-
}
2031
});
Lines changed: 118 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,126 @@
1-
(function( $ ) {
2-
3-
var setupTeardown = TestHelpers.accordion.setupTeardown,
4-
state = TestHelpers.accordion.state;
5-
6-
module( "accordion: core", setupTeardown() );
7-
8-
$.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( type, selector ) {
9-
test( "markup structure: " + type, function() {
10-
expect( 4 );
11-
var element = $( selector ).accordion();
12-
ok( element.hasClass( "ui-accordion" ), "main element is .ui-accordion" );
13-
equal( element.find( ".ui-accordion-header" ).length, 3,
14-
".ui-accordion-header elements exist, correct number" );
15-
equal( element.find( ".ui-accordion-content" ).length, 3,
16-
".ui-accordion-content elements exist, correct number" );
17-
deepEqual( element.find( ".ui-accordion-header" ).next().get(),
18-
element.find( ".ui-accordion-content" ).get(),
19-
"content panels come immediately after headers" );
20-
});
21-
});
1+
define([
2+
"jquery",
3+
"./accordion_test_helpers",
4+
"ui/accordion",
5+
"jquery.simulate"
6+
], function( $, accordionTestHelper ) {
227

23-
test( "handle click on header-descendant", function() {
24-
expect( 1 );
25-
var element = $( "#navigation" ).accordion();
26-
$( "#navigation h2:eq(1) a" ).click();
27-
state( element, 0, 1, 0 );
28-
});
8+
return function() {
9+
10+
var setupTeardown = accordionTestHelper.setupTeardown,
11+
state = accordionTestHelper.state;
12+
13+
module( "accordion: core", setupTeardown() );
2914

30-
test( "accessibility", function () {
31-
expect( 37 );
32-
var element = $( "#list1" ).accordion({
33-
active: 1
34-
}),
35-
headers = element.find( ".ui-accordion-header" );
36-
37-
equal( element.attr( "role" ), "tablist", "element role" );
38-
headers.each(function( i ) {
39-
var header = headers.eq( i ),
40-
panel = header.next();
41-
equal( header.attr( "role" ), "tab", "header " + i + " role" );
42-
equal( header.attr( "aria-controls" ), panel.attr( "id" ), "header " + i + " aria-controls" );
43-
equal( panel.attr( "role" ), "tabpanel", "panel " + i + " role" );
44-
equal( panel.attr( "aria-labelledby" ), header.attr( "id" ), "panel " + i + " aria-labelledby" );
15+
$.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( type, selector ) {
16+
test( "markup structure: " + type, function() {
17+
expect( 4 );
18+
var element = $( selector ).accordion();
19+
ok( element.hasClass( "ui-accordion" ), "main element is .ui-accordion" );
20+
equal( element.find( ".ui-accordion-header" ).length, 3,
21+
".ui-accordion-header elements exist, correct number" );
22+
equal( element.find( ".ui-accordion-content" ).length, 3,
23+
".ui-accordion-content elements exist, correct number" );
24+
deepEqual( element.find( ".ui-accordion-header" ).next().get(),
25+
element.find( ".ui-accordion-content" ).get(),
26+
"content panels come immediately after headers" );
27+
});
4528
});
4629

47-
equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
48-
equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
49-
equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
50-
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel has aria-hidden=false" );
51-
equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
52-
equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
53-
equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
54-
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
55-
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
56-
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
57-
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
58-
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
59-
60-
element.accordion( "option", "active", 0 );
61-
equal( headers.eq( 0 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
62-
equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
63-
equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
64-
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "false", "active tabpanel has aria-hidden=false" );
65-
equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
66-
equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
67-
equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
68-
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
69-
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
70-
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
71-
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
72-
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
73-
});
30+
test( "handle click on header-descendant", function() {
31+
expect( 1 );
32+
var element = $( "#navigation" ).accordion();
33+
$( "#navigation h2:eq(1) a" ).click();
34+
state( element, 0, 1, 0 );
35+
});
36+
37+
test( "accessibility", function () {
38+
expect( 37 );
39+
var element = $( "#list1" ).accordion({
40+
active: 1
41+
}),
42+
headers = element.find( ".ui-accordion-header" );
43+
44+
equal( element.attr( "role" ), "tablist", "element role" );
45+
headers.each(function( i ) {
46+
var header = headers.eq( i ),
47+
panel = header.next();
48+
equal( header.attr( "role" ), "tab", "header " + i + " role" );
49+
equal( header.attr( "aria-controls" ), panel.attr( "id" ), "header " + i + " aria-controls" );
50+
equal( panel.attr( "role" ), "tabpanel", "panel " + i + " role" );
51+
equal( panel.attr( "aria-labelledby" ), header.attr( "id" ), "panel " + i + " aria-labelledby" );
52+
});
53+
54+
equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
55+
equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
56+
equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
57+
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel has aria-hidden=false" );
58+
equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
59+
equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
60+
equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
61+
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
62+
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
63+
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
64+
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
65+
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
7466

75-
asyncTest( "keyboard support", function() {
76-
expect( 13 );
77-
var element = $( "#list1" ).accordion(),
78-
headers = element.find( ".ui-accordion-header" ),
79-
anchor = headers.eq( 1 ).next().find( "a" ).eq( 0 ),
80-
keyCode = $.ui.keyCode;
81-
equal( headers.filter( ".ui-state-focus" ).length, 0, "no headers focused on init" );
82-
headers.eq( 0 ).simulate( "focus" );
83-
setTimeout(function() {
84-
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "first header has focus" );
85-
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
86-
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "DOWN moves focus to next header" );
87-
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } );
88-
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "RIGHT moves focus to next header" );
89-
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
90-
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "DOWN wraps focus to first header" );
91-
92-
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } );
93-
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "UP wraps focus to last header" );
94-
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } );
95-
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "LEFT moves focus to previous header" );
96-
97-
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } );
98-
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "HOME moves focus to first header" );
99-
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } );
100-
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "END moves focus to last header" );
101-
102-
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
103-
equal( element.accordion( "option", "active" ) , 2, "ENTER activates panel" );
104-
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
105-
equal( element.accordion( "option", "active" ), 1, "SPACE activates panel" );
106-
107-
anchor.simulate( "focus" );
67+
element.accordion( "option", "active", 0 );
68+
equal( headers.eq( 0 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
69+
equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
70+
equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
71+
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "false", "active tabpanel has aria-hidden=false" );
72+
equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
73+
equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
74+
equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
75+
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
76+
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
77+
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
78+
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
79+
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
80+
});
81+
82+
asyncTest( "keyboard support", function() {
83+
expect( 13 );
84+
var element = $( "#list1" ).accordion(),
85+
headers = element.find( ".ui-accordion-header" ),
86+
anchor = headers.eq( 1 ).next().find( "a" ).eq( 0 ),
87+
keyCode = $.ui.keyCode;
88+
equal( headers.filter( ".ui-state-focus" ).length, 0, "no headers focused on init" );
89+
headers.eq( 0 ).simulate( "focus" );
10890
setTimeout(function() {
109-
ok( !headers.eq( 1 ).is( ".ui-state-focus" ), "header loses focus when focusing inside the panel" );
110-
anchor.simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } );
111-
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "CTRL+UP moves focus to header" );
112-
start();
91+
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "first header has focus" );
92+
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
93+
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "DOWN moves focus to next header" );
94+
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } );
95+
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "RIGHT moves focus to next header" );
96+
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
97+
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "DOWN wraps focus to first header" );
98+
99+
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } );
100+
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "UP wraps focus to last header" );
101+
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } );
102+
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "LEFT moves focus to previous header" );
103+
104+
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } );
105+
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "HOME moves focus to first header" );
106+
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } );
107+
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "END moves focus to last header" );
108+
109+
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
110+
equal( element.accordion( "option", "active" ) , 2, "ENTER activates panel" );
111+
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
112+
equal( element.accordion( "option", "active" ), 1, "SPACE activates panel" );
113+
114+
anchor.simulate( "focus" );
115+
setTimeout(function() {
116+
ok( !headers.eq( 1 ).is( ".ui-state-focus" ), "header loses focus when focusing inside the panel" );
117+
anchor.simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } );
118+
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "CTRL+UP moves focus to header" );
119+
start();
120+
}, 1 );
113121
}, 1 );
114-
}, 1 );
115-
});
122+
});
116123

117-
}( jQuery ) );
124+
};
125+
126+
});

0 commit comments

Comments
 (0)