Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

specs for favorites services

  • Loading branch information...
commit b76b3166a0f22e04192ba3308cec1d4ecb1b8879 1 parent bc10412
@IgorMinar authored
Showing with 48 additions and 1 deletion.
  1. +1 −1  app/js/services.js
  2. +47 −0 test/unit/servicesSpec.js
View
2  app/js/services.js
@@ -19,7 +19,7 @@ angular.service('phoneCatApp', function($route, $location, $resource, $window) {
angular.service('favorites', function($cookieStore){
return {
has: function(phoneId){
- return ($cookieStore.get('favorites') || {})[phoneId];
+ return !!($cookieStore.get('favorites') || {})[phoneId];
},
add:function(phoneId) {
var favorites = $cookieStore.get('favorites') || {};
View
47 test/unit/servicesSpec.js
@@ -0,0 +1,47 @@
+describe('favorites', function(){
+ var scope, favorites, $cookieStore;
+
+ beforeEach(function(){
+ scope = angular.scope();
+ $cookieStore = scope.$inject('$cookieStore');
+ favorites = scope.$inject('favorites');
+ });
+
+
+ describe('add', function() {
+
+ it('should add phones to favorites and store them in cookie store', function() {
+ expect($cookieStore.get('favorites')).toBeUndefined();
+ favorites.add('abc123');
+ expect($cookieStore.get('favorites')).toEqual({'abc123':true});
+ });
+
+ });
+
+
+ describe('remove', function() {
+
+ it('should remove phones from favorites', function() {
+ favorites.add('abc123');
+ expect($cookieStore.get('favorites')).toEqual({"abc123":true});
+
+ favorites.remove('abc123');
+ expect($cookieStore.get('favorites')).toEqual({});
+ });
+
+ });
+
+
+ describe('has', function() {
+
+ it('should return true if an item is favorite', function() {
+ expect(favorites.has('abc123')).toBe(false);
+
+ favorites.add('abc123');
+
+ expect(favorites.has('abc123')).toBe(true);
+ });
+
+ });
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.