summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/jquery/jquery.tabIndex.js
blob: 1ff81e58e5acaa18d4141e58451cb1d9ec6f2e17 (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
module( 'jquery.tabIndex.js' );

test( '-- Initial check', function() {
	expect(2);

	ok( $.fn.firstTabIndex, '$.fn.firstTabIndex defined' );
	ok( $.fn.lastTabIndex, '$.fn.lastTabIndex defined' );
});

test( 'firstTabIndex', function() {
	expect(2);

	var testEnvironment =
'<form>' +
	'<input tabindex="7" />' +
	'<input tabindex="9" />' +
	'<textarea tabindex="2">Foobar</textarea>' +
	'<textarea tabindex="5">Foobar</textarea>' +
'</form>';

	var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
	strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );

	var $testB = $( '<div>' );
	strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );

	// Clean up
	$testA.add( $testB ).remove();
});

test( 'lastTabIndex', function() {
	expect(2);

	var testEnvironment =
'<form>' +
	'<input tabindex="7" />' +
	'<input tabindex="9" />' +
	'<textarea tabindex="2">Foobar</textarea>' +
	'<textarea tabindex="5">Foobar</textarea>' +
'</form>';

	var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
	strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );

	var $testB = $( '<div>' );
	strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );

	// Clean up
	$testA.add( $testB ).remove();
});