UNPKG

5.2 kBJavaScriptView Raw
1'use strict';
2
3var assert = require('assert'),
4 danf = require('../lib/app')
5;
6
7var app = danf(require(__dirname + '/fixtures/danf'), {silent: true, environment: 'test'});
8
9describe('Danf application', function() {
10 it('should provide a "container" accessible property', function() {
11 assert(app.hasOwnProperty('servicesContainer'));
12 })
13
14 it('should instantiate a "services container"', function() {
15 assert.notEqual(app.servicesContainer, undefined);
16 })
17
18 it('should add the danf services to the list of the container\'s services', function() {
19 var dataResolver = app.servicesContainer.get('danf:manipulation.dataResolver');
20
21 assert.notEqual(dataResolver, undefined);
22 })
23
24 it('should instanciate the services of the dependencies', function() {
25 assert.equal(app.servicesContainer.get('main:dep2:storage.local').name, 'local storage');
26 assert.equal(app.servicesContainer.get('main:dep2:provider.bigImages').rules[0].parameters[0].value, 3);
27 })
28
29 it('should interface the services with their defined existent interfaces', function() {
30 var manager = app.servicesContainer.get('main:manager');
31
32 assert(Object.isInstanceOf(manager, 'main:ManagerInterface'));
33 })
34
35 it('should resolve the defined parameters', function() {
36 var parameter = app.servicesContainer.get('main:provider.bigImages.rules.0.parameters.0');
37
38 assert.equal(parameter.name, 'parameter size');
39 })
40
41 it('should override a dependency of a submodule if defined in the configuration', function() {
42 var counter1 = app.servicesContainer.get('main:dep1:module10:counter'),
43 counter2 = app.servicesContainer.get('main:counter2'),
44 counter3 = app.servicesContainer.get('main:dep3:module10:counter')
45 ;
46
47 assert.equal(counter1.count, 0);
48 assert.equal(counter2.count, 0);
49 assert.equal(counter3.count, 0);
50
51 counter1.inc();
52
53 assert.equal(counter1.count, 1);
54 assert.equal(counter2.count, 1);
55 assert.equal(counter3.count, 0);
56
57 var manager1 = app.servicesContainer.get('main:dep1:manager'),
58 manager2 = app.servicesContainer.get('main:dep2:manager'),
59 manager3 = app.servicesContainer.get('main:dep3:manager')
60 ;
61
62 assert.equal(manager1.timeOut, 1000);
63 assert.equal(manager2.timeOut, 1000);
64 assert.equal(manager3.timeOut, 3000);
65
66 assert.equal(manager1.try, 1);
67 assert.equal(manager2.try, 1);
68 assert.equal(manager3.try, 3);
69 })
70
71 it('should allow multilevel inheritance', function() {
72 var classesRegistry = app.servicesContainer.get('danf:object.classesRegistry'),
73 a = classesRegistry.get('main:a'),
74 b = classesRegistry.get('main:b')
75 ;
76
77 assert(typeof a, 'function');
78 assert(typeof b, 'function');
79 assert(b.Parent, a);
80
81 var polymorphous = app.servicesContainer.get('main:polymorphous');
82
83 assert.equal(typeof polymorphous.a, 'function');
84 assert.equal(typeof polymorphous.b, 'function');
85 assert.equal(typeof polymorphous.c, 'function');
86 assert.equal(polymorphous.a(), 2);
87 assert.equal(polymorphous.b(), 3);
88 assert.equal(polymorphous.c(), 4);
89 })
90
91 it('should allow cross danf modules inheritance', function() {
92 var computer = app.servicesContainer.get('main:computer');
93
94 assert.equal(computer.inc(), 3);
95 assert.equal(computer.inc(), 4);
96 })
97
98 it('should allow cross danf modules inheritance', function(done) {
99 var trigger = app.servicesContainer.get('main:trigger');
100
101 trigger.trigger(done);
102 })
103
104 it('should allow cross danf modules inheritance', function(done) {
105 var trigger = app.servicesContainer.get('main:dep1:trigger');
106
107 trigger.trigger(done);
108 })
109
110 it('should handle environment configurations', function() {
111 var timer = app.servicesContainer.get('main:timer');
112
113 assert.equal(timer.timeOut, 2100);
114 assert.equal(timer.interval, 20);
115 })
116
117 it('should allow to overwrite danf configuration', function() {
118 var callbackExecutor = app.servicesContainer.get('danf:manipulation.callbackExecutor');
119
120 assert.equal(typeof callbackExecutor.executeCallback, 'function');
121 assert.equal(callbackExecutor.executeCallback(function() { return 3; }), 3);
122 })
123
124 it('should process basic events', function(done) {
125 var trigger = app.servicesContainer.get('danf:event.eventsHandler'),
126 computer = app.servicesContainer.get('main:computer')
127 ;
128
129 trigger.trigger('event', 'happenSomething', computer, {i: 3, k: 3, done: done});
130 })
131
132 it('should process basic events', function(done) {
133 var trigger = app.servicesContainer.get('danf:event.eventsHandler'),
134 computer = app.servicesContainer.get('main:computer')
135 ;
136
137 trigger.trigger('event', 'happenSomething', computer, {k: 0, done: done});
138 })
139})
\No newline at end of file