Skip to content

Commit 4d4c765

Browse files
committed
Additional fetchlink tests.
1 parent a1e6c87 commit 4d4c765

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

tests/unit/fetchlink/ext-3.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h1>Header</h1>
2222
</div>
2323
<div data-nstest-role="content">
2424

25-
<a href="ext-4.html" class="foo" data-nstest-role="button">Quote 1</a>
25+
<a href="ext-4.html" class="remote-fetchlink" data-nstest-role="button" href="ext-1.html" data-nstest-target=".secondtarget" data-nstest-fragment=".bq">Quote 4</a>
2626

2727
<label for="slider2">Flip switch:</label>
2828
<select name="slider2" id="slider2" data-nstest-role="slider">
@@ -32,7 +32,9 @@ <h1>Header</h1>
3232

3333
<label for="test-slider">Slider:</label>
3434
<input type="range" name="test-slider" id="test-slider" value="0" min="0" max="100" />
35-
35+
<div class="secondtarget">
36+
37+
</div>
3638
</div>
3739
<div data-nstest-role="footer">
3840
<h1>Footer</h1>

tests/unit/fetchlink/ext-4.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Event Test Suite</title>
7+
</head>
8+
<body>
9+
10+
<blockquote class="bq">
11+
<p>It was easier to know it than to explain why I know it. If you were asked to prove that two and two made four, you might find some difficulty, and yet you are quite sure of the fact.</p>
12+
<address>Arthur Conan Doyle</address>
13+
<cite>Sherlock Holmes: A Study In Scarlet</cite>
14+
</blockquote>
15+
16+
</body>
17+
</html>

tests/unit/fetchlink/fetchlink_core.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
module( "Fetchlinks", {
88
setup: function(){
9-
//
9+
// $.testHelper.openPage("#fetchlink-test1");
1010
}
1111
});
1212

@@ -15,7 +15,7 @@
1515

1616
$.testHelper.pageSequence([
1717
function(){
18-
$('.foo').trigger('click');
18+
$('.standalone').trigger('click');
1919
},
2020
function(){
2121
ok( targetContents !== $( '.loadinto' ).html() );
@@ -24,7 +24,7 @@
2424
]);
2525
});
2626

27-
asyncTest( "Clicking a fetchlink replaces previously loaded content with remote content.", function(){
27+
asyncTest( "Clicking a grouped fetchlink loads remote content.", function(){
2828
var targetContents = $( '.loadinto' ).html();
2929

3030
$.testHelper.pageSequence([
@@ -38,24 +38,51 @@
3838
]);
3939
});
4040

41-
asyncTest( "Elements are properly enhanced after being fetched.", function(){
41+
asyncTest( "When no remote fragment is specified, the remote “page” element’s contents are pulled in instead.", function(){
4242
$.testHelper.pageSequence([
4343
function(){
44-
$('.baz').trigger('click');
44+
$('.remote-page').trigger('click');
4545
},
4646
function(){
47-
ok( $('[data-nstest-role="header"]').hasClass( 'ui-header' ), "Page header is enhanced." );
48-
ok( $('[data-nstest-role="content"]').hasClass( 'ui-content' ), "Page content is enhanced." );
49-
ok( $('[data-nstest-role="footer"]').hasClass( 'ui-footer' ), "Page footer is enhanced." );
50-
ok( $('[data-nstest-role="button"]').hasClass( 'ui-btn' ), "A link with a role of “button” is enhanced." );
51-
ok( $('[data-nstest-role="slider"]').hasClass( 'ui-slider-switch' ), "Toggles are enhanced." );
52-
ok( $('#test-slider').hasClass( 'ui-slider-input' ), "Slider widgets are enhanced." );
47+
var headerFirst = $('.loadinto').find('div:first').attr('data-nstest-role') === 'header',
48+
footerLast = $('.loadinto').find('div:last').attr('data-nstest-role') === 'footer';
49+
50+
ok( headerFirst && footerLast, "First and last items within the page wrapper match the first and last items in the target container." );
51+
start();
52+
}
53+
]);
54+
});
55+
56+
asyncTest( "Elements are properly enhanced after being fetched.", function(){
57+
$.testHelper.pageSequence([
58+
function(){
59+
ok( $('.loadinto').find('[data-nstest-role="header"]').hasClass( 'ui-header' ), "Page header is enhanced." );
60+
ok( $('.loadinto').find('[data-nstest-role="content"]').hasClass( 'ui-content' ), "Page content is enhanced." );
61+
ok( $('.loadinto').find('[data-nstest-role="footer"]').hasClass( 'ui-footer' ), "Page footer is enhanced." );
62+
ok( $('.loadinto').find('[data-nstest-role="button"]').hasClass( 'ui-btn' ), "A link with a role of “button” is enhanced." );
63+
ok( $('.loadinto').find('[data-nstest-role="slider"]').hasClass( 'ui-slider-switch' ), "Toggles are enhanced." );
64+
ok( $('.loadinto').find('#test-slider').hasClass( 'ui-slider-input' ), "Slider widgets are enhanced." );
5365

5466
start();
5567
}
5668
]);
5769
});
5870

71+
asyncTest( "Fetchlinks within remote content function normally.", function(){
72+
var targetContents = $( '.secondtarget' ).html();
73+
74+
$.testHelper.pageSequence([
75+
function() {
76+
$('.remote-fetchlink').trigger('click');
77+
},
78+
function(){
79+
ok( $('.loadinto').html() !== targetContents, "Target container has been updated with remote content." );
80+
start();
81+
}
82+
]);
83+
});
84+
85+
5986

6087

6188
})(jQuery);

tests/unit/fetchlink/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ <h2 id="qunit-userAgent"></h2>
3131
<div data-nstest-role="page" id="fetchlink-test1">
3232

3333
<div data-nstest-role="content">
34+
35+
<a href="ext-1.html" class="standalone" data-nstest-fragment=".bq" data-nstest-target=".loadinto">Quote 1</a>
36+
3437
<ul data-nstest-target=".loadinto" data-nstest-fragment=".bq">
35-
<li><a href="ext-1.html" class="foo">Quote 1</a></li>
3638
<li><a href="ext-2.html" class="bar">Quote 2</a></li>
3739
</ul>
3840

39-
<a href="ext-3.html" class="baz" data-nstest-target=".loadinto">External Page</a>
41+
<a href="ext-3.html" class="remote-page" data-nstest-target=".loadinto">External Page</a>
4042

4143
<div class="loadinto">
4244

0 commit comments

Comments
 (0)