From 83400033a3b7a91ad072a5d306355c9cd5a80d82 Mon Sep 17 00:00:00 2001 From: PliablePixels Date: Fri, 24 Jul 2015 15:48:01 -0400 Subject: integrated event scrubbing with direct image access - need to clean up code --- www/lib/angular-carousel/test/karma.conf.js | 71 +++ .../angular-carousel/test/unit/angular-carousel.js | 624 +++++++++++++++++++++ .../test/unit/angular-carousel.shifty.js | 20 + 3 files changed, 715 insertions(+) create mode 100644 www/lib/angular-carousel/test/karma.conf.js create mode 100755 www/lib/angular-carousel/test/unit/angular-carousel.js create mode 100644 www/lib/angular-carousel/test/unit/angular-carousel.shifty.js (limited to 'www/lib/angular-carousel/test') diff --git a/www/lib/angular-carousel/test/karma.conf.js b/www/lib/angular-carousel/test/karma.conf.js new file mode 100644 index 00000000..00f32b69 --- /dev/null +++ b/www/lib/angular-carousel/test/karma.conf.js @@ -0,0 +1,71 @@ +var grunt = require('grunt'); +module.exports = function ( karma ) { + karma.set({ + /** + * From where to look for files, starting with the location of this file. + */ + basePath: './..', + + /** + * This is the list of file patterns to load into the browser during testing. + */ + files: [ + 'bower_components/angular/angular.js', + 'bower_components/angular-touch/angular-touch.js', + 'bower_components/angular-mocks/angular-mocks.js', + 'bower_components/requirejs/require.js', + 'dist/angular-carousel.js', + 'test/unit/*.js' + ], + + frameworks: [ 'jasmine' ], + plugins: [ 'karma-jasmine', 'karma-firefox-launcher', 'karma-chrome-launcher', 'karma-coverage'], + + logLevel: 'DEBUG', + /** + * How to report, by default. + */ + reporters: ['dots', 'coverage'], + + preprocessors: { + // source files, that you wanna generate coverage for + // do not include tests or libraries + // (these files will be instrumented by Istanbul) + '../dist/*.js': ['coverage'] + }, + + coverageReporter: { + type : 'html', + dir : 'coverage/' + }, + + /** + * On which port should the browser connect, on which port is the test runner + * operating, and what is the URL path for the browser to use. + */ + port: 7018, + runnerPort: 7100, + urlRoot: '/', + + /** + * Disable file watching by default. + */ + autoWatch: false, + + /** + * The list of browsers to launch to test ondest * default, but other browser names include: + * Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS + * + * Note that you can also use the executable name of the browser, like "chromium" + * or "firefox", but that these vary based on your operating system. + * + * You may also leave this blank and manually navigate your browser to + * http://localhost:9018/ when you're running tests. The window/tab can be left + * open and the tests will automatically occur there during the build. This has + * the aesthetic advantage of not launching a browser every time you save. + */ + browsers: [ + 'Chrome' + ] + }); +}; diff --git a/www/lib/angular-carousel/test/unit/angular-carousel.js b/www/lib/angular-carousel/test/unit/angular-carousel.js new file mode 100755 index 00000000..5b2031da --- /dev/null +++ b/www/lib/angular-carousel/test/unit/angular-carousel.js @@ -0,0 +1,624 @@ +/*global waits, runs, iit, browserTrigger, beforeEach, afterEach, describe, it, inject, expect, module, angular, $*/ + +describe('carousel', function () { + 'use strict'; + + var scope, $compile, $sandbox; + + + //$('body').append(""); + /*$('body').append("");*/ + + //console.log(document.location); + beforeEach( + module('angular-carousel') + ); + + beforeEach(inject(function ($rootScope, _$compile_) { + scope = $rootScope; + $compile = _$compile_; + // $('body').css({ + // padding: 0, + // margin:0 + // }); + // $sandbox = $('
').appendTo($('body')); + })); + + afterEach(function() { + //$sandbox.remove(); + scope.$destroy(); + }); + + function compileTpl(overrideOptions) { + var options = { + useIndex: false, + useIndicator: false, + useControl: false, + useBuffer: false, + nbItems: 25, + useWatch: false + }; + if (overrideOptions) angular.extend(options, overrideOptions); + var sampleData = { + scope: { + items: [], + localIndex: 5 + } + }; + for (var i=0; i 0', function() { + var elm = compileTpl({useIndex: 1}); + fakeMove(elm, minMove); + expect(elm.scope().carouselCollection.index).toBe(0); + }); + it('should move to next slide on swipe forward', function() { + var elm = compileTpl(); + fakeMove(elm, -minMove); + expect(elm.scope().carouselCollection.index).toBe(1); + }); + it('should not move to next slide on too little swipe forward', function() { + var elm = compileTpl(); + fakeMove(elm, -12); + expect(elm.scope().carouselCollection.index).toBe(0); + }); + it('should not move to prev slide on too little swipe backward', function() { + var elm = compileTpl({useIndex: 1}); + fakeMove(elm, 12); + expect(elm.scope().carouselCollection.index).toBe(1); + }); + it('should follow multiple moves', function() { + var elm = compileTpl(); + // var minMove = -(elm.outerWidth() * 0.1 + 1); + fakeMove(elm, -minMove); + //console.log(minMove, elm.scope().carouselCollection.index); + fakeMove(elm,-minMove); + fakeMove(elm, -minMove); + expect(elm.scope().carouselCollection.index).toBe(3); + fakeMove(elm, minMove); + fakeMove(elm, minMove); + expect(elm.scope().carouselCollection.index).toBe(1); + fakeMove(elm, minMove); + fakeMove(elm, minMove); + fakeMove(elm, minMove); + expect(elm.scope().carouselCollection.index).toBe(0); + }); + }); + + describe('swipe buffered behaviour', function () { + it('should follow multiple moves and buffer accordingly', function() { + var elm = compileTpl({useBuffer: true}); + var minMove = -(elm.outerWidth() * 0.1 + 1); + fakeMove(elm, minMove); + + waitAndCheck(function() { + expect(elm.scope().carouselCollection.index).toBe(1); + expect(elm.find('li')[0].id).toBe('slide-0'); + fakeMove(elm, minMove); + waitAndCheck(function() { + expect(elm.scope().carouselCollection.index).toBe(2); + expect(elm.find('li')[0].id).toBe('slide-1'); + fakeMove(elm, -minMove); + waitAndCheck(function() { + expect(elm.scope().carouselCollection.index).toBe(1); + expect(elm.find('li')[0].id).toBe('slide-0'); + fakeMove(elm, -minMove); + waitAndCheck(function() { + expect(elm.scope().carouselCollection.index).toBe(0); + expect(elm.find('li')[0].id).toBe('slide-0'); + }); + }); + }); + }); + }); + }); + + describe('collection watch', function () { + describe('standard watch (no deep)', function () { + it('it should display first slide when we reset the collection', function () { + var elm = compileTpl({useIndex: 'localIndex'}); + scope.localIndex = 5; + scope.$digest(); + expect(elm.scope().carouselCollection.index).toBe(5); + scope.items = [{id:1}, {id:2}]; + scope.$digest(); + expect(elm.position().left).toBe(0); + expect(elm.css('left')).toBe('auto'); + expect(elm.scope().carouselCollection.index).toBe(0); + }); + it('should NOT update slides when collection changes partially', function() { + var elm = compileTpl(); + var originalLength = scope.items.length; + expect(elm.find('li').length).toBe(originalLength); + scope.items.push({'text': 'new item', 'id': 999}); + scope.$digest(); + expect(elm.find('li').length).toBe(originalLength); + expect(elm.find('li').last()[0].id).toBe('slide-' + (originalLength - 1)); + scope.items.pop(); + scope.items.pop(); + scope.items.pop(); + scope.$digest(); + expect(elm.find('li').length).toBe(originalLength); + expect(elm.find('li').last()[0].id).toBe('slide-' + (originalLength - 1)); + }); + }); + describe('standard watch (no deep) + buffer', function () { + it('it should display first slide when we reset the collection', function () { + var elm = compileTpl({useBuffer: true, useIndex: 'localIndex'}); + scope.localIndex = 5; + scope.$digest(); + expect(elm.scope().carouselCollection.index).toBe(5); + scope.items = [{id:1}, {id:2}]; + scope.$digest(); + expect(elm.position().left).toBe(0); + expect(elm.css('left')).toBe('auto'); + expect(elm.scope().carouselCollection.index).toBe(0); + }); + it('should NOT update slides when collection changes partially', function() { + var elm = compileTpl({useBuffer: true}); + var originalLength = elm.scope().carouselCollection.bufferSize; + expect(elm.find('li').length).toBe(originalLength); + scope.items.push({'text': 'new item', 'id': 999}); + scope.$digest(); + expect(elm.find('li').length).toBe(originalLength); + expect(elm.find('li').last()[0].id).toBe('slide-' + (originalLength - 1)); + scope.items.pop(); + scope.items.pop(); + scope.items.pop(); + scope.$digest(); + expect(elm.find('li').length).toBe(originalLength); + expect(elm.find('li').last()[0].id).toBe('slide-' + (originalLength - 1)); + }); + }); + describe('deep watch', function () { + it('should display first slide when we reset the collection', function () { + var elm = compileTpl({useIndex: 'localIndex', useWatch: true}); + scope.localIndex = 5; + scope.$digest(); + expect(elm.scope().carouselCollection.index).toBe(5); + scope.items = [{id:1}, {id:2}]; + scope.$digest(); + expect(elm.position().left).toBe(0); + expect(elm.css('left')).toBe('auto'); + expect(elm.scope().carouselCollection.index).toBe(0); + }); + it('should update slides when collection changes partially', function() { + var elm = compileTpl({useWatch: true}); + expect(elm.find('li').length).toBe(scope.items.length); + scope.items.push({'text': 'new item', 'id': 999}); + scope.$digest(); + expect(elm.find('li').length).toBe(scope.items.length); + expect(elm.find('li').last()[0].id).toBe('slide-999'); + scope.items.pop(); + scope.items.pop(); + scope.items.pop(); + scope.$digest(); + expect(elm.find('li').length).toBe(scope.items.length); + expect(elm.find('li').last()[0].id).toBe('slide-' + scope.items[scope.items.length - 1].id); + }); + }); + describe('deep watch + buffer', function () { + it('should display first slide when we reset the collection', function () { + var elm = compileTpl({userBuffer:true, useIndex: 'localIndex', useWatch: true}); + scope.localIndex = 5; + scope.$digest(); + expect(elm.scope().carouselCollection.index).toBe(5); + scope.items = [{id:1}, {id:2}]; + scope.$digest(); + expect(elm.position().left).toBe(0); + expect(elm.css('left')).toBe('auto'); + expect(elm.scope().carouselCollection.index).toBe(0); + }); + it('should update slides when collection changes partially', function() { + var elm = compileTpl({userBuffer:true, useWatch: true}); + expect(elm.find('li').length).toBe(scope.items.length); + scope.items.push({'text': 'new item', 'id': 999}); + scope.$digest(); + expect(elm.find('li').length).toBe(scope.items.length); + expect(elm.find('li').last()[0].id).toBe('slide-999'); + scope.items.pop(); + scope.items.pop(); + scope.items.pop(); + scope.$digest(); + expect(elm.find('li').length).toBe(scope.items.length); + expect(elm.find('li').last()[0].id).toBe('slide-' + scope.items[scope.items.length - 1].id); + }); + }); + + }); + // describe('delayed collection and index', function () { + // it('should follow multiple moves and buffer accordingly', function() { + + // describe('swipe buffered + index behaviour', function () { + // it('should initialise buffer start correctly when index is set', function() { + // var elm = compileTpl({useBuffer: true, useIndex: "localIndex", nbItems: 5}); + // scope.localIndex = 2; + // scope.$digest(); + // expect(elm.scope().carouselBufferStart).toBe(1); + // }); + // it('should initialise buffer start correctly when index is set at 0', function() { + // var elm = compileTpl({useBuffer: true, useIndex: "localIndex", nbItems: 5}); + // scope.localIndex = 0; + // scope.$digest(); + // expect(elm.scope().carouselBufferStart).toBe(0); + // }); + // it('should initialise buffer start correctly when index is set at last item', function() { + // var nbItems = 5; + // var elm = compileTpl({useBuffer: true, useIndex: "localIndex", nbItems: 5}); + // scope.localIndex = nbItems-1; + // scope.$digest(); + // console.log(elm.scope().activeIndex); + // waits(10); + // runs(function() { + // expect(elm.scope().carouselBufferStart).toBe(nbItems - elm.scope().carouselBufferSize); + // }); + // }); + // it('buffer position should update when local index changes', function() { + // var elm = compileTpl({useBuffer: true, useIndex: "localIndex", nbItems: 5}); + // scope.localIndex = 2; + // scope.$digest(); + // expect(elm.scope().carouselBufferStart).toBe(1); + // scope.localIndex = 3; + // scope.$digest(); + // waits(100); + // runs(function() { + // expect(elm.scope().carouselBufferStart).toBe(1); + // scope.localIndex = 0; + // scope.$digest(); + // expect(elm.scope().carouselBufferStart).toBe(0); + // }); + // }); + //}); +*/ + +}); + diff --git a/www/lib/angular-carousel/test/unit/angular-carousel.shifty.js b/www/lib/angular-carousel/test/unit/angular-carousel.shifty.js new file mode 100644 index 00000000..994169ce --- /dev/null +++ b/www/lib/angular-carousel/test/unit/angular-carousel.shifty.js @@ -0,0 +1,20 @@ +/*global waits, runs, iit, browserTrigger, beforeEach, afterEach, describe, it, inject, expect, module, angular, $*/ + +describe('angular-carousel.shifty', function () { + 'use strict'; + + describe("compatibility with requirejs", function(){ + var loadShifty = function() { + module('angular-carousel.shifty'); + }; + it("should not throw an exception when load the shifty within requirejs environment", function(){ + expect(loadShifty).not.toThrow(); + }); + + it("should not throw an exception when inject `Tweenable` within requirejs environment", function(){ + loadShifty(); + expect(function() {inject(function(Tweenable){});}).not.toThrow(); + }); + }); + +}); -- cgit v1.2.3