Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 2278fc3

Browse files
committed
Demos: Added CasperJS functionnal tests
1 parent 8197bb0 commit 2278fc3

File tree

5 files changed

+126
-7
lines changed

5 files changed

+126
-7
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
language: node_js
2-
node_js:
3-
- 0.8
1+
language: php
2+
php:
3+
- "5.5"
44
before_script:
55
- npm install -g grunt-cli
6+
- npm install
67
script: npm run-script ci
78
branches:
89
only:

Gruntfile.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = function( grunt ) {
7070
},
7171
path = require( "path" ),
7272
httpPort = Math.floor( 9000 + Math.random()*1000 ),
73+
phpPort = Math.floor( 8000 + Math.random()*1000 ),
7374
name = "jquery.mobile",
7475
dist = "dist" + path.sep,
7576
copyrightYear = grunt.template.today( "UTC:yyyy" ),
@@ -693,6 +694,37 @@ module.exports = function( grunt ) {
693694
}
694695
},
695696

697+
php: {
698+
server: {
699+
options: {
700+
port: phpPort,
701+
baseUrl: "."
702+
}
703+
}
704+
},
705+
706+
casper: {
707+
options: {
708+
test: true,
709+
verbose : false,
710+
"log-level": "error",
711+
parallel: true,
712+
concurrency: 5
713+
},
714+
"demos.src": {
715+
options: {
716+
args: [ "--port=" + phpPort ]
717+
},
718+
src: [ "tests/casperjs/**/*.js" ]
719+
},
720+
"demos.dist": {
721+
options: {
722+
args: [ "--port=" + phpPort ]
723+
},
724+
src: [ "tests/casperjs/**/*.js" ]
725+
}
726+
},
727+
696728
connect: {
697729
server: {
698730
options: {
@@ -987,13 +1019,21 @@ module.exports = function( grunt ) {
9871019

9881020
grunt.registerTask( "updateDependencies", [ "bowercopy" ] );
9891021

1022+
grunt.registerTask( "test:demos:src", [ "php", "casper:demos.src" ] );
1023+
1024+
grunt.registerTask( "test:demos:dist", [ "casper:demos.dist" ] );
1025+
9901026
grunt.registerTask( "test",
9911027
[
9921028
"clean:testsOutput",
9931029
"jshint",
1030+
"test:demos:src",
9941031
"config:fetchHeadHash",
9951032
"js:release",
996-
"connect", "qunit:http"
1033+
"demos",
1034+
"connect",
1035+
"test:demos:dist",
1036+
"qunit:http"
9971037
]
9981038
);
9991039
grunt.registerTask( "test:ci", [ "qunit_junit", "connect", "qunit:http" ] );

demos/jqm-contents.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<li data-filtertext="form button widget input button submit reset"><a href="../button/" data-ajax="false">Button widget</a></li>
55
<li data-role="collapsible" data-enhanced="true" data-collapsed-icon="carat-d" data-expanded-icon="carat-u" data-iconpos="right" data-inset="false" class="ui-collapsible ui-collapsible-themed-content ui-collapsible-collapsed">
66
<h3 class="ui-collapsible-heading ui-collapsible-heading-collapsed">
7-
<a href="#" class="ui-collapsible-heading-toggle ui-btn ui-btn-icon-right ui-btn-inherit ui-icon-carat-d">
8-
Checkboxradio widget<span class="ui-collapsible-heading-status"> click to expand contents</span>
9-
</a>
7+
<a href="#" class="ui-collapsible-heading-toggle ui-btn ui-btn-icon-right ui-btn-inherit ui-icon-carat-d"
8+
>Checkboxradio widget<span class="ui-collapsible-heading-status"> click to expand contents</span><
9+
/a>
1010
</h3>
1111
<div class="ui-collapsible-content ui-body-inherit ui-collapsible-content-collapsed" aria-hidden="true">
1212
<ul>

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
},
2525
"devDependencies": {
2626
"async": "0.2.9",
27+
"casperjs": "1.1.0-beta3",
2728
"cheerio": "0.12.4",
2829
"commitplease": "1.7.0",
2930
"grunt": "0.4.2",
3031
"grunt-bowercopy": "0.5.0",
32+
"grunt-casper": "0.3.2",
3133
"grunt-contrib-clean": "0.5.0",
3234
"grunt-contrib-compress": "0.5.2",
3335
"grunt-contrib-concat": "0.3.0",
@@ -40,6 +42,7 @@
4042
"grunt-coveralls": "0.3.0",
4143
"grunt-git-authors": "1.2.0",
4244
"grunt-hash-manifest": "0.5.1",
45+
"grunt-php": "0.3.2",
4346
"grunt-qunit-istanbul": "0.3.0",
4447
"grunt-qunit-junit": "0.1.0-alpha2",
4548
"jsdom": "0.8.3",

tests/casperjs/demos.test.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*global casper: false, __utils__: false */
2+
3+
var host = casper.cli.get( "host" ) || "localhost",
4+
port = casper.cli.get( "port" ) || 80,
5+
path = casper.cli.get( "path" ) || "",
6+
mouse = require("mouse").create(casper);
7+
8+
casper.options.viewportSize = {width: 1024, height: 768};
9+
10+
casper.test.begin("Root index should redirect to demos/", 2, function suite( test ) {
11+
casper.start( "http://" + host + ":" + port + path + "/" );
12+
13+
casper.then( function() {
14+
test.assertHttpStatus( 200 );
15+
test.assertUrlMatch( /\/demos\/$/, "/ redirects to /demos/" );
16+
});
17+
18+
casper.run(function() {
19+
test.done();
20+
});
21+
});
22+
23+
casper.test.begin("demos/ should render properly", 2, function suite( test ) {
24+
casper.start( "http://" + host + ":" + port + path + "/demos/" );
25+
26+
casper.then( function() {
27+
test.assertHttpStatus( 200 );
28+
test.assertExists(
29+
"li[data-filtertext='demos homepage'].ui-first-child",
30+
"First ListItem in menu panel should have class ui-first-child"
31+
);
32+
});
33+
34+
casper.run(function() {
35+
test.done();
36+
});
37+
});
38+
39+
casper.test.begin("Checkboxradio widget should render properly", 2, function suite( test ) {
40+
casper.start( "http://" + host + ":" + port + path + "/demos/" );
41+
42+
// Click "Checkboxradio widget" list item
43+
casper.then( function() {
44+
casper.clickLabel( "Checkboxradio widget", "a" );
45+
});
46+
47+
// Click "Checkboxes" sub list item
48+
casper.then( function() {
49+
casper.waitUntilVisible( "ul.jqm-list > li:nth-child(5) > div > ul > li.ui-first-child > a",
50+
function() {
51+
casper.clickLabel( "Checkboxes", "a" );
52+
}
53+
);
54+
});
55+
56+
casper.then( function() {
57+
casper.waitForUrl( /\/demos\/checkboxradio-checkbox\/$/, function() {
58+
test.assertVisible(
59+
"input[name='checkbox-0 ']",
60+
"Checkbox checkbox-0 should be visible"
61+
);
62+
test.assertEvalEquals(
63+
function() {
64+
return $( "input[name='checkbox-0 ']" ).parent( "div" )[0].className;
65+
},
66+
"ui-checkbox",
67+
"Checkbox should be enhanced"
68+
);
69+
});
70+
});
71+
72+
casper.run(function() {
73+
test.done();
74+
});
75+
});

0 commit comments

Comments
 (0)