Skip to content

Commit 11d0627

Browse files
committed
Tests: Add simple tests for Android 2.3
Fixes gh-2505 Refs gh-2483
1 parent 669cb16 commit 11d0627

File tree

4 files changed

+291
-4
lines changed

4 files changed

+291
-4
lines changed

Gruntfile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ module.exports = function( grunt ) {
114114
},
115115
testswarm: {
116116
tests: [
117+
// A special module with basic tests, meant for
118+
// not fully supported environments like Android 2.3,
119+
// jsdom or PhantomJS. We run it everywhere, though,
120+
// to make sure tests are not broken.
121+
"basic",
122+
117123
"ajax",
118124
"animation",
119125
"attributes",

build/tasks/testswarm.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = function( grunt ) {
33
"use strict";
44

55
grunt.registerTask( "testswarm", function( commit, configFile, projectName, browserSets,
6-
timeout ) {
6+
timeout, testMode ) {
77
var jobName, config, tests,
88
testswarm = require( "testswarm" ),
99
runs = {},
@@ -28,9 +28,13 @@ module.exports = function( grunt ) {
2828
commit + "'>" + commit.substr( 0, 10 ) + "</a>";
2929
}
3030

31-
tests.forEach(function( test ) {
32-
runs[ test ] = config.testUrl + commit + "/test/index.html?module=" + test;
33-
});
31+
if ( testMode === "basic" ) {
32+
runs.basic = config.testUrl + commit + "/test/index.html?module=basic";
33+
} else {
34+
tests.forEach( function( test ) {
35+
runs[ test ] = config.testUrl + commit + "/test/index.html?module=" + test;
36+
} );
37+
}
3438

3539
testswarm.createClient({
3640
url: config.swarmUrl

test/data/testinit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ this.loadTests = function() {
268268
// Get testSubproject from testrunner first
269269
require([ "data/testrunner.js" ], function() {
270270
var tests = [
271+
// A special module with basic tests, meant for
272+
// not fully supported environments like Android 2.3,
273+
// jsdom or PhantomJS. We run it everywhere, though,
274+
// to make sure tests are not broken.
275+
"unit/basic.js",
276+
271277
"unit/core.js",
272278
"unit/callbacks.js",
273279
"unit/deferred.js",

test/unit/basic.js

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
module( "basic", {
2+
teardown: moduleTeardown
3+
} );
4+
5+
if ( jQuery.ajax ) {
6+
test( "ajax", function( assert ) {
7+
expect( 4 );
8+
9+
var requestsLeft = 3;
10+
11+
stop();
12+
13+
jQuery.ajax({
14+
type: "GET",
15+
url: url( "data/name.php?name=foo" ),
16+
success: function( msg ) {
17+
assert.strictEqual( msg, "bar", "Check for GET" );
18+
requestsLeft--;
19+
if ( !requestsLeft ) {
20+
start();
21+
}
22+
}
23+
});
24+
25+
jQuery.ajax({
26+
type: "POST",
27+
url: url( "data/name.php" ),
28+
data: "name=peter",
29+
success: function( msg ) {
30+
strictEqual( msg, "pan", "Check for POST" );
31+
requestsLeft--;
32+
if ( !requestsLeft ) {
33+
start();
34+
}
35+
}
36+
});
37+
38+
jQuery( "#first" ).load( url( "data/name.html" ), function() {
39+
assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ),
40+
"Check if content was injected into the DOM" );
41+
requestsLeft--;
42+
if ( !requestsLeft ) {
43+
start();
44+
}
45+
});
46+
} );
47+
}
48+
49+
test( "attributes", function ( assert ) {
50+
expect( 6 );
51+
52+
var a = jQuery( "<a/>" ).appendTo( "#qunit-fixture" ),
53+
input = jQuery( "<input/>" ).appendTo( "#qunit-fixture" );
54+
55+
assert.strictEqual( a.attr( "foo", "bar" ).attr( "foo" ), "bar", ".attr getter/setter" );
56+
assert.strictEqual( a.removeAttr( "foo" ).attr( "foo" ), undefined, ".removeAttr" );
57+
assert.strictEqual( a.prop( "href", "#5" ).prop( "href" ),
58+
location.href.replace( /\#.*$/, "" ) + "#5",
59+
".prop getter/setter" );
60+
61+
a.addClass( "abc def ghj" ).removeClass( "def ghj" );
62+
assert.strictEqual( a.hasClass( "abc" ), true, ".(add|remove|has)Class, class present" );
63+
assert.strictEqual( a.hasClass( "def" ), false, ".(add|remove|has)Class, class missing" );
64+
65+
assert.strictEqual( input.val( "xyz" ).val(), "xyz", ".val getter/setter" );
66+
} );
67+
68+
if ( jQuery.css ) {
69+
test( "css", function( assert ) {
70+
expect( 3 );
71+
72+
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
73+
74+
assert.strictEqual( div.css( "width", "50px" ).css( "width" ), "50px", ".css getter/setter" );
75+
76+
div.hide();
77+
assert.strictEqual( div.css( "display" ), "none", "div hidden" );
78+
div.show();
79+
assert.strictEqual( div.css( "display" ), "block", "div shown" );
80+
} );
81+
}
82+
83+
test( "core", function ( assert ) {
84+
expect( 28 );
85+
86+
var elem = jQuery( "<div></div><span></span>" );
87+
88+
assert.strictEqual( elem.length, 2, "Correct number of elements" );
89+
assert.strictEqual( jQuery.trim(" hello "), "hello", "jQuery.trim" );
90+
91+
assert.strictEqual( jQuery.type( null ), "null", "jQuery.type(null)" );
92+
assert.strictEqual( jQuery.type( undefined ), "undefined", "jQuery.type(undefined)" );
93+
assert.strictEqual( jQuery.type("a"), "string", "jQuery.type(String)" );
94+
95+
assert.ok( jQuery.isPlainObject({ "a": 2 }), "jQuery.isPlainObject(object)" );
96+
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
97+
98+
assert.ok( jQuery.isFunction( jQuery.noop ), "jQuery.isFunction(jQuery.noop)" );
99+
assert.ok( !jQuery.isFunction( 2 ), "jQuery.isFunction(Number)" );
100+
101+
assert.ok( jQuery.isNumeric( "-2" ), "jQuery.isNumeric(String representing a number)" );
102+
assert.ok( !jQuery.isNumeric( "" ), "jQuery.isNumeric(\"\")" );
103+
104+
assert.ok( jQuery.isXMLDoc( jQuery.parseXML(
105+
"<?xml version='1.0' encoding='UTF-8'?><foo bar='baz'></foo>"
106+
) ), "jQuery.isXMLDoc" );
107+
108+
109+
assert.ok( jQuery.isWindow( window ), "jQuery.isWindow(window)" );
110+
assert.ok( !jQuery.isWindow( 2 ), "jQuery.isWindow(Number)" );
111+
112+
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, 3, {} ] ), 3, "jQuery.inArray - true" );
113+
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, "3", {} ] ), -1, "jQuery.inArray - false" );
114+
115+
assert.strictEqual( elem.get( 1 ), elem[ 1 ], ".get" );
116+
assert.strictEqual( elem.first()[ 0 ], elem.get( 0 ), ".first" );
117+
assert.strictEqual( elem.last()[ 0 ], elem.get( 1 ), ".last" );
118+
119+
assert.deepEqual( jQuery.map( [ "a", "b", "c" ], function ( v, k ) {
120+
return k + v;
121+
} ), ["0a", "1b", "2c" ], "jQuery.map" );
122+
123+
assert.deepEqual( jQuery.merge( [ 1, 2 ], [ "a", "b" ] ), [ 1, 2, "a", "b" ], "jQuery.merge" );
124+
125+
assert.deepEqual( jQuery.grep( [ 1, 2, 3 ], function( value ) {
126+
return value % 2 !== 0;
127+
} ), [ 1, 3 ], "jQuery.grep" );
128+
129+
assert.deepEqual( jQuery.extend( { a: 2 }, { b: 3 } ), { a: 2, b: 3 }, "jQuery.extend" );
130+
131+
jQuery.each( [ 0, 2 ], function ( k, v ) {
132+
assert.strictEqual( k * 2, v, "jQuery.each" );
133+
} );
134+
135+
assert.deepEqual( jQuery.makeArray( { 0: "a", 1: "b", 2: "c", length: 3 } ),
136+
[ "a", "b", "c" ], "jQuery.makeArray" );
137+
138+
assert.strictEqual( jQuery.parseHTML( "<div></div><span></span>" ).length,
139+
2, "jQuery.parseHTML" );
140+
141+
assert.deepEqual( jQuery.parseJSON( "{\"a\": 2}" ), { a: 2 }, "jQuery.parseJON" );
142+
} );
143+
144+
test( "data", function ( assert ) {
145+
expect( 4 );
146+
147+
var elem = jQuery( "<div data-c='d'/>" ).appendTo( "#qunit-fixture" );
148+
149+
assert.ok( !jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - false" );
150+
assert.strictEqual( elem.data( "a", "b" ).data( "a" ), "b", ".data getter/setter" );
151+
assert.strictEqual( elem.data( "c" ), "d", ".data from data-* attributes" );
152+
assert.ok( jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - true" );
153+
} );
154+
155+
test( "dimensions", function ( assert ) {
156+
expect( 3 );
157+
158+
var elem = jQuery(
159+
"<div style='margin: 10px; padding: 7px; border: 2px solid black;' /> "
160+
).appendTo( "#qunit-fixture");
161+
162+
assert.strictEqual( elem.width( 50 ).width(), 50, ".width getter/setter" );
163+
assert.strictEqual( elem.innerWidth(), 64, ".innerWidth getter" );
164+
assert.strictEqual( elem.outerWidth(), 68, ".outerWidth getter" );
165+
} );
166+
167+
test( "event", function ( assert ) {
168+
expect( 1 );
169+
170+
var elem = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
171+
172+
elem
173+
.on( "click" , function() {
174+
assert.ok( false, "click should not fire" );
175+
} )
176+
.off( "click" )
177+
.trigger( "click" )
178+
.on( "click" , function() {
179+
assert.ok( true, "click should fire" );
180+
} )
181+
.trigger( "click" );
182+
} );
183+
184+
test( "manipulation", function ( assert ) {
185+
expect( 5 );
186+
187+
var child,
188+
elem1 = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" ),
189+
elem2 = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
190+
191+
assert.strictEqual( elem1.text( "foo" ).text(), "foo", ".html getter/setter" );
192+
assert.strictEqual( elem1.html( "<span/>" ).html(), "<span></span>", ".html getter/setter" );
193+
194+
assert.strictEqual( elem1.append( elem2 )[ 0 ].childNodes[ 1 ], elem2[ 0 ], ".append" );
195+
assert.strictEqual( elem1.prepend( elem2 )[ 0 ].childNodes[ 0 ], elem2[ 0 ], ".prepend" );
196+
197+
child = elem1.find( "span" );
198+
child.after( "<a/>" );
199+
child.before( "<b/>" );
200+
assert.strictEqual( elem1.html(), "<div></div><b></b><span></span><a></a>", ".after/.before" );
201+
} );
202+
203+
test( "offset", function ( assert ) {
204+
expect( 3 );
205+
206+
var parent = jQuery( "<div style='position:fixed;top:20px;'/>" ).appendTo( "#qunit-fixture" ),
207+
elem = jQuery( "<div style='position:absolute;top:5px;'/>" ).appendTo( parent );
208+
209+
assert.strictEqual( elem.offset().top, 25, ".offset getter" );
210+
assert.strictEqual( elem.position().top, 5, ".position getter" );
211+
assert.strictEqual( elem.offsetParent()[ 0 ], parent[ 0 ], ".offsetParent" );
212+
} );
213+
214+
test( "selector", function ( assert ) {
215+
expect( 2 );
216+
217+
var elem = jQuery( "<div><span class='a'></span><span class='b'><a></a></span></div>" )
218+
.appendTo( "#qunit-fixture" );
219+
220+
assert.strictEqual( elem.find( ".a a" ).length, 0, ".find - no result" );
221+
assert.strictEqual( elem.find( "span.b a" )[ 0 ].nodeName, "A", ".find - one result" );
222+
} );
223+
224+
test( "serialize", function ( assert ) {
225+
expect( 2 );
226+
227+
var params = {"someName": [ 1, 2, 3 ], "regularThing": "blah" };
228+
assert.strictEqual( jQuery.param( params ),
229+
"someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah",
230+
"jQuery.param" );
231+
232+
assert.strictEqual( jQuery("#form").serialize(),
233+
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2&select5=3",
234+
"form serialization as query string" );
235+
} );
236+
237+
test( "traversing", function ( assert ) {
238+
expect( 12 );
239+
240+
var elem = jQuery( "<div><a><b><em></em></b></a><i></i><span></span>foo</div>" )
241+
.appendTo( "#qunit-fixture" );
242+
243+
assert.strictEqual( elem.find( "em" ).parent()[ 0 ].nodeName, "B", ".parent" );
244+
assert.strictEqual( elem.find( "em" ).parents()[ 1 ].nodeName, "A", ".parents" );
245+
assert.strictEqual( elem.find( "em" ).parentsUntil( "div" ).length, 2, ".parentsUntil" );
246+
assert.strictEqual( elem.find( "i" ).next()[ 0 ].nodeName, "SPAN", ".next" );
247+
assert.strictEqual( elem.find( "i" ).prev()[ 0 ].nodeName, "A", ".prev" );
248+
assert.strictEqual( elem.find( "a" ).nextAll()[ 1 ].nodeName, "SPAN", ".nextAll" );
249+
assert.strictEqual( elem.find( "span" ).prevAll()[ 1 ].nodeName, "A", ".prevAll" );
250+
assert.strictEqual( elem.find( "a" ).nextUntil( "span" ).length, 1, ".nextUntil" );
251+
assert.strictEqual( elem.find( "span" ).prevUntil( "a" ).length, 1, ".prevUntil" );
252+
assert.strictEqual( elem.find( "i" ).siblings().length, 2, ".siblings" );
253+
assert.strictEqual( elem.children()[ 2 ].nodeName, "SPAN", ".children" );
254+
assert.strictEqual( elem.contents()[ 3 ].nodeType, 3, ".contents" );
255+
} );
256+
257+
test( "wrap", function ( assert ) {
258+
expect( 3 );
259+
260+
var elem = jQuery( "<div><a><b></b></a><a></a></div>" );
261+
262+
elem.find( "b" ).wrap( "<span>" );
263+
assert.strictEqual( elem.html(), "<a><span><b></b></span></a><a></a>", ".wrap" );
264+
elem.find( "span" ).wrapInner( "<em>" );
265+
assert.strictEqual( elem.html(), "<a><span><em><b></b></em></span></a><a></a>", ".wrapInner" );
266+
elem.find( "a" ).wrapAll( "<i>" );
267+
assert.strictEqual( elem.html(), "<i><a><span><em><b></b></em></span></a><a></a></i>", ".wrapAll" );
268+
269+
} );
270+
271+
// TODO write tests for traversing & wrap.

0 commit comments

Comments
 (0)