Skip to content

Commit

Permalink
Fixed the on-demand loading of animation and added necessary unit tes…
Browse files Browse the repository at this point in the history
…t. This closes #31
  • Loading branch information
Marcos Lin committed May 28, 2014
1 parent 5d6a007 commit eae2e56
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 14 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ Here is the list of methods supported by `app.register`:
* `.value`
* `.directive`
* `.filter`
* `.animation` **

** `.animation` is not covered in unit test for now
* `.animation`

### 3rd Party AngularJS Modules

Expand Down
6 changes: 4 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"name": "angularAMD",
"version": "0.1.0",
"dependencies": {
"angular": "~1.2.16",
"angular-route": "~1.2.16",
"angular": "1.2.16",
"angular-route": "1.2.16",
"angular-animate": "1.2.16",
"angular-mocks": "1.2.16",
"angular-ui-bootstrap-bower": "~0.6.0",
"requirejs": "~2.1.9",
"requirejs-plugins": "~1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/angularAMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ define(function () {
service: provide.service,
constant: provide.constant,
value: provide.value,
animation: animateProvider.register
animation: angular.bind(animateProvider, animateProvider.register)
};

}]
Expand Down
2 changes: 1 addition & 1 deletion test/conf/karma.unit.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function (config) {
// list of files / patterns to load in the browser
files: [
{pattern: 'bower_components/angular/*.js', watched: false, included: false},
{pattern: 'bower_components/**/*.js', watched: false, included: false},
{pattern: 'build/*.js', watched: true, included: false},
{pattern: 'src/*.js', watched: true, included: false},
{pattern: 'test/unit/*.spec.js', watched: true, included: false},
Expand Down
7 changes: 4 additions & 3 deletions test/unit/lib/app.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/*jslint browser: true, devel: true, node: true, vars: true, nomen: true */
/*globals define, angular */

define(['angularAMD'], function (angularAMD) {
define(['angularAMD', 'angular-animate'], function (angularAMD) {
'use strict';

/**
* BOOTSTRAP ANGULAR
* Replicating what would normally take place in app.js
*/
var app_name = "unitest-app",
app = angular.module(app_name, []);
app = angular.module(app_name, ['ngAnimate']);

// Add property for unit test
app.__appname = app_name;
app.__origAngular = window.angular;


/*
var elem = document.createElement('div');
var elem = document.body;
angularAMD.bootstrap(app, undefined, elem);
*/
angularAMD.bootstrap(app);
Expand Down
4 changes: 4 additions & 0 deletions test/unit/lib/main.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require.config({
// alias libraries paths
paths: {
'angular': 'bower_components/angular/angular',
'angular-animate': 'bower_components/angular-animate/angular-animate',
'angular-mocks': 'bower_components/angular-mocks/angular-mocks',
'angularAMD': '{{{angularAMD-js-file}}}',
'ngload': '{{{ngload-js-file}}}',
Expand All @@ -20,6 +21,9 @@ require.config({

shim: {
'angularAMD': ['angular'],
'angular-animate': ['angular'],
'angular-mocks': ['angular'],
/*
'services' in this case is a regular angular.js module and therefore non-requirejs module so
must be defined in shim. This is critical as 'services' depends on processing in 'app' to
Expand Down
18 changes: 18 additions & 0 deletions test/unit/lib/regServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ define(['app', 'angularAMD'], function(app, angularAMD) {
};
});

// Create Animation
services.animation('.service-reg-animation', function ($log, $interval) {
return {
addClass : function(element, className, done) {
if ( className === "custom-hide") {
element.css('opacity',0);
done();
}
},
removeClass : function(element, className, done) {
if ( className === "custom-hide") {
element.css('opacity',1);
done();
}
}
}
});

// Return the result in a factory
services.factory('UtestRegServiceResult', function () {
return utest_reg_result;
Expand Down
32 changes: 28 additions & 4 deletions test/unit/regServices.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
/**
* Test to ensure that services can be created using app.register method.
*/
define(['regServices','angularAMD'], function (app, angularAMD) {
define(['regServices','angularAMD', 'angular-mocks'], function (app, angularAMD) {
'use strict';
var inject = angularAMD.inject;
describe('Utest Registered Services', function () {
//console.log("Running serviceSpec.js");
var results = app.__utest_regserv_result,
inject = angularAMD.inject;
var results = app.__utest_regserv_result;

it(".reg_constant check.", function () {
inject(function (reg_constant_name) {
Expand Down Expand Up @@ -55,7 +55,31 @@ define(['regServices','angularAMD'], function (app, angularAMD) {
expect(ufilter("hello")).toBe("hello " + results.reg_filter_name);
});
});

});

describe("Utest Registered Animation", function () {
var scope, animate, elem;

beforeEach(function () {
module("ngAnimateMock");
inject(function ($rootScope, $compile, $rootElement, $animate) {
var html_text = "<div ng-class='AnimationClass' class='service-reg-animation'></div>";
scope = $rootScope;
animate = $animate;
elem = $compile(html_text)(scope);
$rootElement.append(elem);
});
});

it(".animation check.", function () {
animate.addClass(elem, "custom-hide");
scope.$digest();
expect(elem.css("opacity")).toBe("0");

animate.removeClass(elem, "custom-hide");
scope.$digest();
expect(elem.css("opacity")).toBe("1");
});
});

});

0 comments on commit eae2e56

Please sign in to comment.