Robin Thoni преди 8 години
родител
ревизия
c0cd42844b
променени са 5 файла, в които са добавени 272 реда и са изтрити 272 реда
  1. 113
    0
      src/Business/lu-busy-business.js
  2. 0
    113
      src/Business/lu-promise.js
  3. 22
    22
      src/DataAccess/lu-request.js
  4. 137
    0
      tests/Business/lu-busy-business.spec.js
  5. 0
    137
      tests/Business/lu-promise.spec.js

+ 113
- 0
src/Business/lu-busy-business.js Целия файл

@@ -0,0 +1,113 @@
1
+/**
2
+ * Created by robin on 10/24/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luBusyBusiness', [function() {
9
+
10
+            var luBusyBusiness = {};
11
+            luBusyBusiness.promises = {};
12
+            luBusyBusiness.loaders = [];
13
+            luBusyBusiness.errors = [];
14
+
15
+            luBusyBusiness.STATUS_RUNNING = 0;
16
+            luBusyBusiness.STATUS_RESOLVED = 1;
17
+            luBusyBusiness.STATUS_REJECTED = 2;
18
+
19
+            luBusyBusiness.build = function(array)
20
+            {
21
+                luBusyBusiness[array] = {};
22
+                for (var id in luBusyBusiness.promises) {
23
+                    if (luBusyBusiness.promises.hasOwnProperty(id)) {
24
+                        var promise = luBusyBusiness.promises[id];
25
+                        promise[array].forEach(function (group) {
26
+                            if (luBusyBusiness[array][group] == null) {
27
+                                luBusyBusiness[array][group] = [];
28
+                            }
29
+                            luBusyBusiness[array][group].push(promise);
30
+                        });
31
+                    }
32
+                }
33
+            };
34
+
35
+            luBusyBusiness.newPromise = function(id, groups, loaderGroups, errorGroups) {
36
+                return {
37
+                    id: id,
38
+                    groups: groups,
39
+                    loaderGroups: loaderGroups,
40
+                    errorGroups: errorGroups
41
+                };
42
+            };
43
+
44
+            luBusyBusiness.initLuBusy = function(data) {
45
+                var p = {
46
+                    loaders : [],
47
+                    errors: [],
48
+                    status: luBusyBusiness.STATUS_RUNNING,
49
+                    id: data.id
50
+                };
51
+
52
+                if (data.groups instanceof Array) {
53
+                    data.groups.forEach(function (group) {
54
+                        p.loaders.push(group);
55
+                        p.errors.push(group);
56
+                    });
57
+                }
58
+                else if (typeof data.groups === 'string') {
59
+                    p.loaders.push(data.groups);
60
+                    p.errors.push(data.groups);
61
+                }
62
+
63
+                if (data.loaderGroups instanceof Array) {
64
+                    data.loaderGroups.forEach(function (group) {
65
+                        p.loaders.push(group);
66
+                    });
67
+                }
68
+                else if (typeof data.loaderGroups === 'string') {
69
+                    p.loaders.push(data.loaderGroups);
70
+                }
71
+
72
+                if (data.errorGroups instanceof Array) {
73
+                    data.errorGroups.forEach(function (group) {
74
+                        p.errors.push(group);
75
+                    });
76
+                }
77
+                else if (typeof data.errorGroups === 'string') {
78
+                    p.errors.push(data.errorGroups);
79
+                }
80
+
81
+                luBusyBusiness.promises[data.id] = p;
82
+
83
+                luBusyBusiness.build("loaders");
84
+                luBusyBusiness.build("errors");
85
+            };
86
+
87
+            luBusyBusiness.getLoadersGroup = function(group) {
88
+                if (luBusyBusiness.loaders[group] == null) {
89
+                    return null;
90
+                }
91
+                return luBusyBusiness.loaders[group];
92
+            };
93
+
94
+            luBusyBusiness.getErrorsGroup = function(group) {
95
+                if (luBusyBusiness.errors[group] == null) {
96
+                    return null;
97
+                }
98
+                return luBusyBusiness.errors[group];
99
+            };
100
+
101
+            luBusyBusiness.reject = function(promise, error) {
102
+                luBusyBusiness.promises[promise.id].status = luBusyBusiness.STATUS_REJECTED;
103
+                luBusyBusiness.promises[promise.id].value = error;
104
+            };
105
+
106
+            luBusyBusiness.resolve = function(promise, data) {
107
+                luBusyBusiness.promises[promise.id].status = luBusyBusiness.STATUS_RESOLVED;
108
+                luBusyBusiness.promises[promise.id].value = data;
109
+            };
110
+
111
+            return luBusyBusiness;
112
+        }]);
113
+})();

+ 0
- 113
src/Business/lu-promise.js Целия файл

@@ -1,113 +0,0 @@
1
-/**
2
- * Created by robin on 10/24/15.
3
- */
4
-
5
-(function () {
6
-    'use strict';
7
-    angular.module('luticate2Utils')
8
-        .factory('luPromise', [function() {
9
-
10
-            var luPromise = {};
11
-            luPromise.promises = {};
12
-            luPromise.loaders = [];
13
-            luPromise.errors = [];
14
-
15
-            luPromise.STATUS_RUNNING = 0;
16
-            luPromise.STATUS_RESOLVED = 1;
17
-            luPromise.STATUS_REJECTED = 2;
18
-
19
-            luPromise.build = function(array)
20
-            {
21
-                luPromise[array] = {};
22
-                for (var id in luPromise.promises) {
23
-                    if (luPromise.promises.hasOwnProperty(id)) {
24
-                        var promise = luPromise.promises[id];
25
-                        promise[array].forEach(function (group) {
26
-                            if (luPromise[array][group] == null) {
27
-                                luPromise[array][group] = [];
28
-                            }
29
-                            luPromise[array][group].push(promise);
30
-                        });
31
-                    }
32
-                }
33
-            };
34
-
35
-            luPromise.newPromise = function(id, groups, loaderGroups, errorGroups) {
36
-                return {
37
-                    id: id,
38
-                    groups: groups,
39
-                    loaderGroups: loaderGroups,
40
-                    errorGroups: errorGroups
41
-                };
42
-            };
43
-
44
-            luPromise.initPromise = function(data) {
45
-                var p = {
46
-                    loaders : [],
47
-                    errors: [],
48
-                    status: luPromise.STATUS_RUNNING,
49
-                    id: data.id
50
-                };
51
-
52
-                if (data.groups instanceof Array) {
53
-                    data.groups.forEach(function (group) {
54
-                        p.loaders.push(group);
55
-                        p.errors.push(group);
56
-                    });
57
-                }
58
-                else if (typeof data.groups === 'string') {
59
-                    p.loaders.push(data.groups);
60
-                    p.errors.push(data.groups);
61
-                }
62
-
63
-                if (data.loaderGroups instanceof Array) {
64
-                    data.loaderGroups.forEach(function (group) {
65
-                        p.loaders.push(group);
66
-                    });
67
-                }
68
-                else if (typeof data.loaderGroups === 'string') {
69
-                    p.loaders.push(data.loaderGroups);
70
-                }
71
-
72
-                if (data.errorGroups instanceof Array) {
73
-                    data.errorGroups.forEach(function (group) {
74
-                        p.errors.push(group);
75
-                    });
76
-                }
77
-                else if (typeof data.errorGroups === 'string') {
78
-                    p.errors.push(data.errorGroups);
79
-                }
80
-
81
-                luPromise.promises[data.id] = p;
82
-
83
-                luPromise.build("loaders");
84
-                luPromise.build("errors");
85
-            };
86
-
87
-            luPromise.getLoadersGroup = function(group) {
88
-                if (luPromise.loaders[group] == null) {
89
-                    return null;
90
-                }
91
-                return luPromise.loaders[group];
92
-            };
93
-
94
-            luPromise.getErrorsGroup = function(group) {
95
-                if (luPromise.errors[group] == null) {
96
-                    return null;
97
-                }
98
-                return luPromise.errors[group];
99
-            };
100
-
101
-            luPromise.reject = function(promise, error) {
102
-                luPromise.promises[promise.id].status = luPromise.STATUS_REJECTED;
103
-                luPromise.promises[promise.id].value = error;
104
-            };
105
-
106
-            luPromise.resolve = function(promise, data) {
107
-                luPromise.promises[promise.id].status = luPromise.STATUS_RESOLVED;
108
-                luPromise.promises[promise.id].value = data;
109
-            };
110
-
111
-            return luPromise;
112
-        }]);
113
-})();

