Skip to content

Commit

Permalink
Added .travis.yml and some functional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
baig committed Mar 27, 2015
1 parent f6f8335 commit ba711c1
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 47 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
node_js:
- "0.12"
- "iojs"
- "iojs-v1.0.4"
before_install:
- git clone git://github.com/n1k0/casperjs.git ~/casperjs
- cd ~/casperjs
- git checkout tags/1.0.4
- export PATH=$PATH:`pwd`/bin
- cd -
before_script:
- phantomjs --version
- casperjs --version
32 changes: 12 additions & 20 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ gulp.task("minify", 'Minifies all the script files.', [], function () {
aliases: ['m', 'M']
});

gulp.task("minify-css", 'Minifies the CSS stylesheets.', [], function() {
gulp.task("minify-css", 'Minifies the CSS stylesheets.', [], function () {
"use strict";
gulp.src('css/**/*.css')
.pipe(concat('jqm.editable.listview.min.css'))
Expand All @@ -71,7 +71,7 @@ gulp.task("minify-css", 'Minifies the CSS stylesheets.', [], function() {
aliases: ['s', 'S']
});

gulp.task("assets", 'Copies all assets (css stylesheets, images etc.) to the build folder.', [], function(){
gulp.task("assets", 'Copies all assets (css stylesheets, images etc.) to the build folder.', [], function () {
"use strict";
gulp.src("css/**/*")
.pipe(concat("jqm.editable.listview.css"))
Expand All @@ -97,33 +97,25 @@ gulp.task('lint', '', [], function () {
var stylish = require('gulp-jscs-stylish');

gulp.src('js/*.js')
.pipe(jshint()) // hint
.pipe(jscs()) // enforce style guide
.on('error', noop) // don't stop on error
.pipe(stylish.combineWithHintResults()) // combine with jshint results
.pipe(jshint.reporter('jshint-stylish')); // use any jshint reporter to log hint and style guide errors
.pipe(jshint()) // hint
.pipe(jscs()) // enforce style guide
.on('error', noop) // don't stop on error
.pipe(stylish.combineWithHintResults()) // combine with jshint results
.pipe(jshint.reporter('jshint-stylish')); // use any jshint reporter to log hint and style guide errors
});

gulp.task('unit', '', [], function () {
var mocha = require('gulp-mocha');
var chai = require('chai');
var mochaPhantomJS = require('gulp-mocha-phantomjs');

return gulp.src(['test/js/**/*.js'], {
return gulp.src(['tests/test-runner.html'], {
read: false
})
.pipe(mocha({
reporter: 'spec',
globals: {
should: chai.expect
}
.pipe(mochaPhantomJS({
reporter: 'spec'
}));
});


gulp.task('default', '', ['build']);

gulp.task('test', ['lint', 'unit']);

//gulp.task('test-watch', function () {
// gulp.watch(['src/**/*.js', 'test/**/*.js'], ['test']);
//});

71 changes: 44 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "jqm-editable-listview",
"version": "0.3.1",
"description": "A customized version of jQuery Mobile Listview Widget that supports insertion of new list items and removal of existing list items",
"main": "js/editable-listview.js",
"scripts": {
"test": "./node_modules/karma/bin/karma start --browsers Firefox --single-run"
},
"repository": {
"type": "git",
"url": "https://github.com/baig/jquerymobile-editablelistview.git"
},
"keywords": [
"name": "jqm-editable-listview",
"version": "0.3.1",
"description": "A customized version of jQuery Mobile Listview Widget that supports insertion of new list items and removal of existing list items",
"main": "js/editable-listview.js",
"scripts": {
"test": "./node_modules/karma/bin/karma start --browsers Firefox --single-run"
},
"repository": {
"type": "git",
"url": "https://github.com/baig/jquerymobile-editablelistview.git"
},
"keywords": [
"jquery",
"mobile",
"jquerymobile",
Expand All @@ -21,19 +21,36 @@
"editablelistview",
"editable-listview"
],
"author": "Wasif Hasan Baig",
"license": "MIT",
"bugs": {
"url": "https://github.com/baig/jquerymobile-editablelistview/issues"
},
"homepage": "https://github.com/baig/jquerymobile-editablelistview",
"devDependencies": {
"del": "^1.1.0",
"gulp-concat": "^2.4.2",
"gulp-help": "^1.3.1",
"gulp-minify-css": "^0.3.11",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.0.2",
"karma": "~0.12"
}
"author": "Wasif Hasan Baig",
"license": "MIT",
"bugs": {
"url": "https://github.com/baig/jquerymobile-editablelistview/issues"
},
"scripts" : {
"test": "casperjs test tests/functional/casper.spec.js"
},
"homepage": "https://github.com/baig/jquerymobile-editablelistview",
"devDependencies": {
"casper-chai": "^0.2.1",
"chai": "^2.1.2",
"chai-as-promised": "^4.3.0",
"chai-jq": "0.0.8",
"chai-jquery": "^2.0.0",
"del": "^1.1.0",
"gulp": "^3.8.11",
"gulp-concat": "^2.4.2",
"gulp-help": "^1.3.1",
"gulp-jscs": "^1.4.0",
"gulp-jscs-stylish": "^1.0.2",
"gulp-jshint": "^1.9.4",
"gulp-minify-css": "^0.3.11",
"gulp-mocha": "^2.0.0",
"gulp-mocha-phantomjs": "^0.5.3",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.0.2",
"jquery": "^2.1.3",
"jquery-mobile": "^1.4.1",
"jshint-stylish": "^1.0.1",
"mocha": "^2.2.1"
}
}
198 changes: 198 additions & 0 deletions tests/functional/casper.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
var cwd = require('fs').workingDirectory;
var dump = require('utils').dump;
var system = require('system');
var webpage = require('webpage');

casper.test.setUp(function () {
casper.options.clientScripts = [
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/jquery-mobile/dist/jquery.mobile.min.js',
'./js/editable-listview.js'
];
// casper.start().userAgent('Mosaic 0.1');
casper.start("file://" + cwd + "/tests/functional/simple.html");
});

casper.test.tearDown(function () {
casper.echo('Goodbye!');
});

casper.test.begin('Simple Editable Listview is enhanced with correct markup', 5, function suite(test) {

casper.then(function () {
dump(this.getElementAttribute('h1 button', 'class'))
test.assertEquals(this.exists('div[data-role="collapsible"]'), true);
test.assertEquals(this.getElementAttribute('div[data-role="collapsible"]', 'class'), 'ui-collapsible ui-collapsible-inset ui-corner-all ui-collapsible-themed-content ui-collapsible-collapsed');
test.assertEquals(this.getElementAttribute('h1', 'class'), 'ui-collapsible-heading ui-collapsible-heading-collapsed');
test.assertEquals(this.exists('h1.ui-collapsible-heading'), true);
test.assertEquals(this.exists('h1.ui-collapsible-heading'), true);
});

casper.run(function () {
test.done();
});
});

casper.test.begin('Clicking on Add button takes into Edit mode', 1, function (test) {
casper.then(function () {
this.click('h1 button');
});

casper.then(function () {
// console.log('clicked edit button')
test.assertEquals(this.exists('ul li.ui-editable-temp'), true);
// dump(this.getElementInfo('div[data-role="collapsible"]').html)
});

casper.run(function () {
test.done();
});
});

//casper.test.begin('Clicking on plus button inserts the list item', 6, function (test) {
// casper.start("file://" + cwd + "/tests/functional/simple.html");
//
// casper.then(function () {
// test.assertTitle("Casper", "Casper title is ok");
// test.assertTitle("Casper", "Casper title is ok");
// test.assertTitle("Casper", "Casper title is ok");
// });
//
// casper.run(function () {
// test.done();
// });
//});
//
//casper.test.begin('Nothing happens when clicking on plus button when input text is empty', 6, function (test) {
// casper.start("file://" + cwd + "/tests/functional/simple.html");
//
// casper.then(function () {
// test.assertTitle("Casper", "Casper title is ok");
// test.assertTitle("Casper", "Casper title is ok");
// test.assertTitle("Casper", "Casper title is ok");
// });
//
// casper.run(function () {
// test.done();
// });
//});
//
//casper.test.begin('Clicking on Done', 6, function (test) {
// casper.start("file://" + cwd + "/tests/functional/simple.html");
//
// casper.then(function () {
// test.assertTitle("Casper", "Casper title is ok");
// test.assertTitle("Casper", "Casper title is ok");
// test.assertTitle("Casper", "Casper title is ok");
// });
//
// casper.run(function () {
// test.done();
// });
//});
//
//
//
//casper.test.begin('ClientUtils.exists() tests', 5, function (test) {
// var clientutils = require('clientutils').create();
// fakeDocument('<ul class="foo"><li>bar</li><li>baz</li></ul>');
// test.assert(clientutils.exists('ul'),
// 'ClientUtils.exists() checks that an element exist');
// test.assertNot(clientutils.exists('ol'),
// 'ClientUtils.exists() checks that an element exist');
// test.assert(clientutils.exists('ul.foo li'),
// 'ClientUtils.exists() checks that an element exist');
// // xpath
// test.assert(clientutils.exists(x('//ul')),
// 'ClientUtils.exists() checks that an element exist using XPath');
// test.assertNot(clientutils.exists(x('//ol')),
// 'ClientUtils.exists() checks that an element exist using XPath');
// fakeDocument(null);
// test.done();
//});
//
//casper.test.begin('ClientUtils.getElementBounds() tests', 3, function (test) {
// casper.start().then(function () {
// this.page.content = '<div id="b1" style="position:fixed;top:10px;left:11px;width:50px;height:60px"></div>';
// test.assertEquals(
// this.getElementBounds('#b1'), {
// top: 10,
// left: 11,
// width: 50,
// height: 60
// },
// 'ClientUtils.getElementBounds() retrieves element boundaries'
// );
// });
// casper.then(function () {
// var html = '<div id="boxes">';
// html += ' <div style="position:fixed;top:10px;left:11px;width:50px;height:60px"></div>';
// html += ' <div style="position:fixed;top:20px;left:21px;width:70px;height:80px"></div>';
// html += '</div>';
// this.page.content = html;
// var bounds = this.getElementsBounds('#boxes div');
// test.assertEquals(
// bounds[0], {
// top: 10,
// left: 11,
// width: 50,
// height: 60
// },
// 'ClientUtils.getElementsBounds() retrieves multiple elements boundaries'
// );
// test.assertEquals(
// bounds[1], {
// top: 20,
// left: 21,
// width: 70,
// height: 80
// },
// 'ClientUtils.getElementsBounds() retrieves multiple elements boundaries'
// );
// });
// casper.run(function () {
// test.done();
// });
//});
//
//
//casper.test.begin('ClientUtils.getElementBounds() page zoom factor tests', 3, function (test) {
// casper.start().zoom(2).then(function () {
// var html = '<div id="boxes">';
// html += ' <div id="b1" style="position:fixed;top:10px;left:11px;width:50px;height:60px"></div>';
// html += ' <div style="position:fixed;top:20px;left:21px;width:70px;height:80px"></div>';
// html += '</div>';
// this.page.content = html;
// test.assertEquals(
// this.getElementBounds('#b1'), {
// top: 20,
// left: 22,
// width: 100,
// height: 120
// },
// 'ClientUtils.getElementBounds() is aware of the page zoom factor'
// );
// var bounds = this.getElementsBounds('#boxes div');
// test.assertEquals(
// bounds[0], {
// top: 20,
// left: 22,
// width: 100,
// height: 120
// },
// 'ClientUtils.getElementsBounds() is aware of the page zoom factor'
// );
// test.assertEquals(
// bounds[1], {
// top: 40,
// left: 42,
// width: 140,
// height: 160
// },
// 'ClientUtils.getElementsBounds() is aware of the page zoom factor'
// );
// });
// casper.run(function () {
// test.done();
// });
//});
Loading

0 comments on commit ba711c1

Please sign in to comment.