You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lu-busy-business.spec.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * Created by robin on 12/11/16.
  3. */
  4. describe('lu-promise factory', function() {
  5. var luBusyBusiness;
  6. // Before each test load our api.users module
  7. beforeEach(angular.mock.module('luticate2Utils'));
  8. // Before each test set our injected Users factory (_Users_) to our local Users variable
  9. beforeEach(inject(function(_luBusyBusiness_) {
  10. luBusyBusiness = _luBusyBusiness_;
  11. }));
  12. it('should init a simple promise', function()
  13. {
  14. var p = luBusyBusiness.newPromise('my-id', 'all-groups', 'loader-groups', 'error-groups');
  15. luBusyBusiness.initPromise(p);
  16. expect(Object.keys(luBusyBusiness.promises).length).toEqual(1);
  17. var d = luBusyBusiness.promises['my-id'];
  18. expect(d).not.toBe(null);
  19. expect(d).not.toBe(undefined);
  20. expect(d.loaders).toEqual(['all-groups', 'loader-groups']);
  21. expect(d.errors).toEqual(['all-groups', 'error-groups']);
  22. expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
  23. expect(d.id).toBe('my-id');
  24. expect(Object.keys(luBusyBusiness.errors).length).toEqual(2);
  25. expect(luBusyBusiness.errors['all-groups'].length).toEqual(1);
  26. expect(luBusyBusiness.errors['all-groups'][0]['id']).toEqual('my-id');
  27. expect(luBusyBusiness.errors['error-groups'].length).toEqual(1);
  28. expect(luBusyBusiness.errors['error-groups'][0]['id']).toEqual('my-id');
  29. expect(Object.keys(luBusyBusiness.loaders).length).toEqual(2);
  30. expect(luBusyBusiness.loaders['all-groups'].length).toEqual(1);
  31. expect(luBusyBusiness.loaders['all-groups'][0]['id']).toEqual('my-id');
  32. expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
  33. expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
  34. });
  35. it('should init a more complex promise 1', function()
  36. {
  37. var p = luBusyBusiness.newPromise('my-id', ['all-groups', 'another-group'], 'loader-groups');
  38. luBusyBusiness.initPromise(p);
  39. expect(Object.keys(luBusyBusiness.promises).length).toEqual(1);
  40. var d = luBusyBusiness.promises['my-id'];
  41. expect(d).not.toBe(null);
  42. expect(d).not.toBe(undefined);
  43. expect(d.loaders).toEqual(['all-groups', 'another-group', 'loader-groups']);
  44. expect(d.errors).toEqual(['all-groups', 'another-group']);
  45. expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
  46. expect(d.id).toBe('my-id');
  47. expect(Object.keys(luBusyBusiness.errors).length).toEqual(2);
  48. expect(luBusyBusiness.errors['all-groups'].length).toEqual(1);
  49. expect(luBusyBusiness.errors['all-groups'][0]['id']).toEqual('my-id');
  50. expect(luBusyBusiness.errors['another-group'].length).toEqual(1);
  51. expect(luBusyBusiness.errors['another-group'][0]['id']).toEqual('my-id');
  52. expect(Object.keys(luBusyBusiness.loaders).length).toEqual(3);
  53. expect(luBusyBusiness.loaders['all-groups'].length).toEqual(1);
  54. expect(luBusyBusiness.loaders['all-groups'][0]['id']).toEqual('my-id');
  55. expect(luBusyBusiness.loaders['another-group'].length).toEqual(1);
  56. expect(luBusyBusiness.loaders['another-group'][0]['id']).toEqual('my-id');
  57. expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
  58. expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
  59. });
  60. it('should init a more complex promise 2', function()
  61. {
  62. var p = luBusyBusiness.newPromise('my-id', null, 'loader-groups');
  63. luBusyBusiness.initPromise(p);
  64. expect(Object.keys(luBusyBusiness.promises).length).toEqual(1);
  65. var d = luBusyBusiness.promises['my-id'];
  66. expect(d).not.toBe(null);
  67. expect(d).not.toBe(undefined);
  68. expect(d.loaders).toEqual(['loader-groups']);
  69. expect(d.errors).toEqual([]);
  70. expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
  71. expect(d.id).toBe('my-id');
  72. expect(Object.keys(luBusyBusiness.errors).length).toEqual(0);
  73. expect(Object.keys(luBusyBusiness.loaders).length).toEqual(1);
  74. expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
  75. expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
  76. });
  77. it('should init multiple more complex promise 1', function()
  78. {
  79. var p1 = luBusyBusiness.newPromise('my-id', ['all-groups', 'another-group'], 'loader-groups');
  80. luBusyBusiness.initPromise(p1);
  81. var p2 = luBusyBusiness.newPromise('my-id2', ['all-groups', 'another-group'], null, 'an-error-group');
  82. luBusyBusiness.initPromise(p2);
  83. expect(Object.keys(luBusyBusiness.promises).length).toEqual(2);
  84. var d = luBusyBusiness.promises['my-id'];
  85. expect(d).not.toBe(null);
  86. expect(d).not.toBe(undefined);
  87. expect(d.loaders).toEqual(['all-groups', 'another-group', 'loader-groups']);
  88. expect(d.errors).toEqual(['all-groups', 'another-group']);
  89. expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
  90. expect(d.id).toBe('my-id');
  91. d = luBusyBusiness.promises['my-id2'];
  92. expect(d).not.toBe(null);
  93. expect(d).not.toBe(undefined);
  94. expect(d.loaders).toEqual(['all-groups', 'another-group']);
  95. expect(d.errors).toEqual(['all-groups', 'another-group', 'an-error-group']);
  96. expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
  97. expect(d.id).toBe('my-id2');
  98. expect(Object.keys(luBusyBusiness.errors).length).toEqual(3);
  99. expect(luBusyBusiness.errors['all-groups'].length).toEqual(2);
  100. expect(luBusyBusiness.errors['all-groups'][0]['id']).toEqual('my-id');
  101. expect(luBusyBusiness.errors['all-groups'][1]['id']).toEqual('my-id2');
  102. expect(luBusyBusiness.errors['another-group'].length).toEqual(2);
  103. expect(luBusyBusiness.errors['another-group'][0]['id']).toEqual('my-id');
  104. expect(luBusyBusiness.errors['another-group'][1]['id']).toEqual('my-id2');
  105. expect(luBusyBusiness.errors['an-error-group'].length).toEqual(1);
  106. expect(luBusyBusiness.errors['an-error-group'][0]['id']).toEqual('my-id2');
  107. expect(Object.keys(luBusyBusiness.loaders).length).toEqual(3);
  108. expect(luBusyBusiness.loaders['all-groups'].length).toEqual(2);
  109. expect(luBusyBusiness.loaders['all-groups'][0]['id']).toEqual('my-id');
  110. expect(luBusyBusiness.loaders['all-groups'][1]['id']).toEqual('my-id2');
  111. expect(luBusyBusiness.loaders['another-group'].length).toEqual(2);
  112. expect(luBusyBusiness.loaders['another-group'][0]['id']).toEqual('my-id');
  113. expect(luBusyBusiness.loaders['another-group'][1]['id']).toEqual('my-id2');
  114. expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
  115. expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
  116. });
  117. });