]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/direct/Provider.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / direct / Provider.js
CommitLineData
6527f429
DM
1describe("Ext.direct.Provider", function() {\r
2 var provider, connectSpy, disconnectSpy;\r
3 \r
4 function makeProvider(config) {\r
5 provider = new Ext.direct.Provider(config);\r
6 \r
7 return provider;\r
8 }\r
9 \r
10 beforeEach(function() {\r
11 makeProvider();\r
12 \r
13 spyOn(provider, 'doConnect');\r
14 spyOn(provider, 'doDisconnect');\r
15 \r
16 connectSpy = jasmine.createSpy('connect');\r
17 disconnectSpy = jasmine.createSpy('disconnect');\r
18 \r
19 provider.on('connect', connectSpy);\r
20 provider.on('disconnect', disconnectSpy);\r
21 });\r
22 \r
23 afterEach(function() {\r
24 if (provider) {\r
25 provider.destroy();\r
26 }\r
27 \r
28 Ext.direct.Manager.clearAllMethods();\r
29 \r
30 provider = connectSpy = disconnectSpy = null;\r
31 });\r
32 \r
33 describe("ids", function() {\r
34 it("should auto-assign id when not configured with one", function() {\r
35 expect(/^provider-/.test(provider.id)).toBe(true);\r
36 });\r
37 \r
38 it("should not assign auto id when configured", function() {\r
39 provider.destroy();\r
40 \r
41 makeProvider({ id: 'foo' });\r
42 \r
43 expect(provider.id).toBe('foo');\r
44 });\r
45 });\r
46 \r
47 describe("destroy", function() {\r
48 var destroySpy;\r
49 \r
50 beforeEach(function() {\r
51 spyOn(provider, 'disconnect').andCallThrough();\r
52 \r
53 provider.destroy();\r
54 });\r
55 \r
56 it("should disconnect when called first time", function() {\r
57 expect(provider.disconnect).toHaveBeenCalled();\r
58 });\r
59 \r
60 it("should force disconnect", function() {\r
61 var args = provider.disconnect.mostRecentCall.args;\r
62 \r
63 expect(args[0]).toBe(true);\r
64 });\r
65 \r
66 it("should set destroyed flag", function() {\r
67 expect(provider.destroyed).toBe(true);\r
68 });\r
69 \r
70 it("should not disconnect when called more than once", function() {\r
71 provider.destroy();\r
72 \r
73 expect(provider.disconnect.callCount).toBe(1);\r
74 });\r
75 });\r
76 \r
77 describe("isConnected", function() {\r
78 it("should return false when subscribers === 0", function() {\r
79 expect(provider.isConnected()).toBe(false);\r
80 });\r
81 \r
82 it("should return true when subscribers > 0", function() {\r
83 provider.subscribers = 1;\r
84 \r
85 expect(provider.isConnected()).toBe(true);\r
86 });\r
87 });\r
88 \r
89 describe("connect", function() {\r
90 describe("first time", function() {\r
91 beforeEach(function() {\r
92 provider.connect();\r
93 });\r
94 \r
95 it("should call doConnect", function() {\r
96 expect(provider.doConnect).toHaveBeenCalled();\r
97 });\r
98 \r
99 it("should fire connect event", function() {\r
100 expect(connectSpy).toHaveBeenCalled();\r
101 });\r
102 \r
103 it("should increment subscribers", function() {\r
104 expect(provider.subscribers).toBe(1);\r
105 });\r
106 });\r
107 \r
108 describe("after first time", function() {\r
109 beforeEach(function() {\r
110 provider.subscribers = 1;\r
111 provider.connect();\r
112 });\r
113 \r
114 it("should not call doConnect", function() {\r
115 expect(provider.doConnect).not.toHaveBeenCalled();\r
116 });\r
117 \r
118 it("should not fire connect event", function() {\r
119 expect(connectSpy).not.toHaveBeenCalled();\r
120 });\r
121 \r
122 it("should increment subscribers", function() {\r
123 expect(provider.subscribers).toBe(2);\r
124 });\r
125 });\r
126 });\r
127 \r
128 describe("disconnect", function() {\r
129 describe("when subscribers == 2", function() {\r
130 beforeEach(function() {\r
131 provider.subscribers = 2;\r
132 });\r
133 \r
134 describe("not forced", function() {\r
135 beforeEach(function() {\r
136 provider.disconnect();\r
137 });\r
138 \r
139 it("should not call doDisconnect", function() {\r
140 expect(provider.doDisconnect).not.toHaveBeenCalled();\r
141 });\r
142 \r
143 it("should not fire disconnect event", function() {\r
144 expect(disconnectSpy).not.toHaveBeenCalled();\r
145 });\r
146 \r
147 it("should decrement subscribers", function() {\r
148 expect(provider.subscribers).toBe(1);\r
149 });\r
150 });\r
151 \r
152 describe("forced", function() {\r
153 beforeEach(function() {\r
154 provider.disconnect(true);\r
155 });\r
156 \r
157 it("should call doDisconnect", function() {\r
158 expect(provider.doDisconnect).toHaveBeenCalled();\r
159 });\r
160 \r
161 it("should fire disconnect event", function() {\r
162 expect(disconnectSpy).toHaveBeenCalled();\r
163 });\r
164 \r
165 it("should reset subscribers to 0", function() {\r
166 expect(provider.subscribers).toBe(0);\r
167 });\r
168 });\r
169 });\r
170 \r
171 describe("when subscribers == 1", function() {\r
172 beforeEach(function() {\r
173 provider.subscribers = 1;\r
174 provider.disconnect();\r
175 });\r
176 \r
177 it("should call doDisconnect", function() {\r
178 expect(provider.doDisconnect).toHaveBeenCalled();\r
179 });\r
180 \r
181 it("should fire disconnect event", function() {\r
182 expect(disconnectSpy).toHaveBeenCalled();\r
183 });\r
184 \r
185 it("should decrement subscribers", function() {\r
186 expect(provider.subscribers).toBe(0);\r
187 });\r
188 });\r
189 \r
190 describe("when subscribers == 0", function() {\r
191 beforeEach(function() {\r
192 provider.disconnect();\r
193 });\r
194 \r
195 it("should not call doDisconnect", function() {\r
196 expect(provider.doDisconnect).not.toHaveBeenCalled();\r
197 });\r
198 \r
199 it("should not fire disconnect event", function() {\r
200 expect(disconnectSpy).not.toHaveBeenCalled();\r
201 });\r
202 \r
203 it("should not decrement subscribers", function() {\r
204 expect(provider.subscribers).toBe(0);\r
205 });\r
206 });\r
207 });\r
208});\r