+ 22
- 22
src/DataAccess/lu-request.js Целия файл

@@ -5,54 +5,54 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticate2Utils')
8
-        .factory('luRequest', ['$q', '$http', 'luPromise', function ($q, $http, luPromise) {
8
+        .factory('luRequest', ['$q', '$http', 'luBusyBusiness', function ($q, $http, luBusyBusiness) {
9 9
 
10 10
             var luRequest = {};
11 11
 
12
-            luRequest.get = function(url, dataGet, promise)
12
+            luRequest.get = function(url, dataGet, luBusyDbo)
13 13
             {
14
-                return luRequest.request(url, 'GET', dataGet, null, promise);
14
+                return luRequest.request(url, 'GET', dataGet, null, luBusyDbo);
15 15
             };
16 16
 
17
-            luRequest.post = function(url, dataGet, dataPost, promise)
17
+            luRequest.post = function(url, dataGet, dataPost, luBusyDbo)
18 18
             {
19
-                return luRequest.request(url, 'POST', dataGet, dataPost, promise);
19
+                return luRequest.request(url, 'POST', dataGet, dataPost, luBusyDbo);
20 20
             };
21 21
 
22
-            luRequest.put = function(url, dataGet, dataPost, promise)
22
+            luRequest.put = function(url, dataGet, dataPost, luBusyDbo)
23 23
             {
24
-                return luRequest.request(url, 'PUT', dataGet, dataPost, promise);
24
+                return luRequest.request(url, 'PUT', dataGet, dataPost, luBusyDbo);
25 25
             };
26 26
 
27
-            luRequest.delete = function(url, dataGet, dataPost, promise)
27
+            luRequest.delete = function(url, dataGet, dataPost, luBusyDbo)
28 28
             {
29
-                return luRequest.request(url, 'DELETE', dataGet, dataPost, promise);
29
+                return luRequest.request(url, 'DELETE', dataGet, dataPost, luBusyDbo);
30 30
             };
31 31
 
32
-            function reject(deferred, data, status, promise)
32
+            function reject(deferred, data, status, luBusyDbo)
33 33
             {
34 34
                 var obj = {
35 35
                     Data: data,
36 36
                     Status: status
37 37
                 };
38 38
                 deferred.reject(obj);
39
-                if (promise != null) {
40
-                    luPromise.reject(promise, obj);
39
+                if (luBusyDbo != null) {
40
+                    luBusyBusiness.reject(luBusyDbo, obj);
41 41
                 }
42 42
             }
43 43
 
44
-            function resolve(deferred, data, promise)
44
+            function resolve(deferred, data, luBusyDbo)
45 45
             {
46 46
                 deferred.resolve(data);
47
-                if (promise != null) {
48
-                    luPromise.resolve(promise, data);
47
+                if (luBusyDbo != null) {
48
+                    luBusyBusiness.resolve(luBusyDbo, data);
49 49
                 }
50 50
             }
51 51
 
52
-            luRequest.request = function(url, method, dataGet, dataPost, promise)
52
+            luRequest.request = function(url, method, dataGet, dataPost, luBusyDbo)
53 53
             {
54
-                if (promise != null) {
55
-                    luPromise.initPromise(promise);
54
+                if (luBusyDbo != null) {
55
+                    luBusyBusiness.initLuBusy(luBusyDbo);
56 56
                 }
57 57
                 var deferred = $q.defer();
58 58
 
@@ -72,19 +72,19 @@
72 72
                     .success(function (result, status) {
73 73
                         if (result == null || result.Message != null) {
74 74
                             var message = result == null ? "Failed to parse response" : result.Message;
75
-                            reject(deferred, message, status, promise);
75
+                            reject(deferred, message, status, luBusyDbo);
76 76
                         }
77 77
                         else {
78
-                            resolve(deferred, result.Data, promise);
78
+                            resolve(deferred, result.Data, luBusyDbo);
79 79
                         }
80 80
                     })
81 81
                     .error(function (result, status) {
82 82
                         if (result == null || result.Message != null) {
83 83
                             var message = result == null ? "Failed to parse response" : result.Message;
84
-                            reject(deferred, message, status, promise);
84
+                            reject(deferred, message, status, luBusyDbo);
85 85
                         }
86 86
                         else {
87
-                            reject(deferred, result, status, promise);
87
+                            reject(deferred, result, status, luBusyDbo);
88 88
                         }
89 89
                     });
90 90
                 return deferred.promise;

+ 137
- 0
tests/Business/lu-busy-business.spec.js Целия файл

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

+ 0
- 137
tests/Business/lu-promise.spec.js Целия файл

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

Loading…
Отказ
Запис