diff --git a/README.md b/README.md index 405d0d4..6345b48 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,61 @@ [![Build Status](https://travis-ci.org/thisissoon/angular-velocity.svg?branch=develop)](https://travis-ci.org/thisissoon/angular-velocity) [![Coverage Status](https://coveralls.io/repos/thisissoon/angular-velocity/badge.svg)](https://coveralls.io/r/thisissoon/angular-velocity) +These velocity directives configure velocity.js keyframe animations on an element. + + +## Install +``` +bower install angular-velocity-animate +bower install velocity +``` + +## Basic Usage + +```html + + +
+ ... +
+ +``` +The `data-keyframes` attribute takes an array of velocity.js animation keyframes. See the [Velocity Docs](http://julian.com/research/velocity/#propertiesMap) for available properties and options. + + +## Animation Groups + +The `sn-velocity-group` directive can be used to animate a number of elements together. + +```html + + + +
+
+
+ +``` +The `data-keyframes` attribute of `sn-velocity-group` takes an object of element identifiers. Each key in the object should hold an array of velocity.js animation keyframes as per the `sn-velocity` directive. + +```json + +{ + "#elem1": [{ + "properties": { "opacity": "1" }, + "options": { "duration": "1000", "loop": true } + }], + "#elem2": [{ + "properties": { "left": "+=100" }, + "options": { "duration": "1000" } + },{ + "properties": { "opacity": "-=100" }, + "options": { "duration": "1000" } + }] +} + +``` + This project structure is based on the [angular-seed](https://github.com/angular/angular-seed) application skeleton for a typical [AngularJS](http://angularjs.org/) web app. The project is preconfigured to install the Angular framework and a bunch of development and testing tools for instant web development gratification. @@ -117,34 +172,15 @@ The build files will then be in the `dist/` directory. app/ --> all of the files to be used in production components/ --> all of our javascript libraries (installed using bower) - css/ --> css files - app.css --> default stylesheet (generated using less) - img/ --> image files - less/ --> less folder - default/ --> styling appied to all screen sizes (e.g. fonts, colors etc..) - core/ --> core styling applied to all screen sizes - modules/ --> module styling applied to all screen sizes - large/ --> styling appied to large screen screen sizes (overrides styling in default folder) - core/ --> core styling applied to large screen screen sizes - modules/ --> module styling applied to large screen screen sizes - tablet/ --> styling appied to tablet screen sizes (overrides styling in default folder) - core/ --> core styling applied to tablet screens - modules/ --> module styling applied to tablet screens - mobile/ --> styling appied to mobile screen sizes (overrides styling in default folder) - core/ --> core styling applied to mobile screens - modules/ --> module styling applied to mobile screens index.html --> app layout file (the main html template file of the app) js/ --> javascript files {app}/ --> angular module javascript files {app}.js --> angular module initialisation config.js --> angular module config controllers/ --> controllers - {view}Ctrl.js + {view}Ctrl.js directives/ --> directives - {module}.js - partials/ --> angular view partials (partial html templates) - partial1.html - partial2.html + {module}.js modules/ --> static html files for building and testing styling and mark up {module}/ index.html diff --git a/app/index.html b/app/index.html index 0c51417..0c286be 100644 --- a/app/index.html +++ b/app/index.html @@ -1,34 +1,27 @@ - - + + - SOON_ AngularJS Template + SOON_ Velocity Directives - - - - - - - - - - + + + diff --git a/app/js/angular-velocity.js b/app/js/angular-velocity.js new file mode 100644 index 0000000..4a426ad --- /dev/null +++ b/app/js/angular-velocity.js @@ -0,0 +1,11 @@ +"use strict"; +/** + * Angular wrapper for velocityjs animation library + * @requires velocityjs {@link https://github.com/julianshapiro/velocity} + * @module sn.velocity + * @author SOON_ + */ +angular.module("sn.velocity", [ + "sn.velocity.snVelocity", + "sn.velocity.snVelocityGroup" +]); diff --git a/app/js/directives/velocity-group.js b/app/js/directives/velocity-group.js new file mode 100644 index 0000000..b299278 --- /dev/null +++ b/app/js/directives/velocity-group.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * @author SOON_ + * @module sn.velocity.snVelocityGroup + * @class snVelocityGroup + * @example + */ +angular.module("sn.velocity.snVelocityGroup", [ + "sn.velocity.snVelocity" +]) + +.directive("snVelocityGroup",[ + "$compile", + "$rootScope", + /** + * @constructor + * + * @param {Service} $compile angular template compiler + * @param {Object} $rootScope + */ + function($compile, $rootScope) { + return { + restrict: "E", + scope: { + "keyframes": "=" + }, + link: function($scope, $element){ + + angular.forEach($scope.keyframes, function(keyframes, key){ + var animateElement = angular.element($element[0].querySelector(key)); + var scope = $rootScope.$new(); + scope.keyframes = keyframes; + + animateElement.attr("sn-velocity", ""); + animateElement.attr("data-keyframes", "keyframes"); + + $compile(animateElement)(scope); + }); + + } + }; + } +]); diff --git a/app/js/directives/velocity.js b/app/js/directives/velocity.js new file mode 100644 index 0000000..91e88e7 --- /dev/null +++ b/app/js/directives/velocity.js @@ -0,0 +1,29 @@ +"use strict"; +/** + * Angular wrapper for velocityjs + * @author SOON_ + * @module sn.velocity.snVelocity + * @class snVelocity + * @example + */ +angular.module("sn.velocity.snVelocity", []).directive("snVelocity",[ + "$window", + /** + * @constructor + */ + function($window) { + return { + restrict: "A", + scope: { + "keyframes": "=" + }, + link: function($scope, $element){ + + angular.forEach($scope.keyframes, function(value){ + $window.Velocity($element, value.properties, value.options); + }); + + } + }; + } +]); diff --git a/app/js/soon-example/app.js b/app/js/soon-example/app.js deleted file mode 100644 index 86fc491..0000000 --- a/app/js/soon-example/app.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -/** - * @module sn.example - * @main sn.example - * @author SOON_ - * @requires ngRoute {@link https://docs.angularjs.org/api/ngRoute} - */ -angular.module("sn.example", ["ngRoute"]); diff --git a/app/js/soon-example/config.js b/app/js/soon-example/config.js deleted file mode 100644 index 521d802..0000000 --- a/app/js/soon-example/config.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; -/** - * Configuration for sn.example dependencies are set here. - * @module sn.example - * @author SOON_ - */ -angular.module("sn.example").config([ - "$routeProvider", - "$locationProvider", - /** - * @constructor - * @param {Service} $routeProvider - * @param {Service} $locationProvider - */ - function ($routeProvider, $locationProvider) { - - $locationProvider.html5Mode(true).hashPrefix = "!"; - - $routeProvider - .when("/", { - templateUrl: "partials/search.html", - controller: "SearchCtrl" - }) - .when("/results", { - templateUrl: "partials/results.html", - controller: "ResultsCtrl" - }) - .otherwise({ - redirectTo: "/" - }); - - } -]); diff --git a/app/js/soon-example/controllers/ResultsCtrl.js b/app/js/soon-example/controllers/ResultsCtrl.js deleted file mode 100644 index 27ac4ec..0000000 --- a/app/js/soon-example/controllers/ResultsCtrl.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; -/** - * Controller to display results of search in sn.example. - * @class ResultsCtrl - * @module sn.example - * @author SOON_ - */ -angular.module("sn.example").controller("ResultsCtrl", [ - "$scope", - "$rootScope", - /** - * @constructor - * @param {Object} $scope - * @param {Service} $rootScope - */ - function ($scope, $rootScope) { - - /** - * The result from the search query - * @property results - * @type {Array} - */ - $scope.results = $rootScope.results; - - } - -]); diff --git a/app/js/soon-example/controllers/SearchCtrl.js b/app/js/soon-example/controllers/SearchCtrl.js deleted file mode 100644 index 32d680a..0000000 --- a/app/js/soon-example/controllers/SearchCtrl.js +++ /dev/null @@ -1,41 +0,0 @@ -"use strict"; -/** - * Controller to perform search in sn.example. - * @class SearchCtrl - * @module sn.example - * @author SOON_ - */ -angular.module("sn.example").controller("SearchCtrl", [ - "$scope", - "$rootScope", - "$http", - "$location", - /** - * @constructor - * @param {Object} $scope - * @param {Service} $rootScope - * @param {Service} $http - * @param {Service} $location - */ - function ($scope, $rootScope, $http, $location) { - - /** - * Search locations based on val - * @method getLocation - * @param {String} val location to query - */ - $scope.getLocation = function getLocation(val){ - $http.get("http://maps.googleapis.com/maps/api/geocode/json", { - params: { - address: val, - sensor: false - } - }).then(function (response){ - $rootScope.results = response.data.results; - $location.path("/results"); - }); - }; - - } - -]); diff --git a/scripts.json b/scripts.json index 06cd690..58580d9 100644 --- a/scripts.json +++ b/scripts.json @@ -4,9 +4,8 @@ "app/components/angular-route/angular-route.js" ], "application": [ - "app/js/soon-example/app.js", - "app/js/soon-example/config.js", - "app/js/soon-example/controllers/SearchCtrl.js", - "app/js/soon-example/controllers/ResultsCtrl.js" + "app/js/angular-velocity.js", + "app/js/directives/velocity-group.js", + "app/js/directives/velocity.js" ] } diff --git a/tests/e2e/app.js b/tests/e2e/app.js index 8ec02c6..98bc87d 100644 --- a/tests/e2e/app.js +++ b/tests/e2e/app.js @@ -3,16 +3,15 @@ * This module runs e2e test by setting up a module to make our * backend assertions e.g. mock the responses from our api before * lauching our actual application. - * @main sn.example.e2e - * @module sn.example.e2e + * @main sn.velocity.e2e + * @module sn.velocity.e2e * @author SOON_ */ -angular.module("sn.example.e2e", ["sn.example", "ngMockE2E"]) +angular.module("sn.velocity.e2e", ["sn.velocity", "ngMockE2E"]) .run([ "$httpBackend", function ($httpBackend) { - $httpBackend.whenGET(/.*\/maps\/api\/geocode\/json.*/).respond({ "results" : [ { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "United Kingdom", "short_name" : "GB", "types" : [ "country", "political" ] } ], "formatted_address" : "London, UK", "geometry" : { "bounds" : { "northeast" : { "lat" : 51.6723432, "lng" : 0.148271 }, "southwest" : { "lat" : 51.38494009999999, "lng" : -0.3514683 } }, "location" : { "lat" : 51.5073509, "lng" : -0.1277583 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 51.6723432, "lng" : 0.148271 }, "southwest" : { "lat" : 51.38494009999999, "lng" : -0.3514683 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "Middlesex County", "short_name" : "Middlesex County", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Ontario", "short_name" : "ON", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Canada", "short_name" : "CA", "types" : [ "country", "political" ] } ], "formatted_address" : "London, ON, Canada", "geometry" : { "bounds" : { "northeast" : { "lat" : 43.073245, "lng" : -81.1063879 }, "southwest" : { "lat" : 42.824517, "lng" : -81.390852 } }, "location" : { "lat" : 42.9869502, "lng" : -81.243177 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 43.073245, "lng" : -81.1063879 }, "southwest" : { "lat" : 42.824517, "lng" : -81.390852 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "Laurel County", "short_name" : "Laurel County", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Kentucky", "short_name" : "KY", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] } ], "formatted_address" : "London, KY, USA", "geometry" : { "bounds" : { "northeast" : { "lat" : 37.1522599, "lng" : -84.03595709999999 }, "southwest" : { "lat" : 37.0797589, "lng" : -84.126262 } }, "location" : { "lat" : 37.1289771, "lng" : -84.08326459999999 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 37.1522599, "lng" : -84.03595709999999 }, "southwest" : { "lat" : 37.0797589, "lng" : -84.126262 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "Madison County", "short_name" : "Madison County", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Ohio", "short_name" : "OH", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] }, { "long_name" : "43140", "short_name" : "43140", "types" : [ "postal_code" ] } ], "formatted_address" : "London, OH 43140, USA", "geometry" : { "bounds" : { "northeast" : { "lat" : 39.921786, "lng" : -83.3899969 }, "southwest" : { "lat" : 39.85928, "lng" : -83.47892299999999 } }, "location" : { "lat" : 39.8864493, "lng" : -83.4482529 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 39.921786, "lng" : -83.3899969 }, "southwest" : { "lat" : 39.85928, "lng" : -83.47892299999999 } } }, "types" : [ "locality", "political" ] } ], "status" : "OK" }); $httpBackend.whenGET(/partials\/.*/).passThrough(); } diff --git a/tests/e2e/specs/scenarios.js b/tests/e2e/specs/scenarios.js index 53d5328..6fad871 100644 --- a/tests/e2e/specs/scenarios.js +++ b/tests/e2e/specs/scenarios.js @@ -2,70 +2,8 @@ /* https://github.com/angular/protractor/blob/master/docs/getting-started.md */ -describe("sn.example", function() { +describe("sn.velocity", function() { - describe("search", function() { - beforeEach(function(){ - browser.manage().deleteAllCookies(); - browser.get("http://127.0.0.1:8000/"); - browser.waitForAngular(); - browser.driver.sleep(2000); - }); - - it("should automatically redirect to / when location hash/fragment is empty", function() { - expect(browser.getLocationAbsUrl()).toMatch("/"); - }); - - it("should render home partial when user navigates to /", function() { - expect(element.all(by.css("ng-view h1")).first().getText()).toContain("Search"); - }); - - it("should search for location", function() { - element(by.model("location")).sendKeys("London"); - element(by.id("submit")).click(); - - browser.driver.sleep(5000); - - browser.driver.wait(function() { - return browser.driver.getCurrentUrl().then(function (url) { - return /results/.test(url); - }); - }); - expect(browser.getLocationAbsUrl()).toMatch("/results"); - expect(element.all(by.repeater("result in results")).count()).toEqual(4); - }); - - }); - - - describe("results", function() { - - beforeEach(function(){ - browser.get("http://127.0.0.1:8000/results"); - browser.waitForAngular(); - browser.driver.sleep(2000); - }); - - it("should render results page view", function() { - expect(element.all(by.css("ng-view h1")).first().getText()).toContain("Results"); - expect(element(by.css(".bg-info")).getText()).toContain("No search results"); - - }); - - it("should go back to search page view", function() { - element(by.css("a.home")).click(); - - browser.driver.wait(function() { - return browser.driver.getCurrentUrl().then(function (url) { - return /\//.test(url); - }); - }); - - expect(browser.getLocationAbsUrl()).toMatch("/"); - - }); - - }); }); diff --git a/tests/unit/directives/velocity-group.js b/tests/unit/directives/velocity-group.js new file mode 100644 index 0000000..6a5e6fe --- /dev/null +++ b/tests/unit/directives/velocity-group.js @@ -0,0 +1,47 @@ +"use strict"; + +describe("directive: snVelocityGroup", function() { + var element, scope, isolatedScope, _window, spy, keyframes; + + beforeEach(module("sn.velocity")); + + beforeEach(inject(function ($rootScope, $compile, $injector) { + scope = $rootScope.$new(); + + _window = $injector.get("$window"); + + _window.Velocity = function(){}; + + element = + "" + + "
" + + "
"; + + element = $compile(element)(scope); + scope.$digest(); + + isolatedScope = element.isolateScope(); + + })); + + it("should attach directive options to scope", function (){ + expect(isolatedScope.keyframes).toEqual({ '#elem1': [{ 'properties': { 'opacity': '1' }, 'options': { 'duration': '1000' } }] }); + }); + + it("should attach keyframes to scope of child", function (){ + + var animateElementScope = angular.element(element).find("div").scope(); + + expect(animateElementScope.keyframes).toEqual([{ properties: { opacity: '1' }, options: { duration: '1000' } }]); + }); + + it("should add attributes to child element", function (){ + + var animateElement = angular.element(element).find("div"); + + expect(animateElement.attr("sn-velocity")).toEqual(""); + expect(animateElement.attr("data-keyframes")).toEqual("keyframes"); + }); + +}); + diff --git a/tests/unit/directives/velocity.js b/tests/unit/directives/velocity.js new file mode 100644 index 0000000..4315480 --- /dev/null +++ b/tests/unit/directives/velocity.js @@ -0,0 +1,38 @@ +"use strict"; + +describe("directive: snVelocity", function() { + var element, scope, isolatedScope, _window, spy, keyframes; + + beforeEach(module("sn.velocity")); + + beforeEach(inject(function ($rootScope, $compile, $injector) { + scope = $rootScope.$new(); + + _window = $injector.get("$window"); + + _window.Velocity = function(){}; + spy = spyOn(_window, "Velocity"); + + element = + "
" + + "
" + + "
"; + + element = $compile(element)(scope); + scope.$digest(); + + isolatedScope = element.isolateScope(); + + })); + + it("should attach directive options to scope", function (){ + expect(isolatedScope.keyframes).toEqual([{ 'properties': { 'opacity': '1' }, 'options': { 'duration': '1000' } }]); + }); + + it("should initialise Velocity with keyframes", function (){ + expect(spy.calls.count()).toBe(1); + expect(spy).toHaveBeenCalledWith(element, { 'opacity': '1' }, { 'duration': '1000' }); + }); + +}); + diff --git a/tests/unit/soon-example/controllers/ResultsCtrl.js b/tests/unit/soon-example/controllers/ResultsCtrl.js deleted file mode 100644 index 46a9b0b..0000000 --- a/tests/unit/soon-example/controllers/ResultsCtrl.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -describe("ResultsCtrl", function (){ - - var _scope, _rootScope; - - beforeEach(function(){ - module("sn.example"); - }); - - beforeEach(inject(function ($rootScope, $controller) { - - _scope = $rootScope.$new(); - _rootScope = $rootScope; - _rootScope.results = ["123","456"]; - - $controller("ResultsCtrl", { - $scope: _scope, - $rootScope: _rootScope - }); - - })); - - it("should attach results to scope ", function (){ - expect(_scope.results).toContain("123"); - expect(_scope.results).toContain("456"); - }); - - -}); diff --git a/tests/unit/soon-example/controllers/SearchCtrl.js b/tests/unit/soon-example/controllers/SearchCtrl.js deleted file mode 100644 index 2e13212..0000000 --- a/tests/unit/soon-example/controllers/SearchCtrl.js +++ /dev/null @@ -1,44 +0,0 @@ -"use strict"; - -describe("SearchCtrl", function (){ - - var _scope, _rootScope, _http, _location, $httpBackend; - - beforeEach(function(){ - module("sn.example"); - }); - - beforeEach(inject(function ($injector, $rootScope, $controller) { - - _scope = $rootScope.$new(); - _rootScope = $rootScope; - _http = $injector.get("$http"); - _location = $injector.get("$location"); - _location.path = function(){} - - spyOn(_location, "path"); - - $httpBackend = $injector.get("$httpBackend"); - - $httpBackend.whenGET(/.*\/maps\/api\/geocode\/json.*/).respond({ "results" : [ { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "United Kingdom", "short_name" : "GB", "types" : [ "country", "political" ] } ], "formatted_address" : "London, UK", "geometry" : { "bounds" : { "northeast" : { "lat" : 51.6723432, "lng" : 0.148271 }, "southwest" : { "lat" : 51.38494009999999, "lng" : -0.3514683 } }, "location" : { "lat" : 51.5073509, "lng" : -0.1277583 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 51.6723432, "lng" : 0.148271 }, "southwest" : { "lat" : 51.38494009999999, "lng" : -0.3514683 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "Middlesex County", "short_name" : "Middlesex County", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Ontario", "short_name" : "ON", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Canada", "short_name" : "CA", "types" : [ "country", "political" ] } ], "formatted_address" : "London, ON, Canada", "geometry" : { "bounds" : { "northeast" : { "lat" : 43.073245, "lng" : -81.1063879 }, "southwest" : { "lat" : 42.824517, "lng" : -81.390852 } }, "location" : { "lat" : 42.9869502, "lng" : -81.243177 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 43.073245, "lng" : -81.1063879 }, "southwest" : { "lat" : 42.824517, "lng" : -81.390852 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "Laurel County", "short_name" : "Laurel County", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Kentucky", "short_name" : "KY", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] } ], "formatted_address" : "London, KY, USA", "geometry" : { "bounds" : { "northeast" : { "lat" : 37.1522599, "lng" : -84.03595709999999 }, "southwest" : { "lat" : 37.0797589, "lng" : -84.126262 } }, "location" : { "lat" : 37.1289771, "lng" : -84.08326459999999 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 37.1522599, "lng" : -84.03595709999999 }, "southwest" : { "lat" : 37.0797589, "lng" : -84.126262 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "Madison County", "short_name" : "Madison County", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Ohio", "short_name" : "OH", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] }, { "long_name" : "43140", "short_name" : "43140", "types" : [ "postal_code" ] } ], "formatted_address" : "London, OH 43140, USA", "geometry" : { "bounds" : { "northeast" : { "lat" : 39.921786, "lng" : -83.3899969 }, "southwest" : { "lat" : 39.85928, "lng" : -83.47892299999999 } }, "location" : { "lat" : 39.8864493, "lng" : -83.4482529 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 39.921786, "lng" : -83.3899969 }, "southwest" : { "lat" : 39.85928, "lng" : -83.47892299999999 } } }, "types" : [ "locality", "political" ] } ], "status" : "OK" }); - - $controller("SearchCtrl", { - $scope: _scope, - $rootScope: _rootScope, - $http: _http, - $location: _location - - }); - - })); - - it("should get locations search results", function (){ - _scope.getLocation("foo"); - $httpBackend.flush(); - expect(_rootScope.results.length).toBe(4); - expect(_rootScope.results[0]).toEqual({ "address_components": [ { "long_name": "London", "short_name": "London", "types": [ "locality", "political" ] }, { "long_name": "United Kingdom", "short_name": "GB", "types": [ "country", "political" ] } ], "formatted_address": "London, UK", "geometry": { "bounds": { "northeast": { "lat": 51.6723432, "lng": 0.148271 }, "southwest": { "lat": 51.38494009999999, "lng": -0.3514683 } }, "location": { "lat": 51.5073509, "lng": -0.1277583 }, "location_type": "APPROXIMATE", "viewport": { "northeast": { "lat": 51.6723432, "lng": 0.148271 }, "southwest": { "lat": 51.38494009999999, "lng": -0.3514683 } } }, "types": [ "locality", "political" ] }); - expect(_location.path).toHaveBeenCalledWith("/results"); - }); - - -});