Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. $scope.saveFailure = function (response) {
  2. var errs = [];
  3. response.data.forEach((entry) => errs.push("options." + entry.dataField));
  4. if (errs.length > 0) $scope.$emit('datafields:errors', errs);
  5.  
  6. $scope.gotoTop();
  7. $scope.processing = false;
  8. };
  9.  
  10. var mockFailureResponse;
  11.  
  12. beforeEach(function () {
  13. mockFailureResponse = {
  14. data: [],
  15. };
  16. });
  17.  
  18. it('saveFailure should set processing to false', function () {
  19. $scope.processing = true;
  20. $scope.saveFailure(mockFailureResponse);
  21. expect($scope.processing).toBe(false);
  22. });
  23. it('saveFailure should call goToTop()', function () {
  24. spyOn($scope, 'gotoTop');
  25. $scope.saveFailure(mockFailureResponse);
  26. expect($scope.gotoTop).toHaveBeenCalled();
  27. });
  28. it('saveFailure should emit datafield errors when present', function () {
  29. spyOn($scope, '$emit');
  30. mockFailureResponse = {
  31. data: [{dataField: "field"}],
  32. };
  33. $scope.saveFailure(mockFailureResponse);
  34. expect($scope.$emit).toHaveBeenCalledWith('datafields:errors', ['options.field']);
  35. });
  36. it('saveFailure should not emit datafield errors non are present', function () {
  37. spyOn($scope, '$emit');
  38. $scope.saveFailure(mockFailureResponse);
  39. expect($scope.$emit.calls.count()).toEqual(0);
  40. });
  41.  
  42. it('saveFailure should handle failed requests', function () {
  43. spyOn($scope, '$emit');
  44. let mockFailureResponse = {
  45. data: [],
  46. };
  47. $scope.saveFailure(mockFailureResponse);
  48. expect($scope.$emit.calls.count()).toEqual(0);
  49.  
  50. mockFailureResponse = {
  51. data: [{ dataField: "field" }],
  52. };
  53. $scope.saveFailure(mockFailureResponse);
  54. expect($scope.$emit).toHaveBeenCalledWith('datafields:errors', ['options.field']);
  55.  
  56. spyOn($scope, 'gotoTop');
  57. $scope.saveFailure(mockFailureResponse);
  58. expect($scope.gotoTop).toHaveBeenCalled();
  59.  
  60. $scope.processing = true;
  61. $scope.saveFailure(mockFailureResponse);
  62. expect($scope.processing).toBe(false);
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement