Permalink
Browse files

Merge pull request #774 from Johann-S/unit_test

Add unit test to Ratchet
  • Loading branch information...
2 parents 8a32a9a + c95927b commit 086702721ff36b908a7fc7b8f61e6f5e1d013aeb @XhmikosR XhmikosR committed Jan 27, 2016
Showing with 213 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +27 −1 Gruntfile.js
  3. +5 −0 js/tests/.jshintrc
  4. +69 −0 js/tests/SpecRunner.html
  5. +20 −0 js/tests/commonSpec.js
  6. +52 −0 js/tests/modalsSpec.js
  7. +32 −0 js/tests/sliderSpec.js
  8. +6 −0 js/tests/vendor/touchfaker.min.js
  9. +1 −0 package.json
View
@@ -39,3 +39,4 @@ docs/.jekyll-metadata
# Folders to ignore
node_modules
bower_components
+.grunt
View
@@ -29,6 +29,7 @@ module.exports = function (grunt) {
docsDistPath: 'docs/dist/',
docsPath: 'docs/',
jsPath: 'js/',
+ jsTestPath: 'js/tests/',
srcPath: 'sass/'
},
@@ -303,6 +304,12 @@ module.exports = function (grunt) {
},
docs: {
src: ['<%= meta.docsAssetsPath %>/js/docs.js', '<%= meta.docsAssetsPath %>/js/fingerblast.js']
+ },
+ tests: {
+ options: {
+ jshintrc: 'js/tests/.jshintrc'
+ },
+ src: 'js/tests/*.js'
}
},
@@ -318,6 +325,9 @@ module.exports = function (grunt) {
},
docs: {
src: '<%= jshint.docs.src %>'
+ },
+ tests: {
+ src: '<%= jshint.tests.src %>'
}
},
@@ -394,6 +404,22 @@ module.exports = function (grunt) {
}
]
}
+ },
+
+ jasmine: {
+ src: '<%= jshint.src.src %>',
+ options: {
+ specs: '<%= jshint.tests.src %>',
+ styles: 'dist/ratchet.min.css',
+ display: 'short',
+ vendor: [
+ '<%= meta.docsAssetsPath %>js/fingerblast.js',
+ '<%= jshint.src.src %>',
+ '<%= meta.jsTestPath %>vendor/touchfaker.min.js'
+ ],
+ outfile: 'js/tests/SpecRunner.html',
+ keepRunner: true
+ }
}
});
@@ -408,7 +434,7 @@ module.exports = function (grunt) {
grunt.registerTask('validate-html', ['jekyll:docs', 'htmllint']);
grunt.registerTask('build', ['dist']);
grunt.registerTask('default', ['dist']);
- grunt.registerTask('test', ['dist', 'csslint', 'jshint', 'jscs', 'validate-html']);
+ grunt.registerTask('test', ['dist', 'csslint', 'jshint', 'jscs', 'jasmine', 'validate-html']);
grunt.registerTask('server', ['dist', 'jekyll:docs', 'connect', 'watch']);
grunt.registerTask('prep-release', ['dist', 'jekyll:github', 'htmlmin', 'compress']);
View
@@ -0,0 +1,5 @@
+{
+ "devel" : true,
+ "es3" : false,
+ "jasmine" : true
+}
@@ -0,0 +1,69 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Jasmine Spec Runner</title>
+ <link rel="shortcut icon" type="image/png" href=".grunt/grunt-contrib-jasmine/jasmine_favicon.png">
+
+ <link rel="stylesheet" type="text/css" href="../../.grunt/grunt-contrib-jasmine/jasmine.css">
+
+ <link rel="stylesheet" type="text/css" href="../../dist/ratchet.min.css">
+
+
+</head>
+<body>
+
+
+ <script src="../../.grunt/grunt-contrib-jasmine/es5-shim.js"></script>
+
+ <script src="../../.grunt/grunt-contrib-jasmine/jasmine.js"></script>
+
+ <script src="../../.grunt/grunt-contrib-jasmine/jasmine-html.js"></script>
+
+ <script src="../../.grunt/grunt-contrib-jasmine/json2.js"></script>
+
+ <script src="../../.grunt/grunt-contrib-jasmine/boot.js"></script>
+
+ <script src="../../docs/assets/js/fingerblast.js"></script>
+
+ <script src="../common.js"></script>
+
+ <script src="../modals.js"></script>
+
+ <script src="../popovers.js"></script>
+
+ <script src="../push.js"></script>
+
+ <script src="../segmented-controllers.js"></script>
+
+ <script src="../sliders.js"></script>
+
+ <script src="../toggles.js"></script>
+
+ <script src="vendor/touchfaker.min.js"></script>
+
+ <script src="../common.js"></script>
+
+ <script src="../modals.js"></script>
+
+ <script src="../popovers.js"></script>
+
+ <script src="../push.js"></script>
+
+ <script src="../segmented-controllers.js"></script>
+
+ <script src="../sliders.js"></script>
+
+ <script src="../toggles.js"></script>
+
+ <script src="commonSpec.js"></script>
+
+ <script src="modalsSpec.js"></script>
+
+ <script src="sliderSpec.js"></script>
+
+ <script src="../../.grunt/grunt-contrib-jasmine/reporter.js"></script>
+
+
+</body>
+</html>
@@ -0,0 +1,20 @@
+describe('Common', function () {
+ it('RATCHET namespace is defined', function () {
+ expect(typeof RATCHET !== 'undefined').toBe(true);
+ });
+
+ it('window.CustomEvent exists', function () {
+ expect(typeof window.CustomEvent !== 'undefined').toBe(true);
+ });
+
+ it('RATCHET.getBrowserCapabilities returns an object', function () {
+ var result = RATCHET.getBrowserCapabilities;
+ expect(typeof result === 'object').toBe(true);
+ });
+
+ it('RATCHET.getTransitionEnd returns string', function () {
+ var result = RATCHET.getTransitionEnd;
+ expect(typeof result === 'string').toBe(true);
+ expect(result.length > 0).toBe(true);
+ });
+});
@@ -0,0 +1,52 @@
+describe('Modals', function () {
+ beforeEach(function () {
+ var templateModal = [
+ '<a id="linkOpenModal" href="#myModal" class="btn">Open modal</a>',
+ '<div id="myModal" class="modal">',
+ '<header class="bar bar-nav">',
+ '<a id="linkCloseModal" class="icon icon-close pull-right" href="#myModal"></a>',
+ '<h1 class="title">Modal</h1>',
+ '</header>',
+ '<div class="content">',
+ '<p class="content-padded">The contents of my modal go here.</p>',
+ '</div>',
+ '</div>'
+ ].join('');
+ document.body.innerHTML += templateModal;
+ });
+
+ afterEach(function () {
+ var linkModal = document.getElementById('linkOpenModal');
+ var modal = document.getElementById('myModal');
+ linkModal.parentNode.removeChild(linkModal);
+ modal.parentNode.removeChild(modal);
+ });
+
+ it('Modal should fire modalOpen event', function (done) {
+ window.addEventListener('modalOpen', function () {
+ expect(true).toBe(true);
+ done();
+ });
+ var link = document.getElementById('linkOpenModal');
+ var eventTouchEnd = new CustomEvent('touchend', {
+ bubbles: true,
+ cancelable: true
+ });
+ link.dispatchEvent(eventTouchEnd);
+ });
+
+ it('Modal should fire modalClose event', function (done) {
+ var link = document.getElementById('linkOpenModal');
+ var eventTouchEnd = new CustomEvent('touchend', {
+ bubbles: true,
+ cancelable: true
+ });
+ window.addEventListener('modalClose', function () {
+ expect(true).toBe(true);
+ done();
+ });
+ link.dispatchEvent(eventTouchEnd);
+ var closeLink = document.getElementById('linkCloseModal');
+ closeLink.dispatchEvent(eventTouchEnd);
+ });
+});
@@ -0,0 +1,32 @@
+describe('Slider', function () {
+ var slider = null;
+ beforeEach(function () {
+ var templateSlider = [
+ '<div class="slider" id="mySlider">',
+ '<div id="mySlider" class="slide-group">',
+ '<div id="firstSlide" class="slide">',
+ '<img src="http://goratchet.com/assets/img/slide-2.jpg">',
+ '</div>',
+ '<div class="slide">',
+ '<img src="http://goratchet.com/assets/img/slide-3.jpg">',
+ '</div>',
+ '</div>',
+ '</div>'
+ ].join('');
+ document.body.innerHTML += templateSlider;
+ slider = document.getElementById('mySlider');
+ });
+
+ afterEach(function () {
+ slider.parentNode.removeChild(slider);
+ slider = null;
+ });
+
+ it('Slider should fire slide event', function (done) {
+ slider.addEventListener('slide', function () {
+ expect(true).toBe(true);
+ done();
+ });
+ TouchFaker.fakeEvent('touchstart', '#firstSlide');
+ });
+});
@@ -0,0 +1,6 @@
+/*!
+ * TouchFaker - v1.1.0 - 2015-05-21
+ * https://github.com/Johann-S/TouchFaker
+ * Copyright (c) 2015 Johann SERVOIRE; Licensed MIT
+ */
+!function(){"use strict";function a(a,b,c,d,e){d=d||0,e=e||0,this.identifier=b,this.target=a,this.clientX=c.clientX+d||0,this.clientY=c.clientY+e||0,this.screenX=c.screenX+d||0,this.screenY=c.screenY+e||0,this.pageX=c.pageX+d||0,this.pageY=c.pageY+e||0}function b(){var a=[];return a.item=function(a){return this[a]||null},a.identifiedTouch=function(a){return this[a+1]||null},a}function c(){for(var a=[window,document.documentElement],b=["ontouchstart","ontouchmove","ontouchcancel","ontouchend"],c=0;c<a.length;c++)for(var d=0;d<b.length;d++)a[c]&&void 0===a[c][b[d]]&&(a[c][b[d]]=null)}function d(){return"ontouchstart"in window||window.Modernizr&&window.Modernizr.touch||(navigator.msMaxTouchPoints||navigator.maxTouchPoints)>2}function e(a,b,c){var d=document.createEvent("Event");d.initEvent(a,!0,!0);var e="undefined"!=typeof c?g(c):f(b);d.touches=i(e,a,b),d.targetTouches=i(e,a,b),d.changedTouches=j(e,a,b),b.dispatchEvent(d)}function f(a){var b=a.getBoundingClientRect();return{pageX:b.left,pageY:b.top}}function g(a){var b={};return b.clientX=a.hasOwnProperty("clientX")?a.clientX:0,b.clientY=a.hasOwnProperty("clientY")?a.clientY:0,b.pageX=a.hasOwnProperty("pageX")?a.pageX:0,b.pageY=a.hasOwnProperty("pageY")?a.pageY:0,b.screenX=a.hasOwnProperty("screenX")?a.screenX:0,b.screenY=a.hasOwnProperty("screenY")?a.screenY:0,b}function h(c,d){var e=new b;return e.push(new a(d,1,c,0,0)),e}function i(a,c,d){var e=new b;return"touchend"!==c&&(e=h(a,d)),e}function j(a,b,c){var d=h(a,c);return("touchstart"===b||"touchend"===b)&&d.splice(0,1),d}document.createTouch||(document.createTouch=function(b,c,d,e,f,g,h,i,j){return(void 0===i||void 0===j)&&(i=e-window.pageXOffset,j=f-window.pageYOffset),new a(c,d,{pageX:e,pageY:f,screenX:g,screenY:h,clientX:i,clientY:j})}),document.createTouchList||(document.createTouchList=function(){for(var a=new b,c=0;c<arguments.length;c++)a[c]=arguments[c];return a.length=arguments.length,a}),"undefined"==typeof window.TouchFaker&&(window.TouchFaker={}),window.TouchFaker.multiTouchOffset=75,window.TouchFaker.init=function(){d()||c()}(),window.TouchFaker.fakeEvent=function(a,b,c){var d=b;if("string"==typeof b&&(d=document.querySelector(b)),!d)throw new Error("Target cannot be found");if(-1===a.indexOf("touch"))throw new Error("Not a touch event");if("undefined"!=typeof c&&"object"!=typeof c)throw new Error("Params has to be an Object");e(a,d,c)}}();
View
@@ -42,6 +42,7 @@
"grunt-contrib-watch": "~0.6.1",
"grunt-csscomb": "~3.1.0",
"grunt-html": "~5.0.0",
+ "grunt-contrib-jasmine": "~0.9.2",
"grunt-jekyll": "~0.4.2",
"grunt-jscs": "~2.6.0",
"grunt-sass": "~1.1.0",

0 comments on commit 0867027

Please sign in to comment.