From b28028ac4082842143b0f528d6bc539da6ccb419 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Thu, 21 Sep 2017 12:49:18 -0400 Subject: mega changes, including updates and X --- .../angular-carousel/test/unit/angular-carousel.js | 624 +++++++++++++++++++++ .../test/unit/angular-carousel.shifty.js | 20 + 2 files changed, 644 insertions(+) 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/unit') 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..faea0e94 --- /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