arpho

Untitled

Feb 10th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. 'use strict';
  2.  
  3. describe('Controller: MainCtrl', function () {
  4.  
  5. // load the controller's module
  6. beforeEach(module('mongoBalanceApp'));
  7.  
  8. var MainCtrl,
  9. scope,
  10. $httpBackend;
  11.  
  12. // Initialize the controller and a mock scope
  13. beforeEach(inject(function (_$httpBackend_, $controller, $rootScope) {
  14. $httpBackend = _$httpBackend_;
  15. $httpBackend.expectGET('/api/purchase').respond([{
  16. "_id": "52aeb5e016942648d8a0a974",
  17. "info": "item di test",
  18. "item": "test",
  19. "payment": "test payment",
  20. "price": 0,
  21. "category": [
  22. "test category"
  23. ],
  24. "data": "2013-12-16T08:12:16.269Z"
  25. },
  26. {
  27. "payment": "test payment",
  28. "price": 0,
  29. "info": "no note",
  30. "item": "test form",
  31. "_id": "52af0dafbc61a84c49000006",
  32. "__v": 0,
  33. "category": [
  34. "test category"
  35. ],
  36. "data": "2013-12-16T14:26:55.824Z"
  37. },
  38. {
  39. "payment": "visa",
  40. "price": 9.58,
  41. "item": "spesa punto simply",
  42. "_id": "52b2ff4692a450f313000006",
  43. "__v": 0,
  44. "category": [
  45. "alimenti"
  46. ],
  47. "data": "2013-12-19T14:14:30.000Z"
  48. },
  49.  
  50. {
  51. "payment": "test payment",
  52. "price": 0,
  53. "info": "i controller sono separati",
  54. "item": "break test",
  55. "_id": "52b3ffe18b0662d114000006",
  56. "__v": 0,
  57. "category": [
  58. "test category"
  59. ],
  60. "data": "2013-12-20T08:29:21.173Z"
  61. },
  62. {
  63. "payment": "visa",
  64. "price": 6.66,
  65. "info": "per la festa di natale della scuola",
  66. "item": "torta naturasì",
  67. "_id": "52b5f1db11bf8b4a31000008",
  68. "__v": 0,
  69. "category": [
  70. "alimenti",
  71. "gnosis"
  72. ],
  73. "data": "2013-12-21T19:54:03.721Z"
  74. } ])
  75. scope = $rootScope.$new();
  76. // creo il controller
  77. MainCtrl = $controller('MainCtrl', {
  78. $scope: scope
  79. });
  80. }));
  81. it('should calculate the total for every category',function(){
  82. expect(scope.total4categories).toBeUndefined();
  83. $httpBackend.flush();
  84. var total4categories = {'alimenti':16.24,'test category':0,gnosis:6.66};
  85. expect(scope.total4categories).toEqual(total4categories);
  86. })
  87. it('calculate total ', function() {
  88. // scope.Payment = "test payment";
  89. $httpBackend.flush();
  90. expect(Math.round(scope.Partial*100)/100).toEqual(16.24);
  91. })
  92. it('calculate total for payment test payment', function() {
  93. scope.Payment = "test payment";
  94. $httpBackend.flush();
  95. expect(Math.round(scope.Partial*100)/100).toEqual(0);
  96. })
  97. it('calculate total for payment visa', function() {
  98. scope.Payment = "visa";
  99. $httpBackend.flush();
  100. expect(Math.round(scope.Partial*100)/100).toEqual(16.24);
  101. })
  102. it('calculate total for payment visa for gnosis', function() {
  103. scope.Payment = "visa";
  104. scope.Category = 'gnosis';
  105. $httpBackend.flush();
  106. expect(Math.round(scope.Partial*100)/100).toEqual(6.66);
  107. })
  108. xit('should attach a list of awesomeThings to the scope', function () {
  109. expect(scope.awesomeThings).toBeUndefined();
  110. $httpBackend.flush();
  111. expect(scope.awesomeThings.length).toBe(4);
  112. });
  113. it('should attach a list of purchases to the scope',function () {
  114. expect(scope.purchases).toBeUndefined();
  115. $httpBackend.flush();
  116. expect(scope.purchases.length).toBe(5);
  117. });
  118. });
  119.  
  120. xdescribe("A suite is just a function", function() {
  121. var a;
  122.  
  123. it("and so is a spec", function() {
  124. a = true;
  125.  
  126. expect(a).toBe(true);
  127. });
  128. });
Advertisement
Add Comment
Please, Sign In to add comment