Skip to content

Commit

Permalink
Merge branch 'fa-scroll-view-test' of github.com:stristr/famous-angul…
Browse files Browse the repository at this point in the history
…ar into stristr-fa-scroll-view-test

Conflicts:
	test/bootstrap/common.js
  • Loading branch information
zackbrown committed Jun 4, 2014
2 parents ec906a4 + 7461d45 commit 6ab3c41
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 9 deletions.
21 changes: 17 additions & 4 deletions test/bootstrap/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ window.famousAngularCommon = function($scope, $compile) {
var surface = scope.isolate[scope.$id].renderNode;
return surface;
},
getIsolateFromElement: function(elem){
var scope = elem.scope();
var isolate = scope.isolate[scope.$id];
return isolate;
createApp: function(markup, height, scope) {
height = height || 100;

var app = $compile(
'<fa-app style="height: ' + height + 'px">' +
markup +
'</fa-app>'
)(scope || $scope)[0];

document.body.appendChild(app);
return app;
},
destroyApp: function(app) {
document.body.removeChild(app);
},
mockEvent: function(eventData) {
return new CustomEvent('mock', eventData || {});
}
}
};
13 changes: 8 additions & 5 deletions test/directives/faPipeFromSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

describe('faPipeFrom', function() {
var eventHandler, $compile, $scope, $rootScope, $famous;
var eventHandler, common, $compile, $scope, $rootScope, $famous;
var listenerValue = false;

beforeEach(module('famous.angular'));
Expand All @@ -13,6 +13,8 @@ describe('faPipeFrom', function() {
$famous = _$famous_;

eventHandler = new $famous['famous/core/EventHandler']();

common = window.famousAngularCommon($scope, $compile);
}));

it('should correctly pipe from an array of eventhandlers', function(){
Expand All @@ -28,13 +30,11 @@ describe('faPipeFrom', function() {
$scope.toEventHandler = eventHandler;

// Inject a simple disconnected pipeline into the document body
var pipeline = $compile(
var pipeline = common.createApp(
'<fa-view fa-pipe-from="fromEventHandler" id="pipe-from">' +
'<fa-surface fa-pipe-to="toEventHandler" id="pipe-to"></fa-surface>' +
'</fa-view>'
)($scope);

document.body.appendChild(pipeline[0]);
);

var toHandler = $famous.find('#pipe-to')[0].renderNode.eventHandler;
var fromHandler = $famous.find('#pipe-from')[0].renderNode._eventInput;
Expand All @@ -55,5 +55,8 @@ describe('faPipeFrom', function() {
// the pipeline is connected
toHandler.trigger('testevent');
expect(listenerValue).toBe(true);

// Cleanup
common.destroyApp(pipeline);
});
});
115 changes: 115 additions & 0 deletions test/directives/faScrollViewSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use strict';

describe('faScrollView', function() {
var eventHandler, common, $compile, $timeout, $scope, $famous;

beforeEach(module('famous.angular'));

beforeEach(inject(function(_$compile_, _$timeout_, _$rootScope_, _$famous_) {
$compile = _$compile_;
$timeout = _$timeout_;
$scope = _$rootScope_.$new();
$famous = _$famous_;

eventHandler = new $famous['famous/core/EventHandler']();

common = window.famousAngularCommon($scope, $compile);
}));

it('should implement the Scrollview event pipeline', function() {
var app = common.createApp(
'<fa-scroll-view fa-pipe-from="eventHandler">' +
'<fa-view>' +
'<fa-surface fa-pipe-to="eventHandler" fa-size="[undefined, 100]"></fa-surface>' +
'</fa-view>' +
'</fa-scroll-view>'
);

$scope.eventHandler = eventHandler;
$scope.$apply();

var scrollView = $famous.find('fa-scroll-view')[0].renderNode;
var surface = $famous.find('fa-surface')[0].renderNode;

// We are testing the widget event pipeline, not the rendering behavior of the widget.
// Emitting a mock mousewheel event on the surface should affect the Scrollview's private _touchCount.
expect(scrollView._touchCount).toBe(0);
surface.eventHandler.emit('mousewheel', common.mockEvent({count: 1}));
expect(scrollView._touchCount).toBe(1);

common.destroyApp(app);
});

it('should work with ng-repeated views', function() {
var app = common.createApp(
'<fa-scroll-view fa-pipe-from="eventHandler">' +
'<fa-view ng-repeat="view in views">' +
'<fa-surface fa-pipe-to="eventHandler" fa-size="[undefined, 100]"></fa-surface>' +
'</fa-view>' +
'</fa-scroll-view>'
);

$scope.eventHandler = eventHandler;
$scope.views = [0, 1];
$scope.$apply();

var scrollView = $famous.find('fa-scroll-view')[0].renderNode;

// The $timeout promise resolves view sequencing
expect(scrollView._node).toBeNull();
$timeout.flush();
expect(scrollView._node.index).toBe(0);

common.destroyApp(app);
});

it('should allow specification of a start index with fa-start-index', function() {
var app = common.createApp(
'<fa-scroll-view fa-pipe-from="eventHandler" fa-start-index="1">' +
'<fa-view ng-repeat="view in views">' +
'<fa-surface fa-pipe-to="eventHandler" fa-size="[undefined, 100]"></fa-surface>' +
'</fa-view>' +
'</fa-scroll-view>'
);

$scope.eventHandler = eventHandler;
$scope.views = [0, 1];
$scope.$apply();

$timeout.flush();

var scrollView = $famous.find('fa-scroll-view')[0].renderNode;
expect(scrollView._node.index).toBe(1);
common.destroyApp(app);
});

it('should unregister children when their scopes are destroyed', function() {
var app = common.createApp(
'<fa-scroll-view fa-pipe-from="eventHandler" fa-start-index="1">' +
'<fa-view ng-repeat="view in views">' +
'<fa-surface fa-pipe-to="eventHandler" fa-size="[undefined, 100]"></fa-surface>' +
'</fa-view>' +
'</fa-scroll-view>'
);

$scope.eventHandler = eventHandler;
$scope.views = [0, 1, 2];
$scope.$apply();

$timeout.flush();

var scrollView = $famous.find('fa-scroll-view')[0].renderNode;

expect(scrollView._node._.array.length).toBe(3);

// Pop out the current index
$scope.views.splice(1, 1);
$scope.$apply();

$timeout.flush();

expect(scrollView._node._.array.length).toBe(2);

common.destroyApp(app);
});
});

0 comments on commit 6ab3c41

Please # to comment.