123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /**
- * Created by robin on 12/11/16.
- */
-
- describe('lu-promise factory', function() {
- var luBusyBusiness;
-
- // Before each test load our api.users module
- beforeEach(angular.mock.module('luticate2Utils'));
-
- // Before each test set our injected Users factory (_Users_) to our local Users variable
- beforeEach(inject(function(_luBusyBusiness_) {
- luBusyBusiness = _luBusyBusiness_;
- }));
-
- it('should init a simple promise', function()
- {
- var p = luBusyBusiness.newPromise('my-id', 'all-groups', 'loader-groups', 'error-groups');
- luBusyBusiness.initPromise(p);
- expect(Object.keys(luBusyBusiness.promises).length).toEqual(1);
-
- var d = luBusyBusiness.promises['my-id'];
- expect(d).not.toBe(null);
- expect(d).not.toBe(undefined);
- expect(d.loaders).toEqual(['all-groups', 'loader-groups']);
- expect(d.errors).toEqual(['all-groups', 'error-groups']);
- expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
- expect(d.id).toBe('my-id');
-
- expect(Object.keys(luBusyBusiness.errors).length).toEqual(2);
- expect(luBusyBusiness.errors['all-groups'].length).toEqual(1);
- expect(luBusyBusiness.errors['all-groups'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.errors['error-groups'].length).toEqual(1);
- expect(luBusyBusiness.errors['error-groups'][0]['id']).toEqual('my-id');
-
- expect(Object.keys(luBusyBusiness.loaders).length).toEqual(2);
- expect(luBusyBusiness.loaders['all-groups'].length).toEqual(1);
- expect(luBusyBusiness.loaders['all-groups'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
- expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
- });
-
- it('should init a more complex promise 1', function()
- {
- var p = luBusyBusiness.newPromise('my-id', ['all-groups', 'another-group'], 'loader-groups');
- luBusyBusiness.initPromise(p);
- expect(Object.keys(luBusyBusiness.promises).length).toEqual(1);
-
- var d = luBusyBusiness.promises['my-id'];
- expect(d).not.toBe(null);
- expect(d).not.toBe(undefined);
- expect(d.loaders).toEqual(['all-groups', 'another-group', 'loader-groups']);
- expect(d.errors).toEqual(['all-groups', 'another-group']);
- expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
- expect(d.id).toBe('my-id');
-
- expect(Object.keys(luBusyBusiness.errors).length).toEqual(2);
- expect(luBusyBusiness.errors['all-groups'].length).toEqual(1);
- expect(luBusyBusiness.errors['all-groups'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.errors['another-group'].length).toEqual(1);
- expect(luBusyBusiness.errors['another-group'][0]['id']).toEqual('my-id');
-
- expect(Object.keys(luBusyBusiness.loaders).length).toEqual(3);
- expect(luBusyBusiness.loaders['all-groups'].length).toEqual(1);
- expect(luBusyBusiness.loaders['all-groups'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.loaders['another-group'].length).toEqual(1);
- expect(luBusyBusiness.loaders['another-group'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
- expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
- });
-
- it('should init a more complex promise 2', function()
- {
- var p = luBusyBusiness.newPromise('my-id', null, 'loader-groups');
- luBusyBusiness.initPromise(p);
- expect(Object.keys(luBusyBusiness.promises).length).toEqual(1);
-
- var d = luBusyBusiness.promises['my-id'];
- expect(d).not.toBe(null);
- expect(d).not.toBe(undefined);
- expect(d.loaders).toEqual(['loader-groups']);
- expect(d.errors).toEqual([]);
- expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
- expect(d.id).toBe('my-id');
-
- expect(Object.keys(luBusyBusiness.errors).length).toEqual(0);
-
- expect(Object.keys(luBusyBusiness.loaders).length).toEqual(1);
- expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
- expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
- });
-
- it('should init multiple more complex promise 1', function()
- {
- var p1 = luBusyBusiness.newPromise('my-id', ['all-groups', 'another-group'], 'loader-groups');
- luBusyBusiness.initPromise(p1);
- var p2 = luBusyBusiness.newPromise('my-id2', ['all-groups', 'another-group'], null, 'an-error-group');
- luBusyBusiness.initPromise(p2);
- expect(Object.keys(luBusyBusiness.promises).length).toEqual(2);
-
- var d = luBusyBusiness.promises['my-id'];
- expect(d).not.toBe(null);
- expect(d).not.toBe(undefined);
- expect(d.loaders).toEqual(['all-groups', 'another-group', 'loader-groups']);
- expect(d.errors).toEqual(['all-groups', 'another-group']);
- expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
- expect(d.id).toBe('my-id');
-
- d = luBusyBusiness.promises['my-id2'];
- expect(d).not.toBe(null);
- expect(d).not.toBe(undefined);
- expect(d.loaders).toEqual(['all-groups', 'another-group']);
- expect(d.errors).toEqual(['all-groups', 'another-group', 'an-error-group']);
- expect(d.status).toBe(luBusyBusiness.STATUS_RUNNING);
- expect(d.id).toBe('my-id2');
-
- expect(Object.keys(luBusyBusiness.errors).length).toEqual(3);
- expect(luBusyBusiness.errors['all-groups'].length).toEqual(2);
- expect(luBusyBusiness.errors['all-groups'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.errors['all-groups'][1]['id']).toEqual('my-id2');
- expect(luBusyBusiness.errors['another-group'].length).toEqual(2);
- expect(luBusyBusiness.errors['another-group'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.errors['another-group'][1]['id']).toEqual('my-id2');
- expect(luBusyBusiness.errors['an-error-group'].length).toEqual(1);
- expect(luBusyBusiness.errors['an-error-group'][0]['id']).toEqual('my-id2');
-
- expect(Object.keys(luBusyBusiness.loaders).length).toEqual(3);
- expect(luBusyBusiness.loaders['all-groups'].length).toEqual(2);
- expect(luBusyBusiness.loaders['all-groups'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.loaders['all-groups'][1]['id']).toEqual('my-id2');
- expect(luBusyBusiness.loaders['another-group'].length).toEqual(2);
- expect(luBusyBusiness.loaders['another-group'][0]['id']).toEqual('my-id');
- expect(luBusyBusiness.loaders['another-group'][1]['id']).toEqual('my-id2');
- expect(luBusyBusiness.loaders['loader-groups'].length).toEqual(1);
- expect(luBusyBusiness.loaders['loader-groups'][0]['id']).toEqual('my-id');
- });
- });
|