scandit-datacapture-frameworks-core 8.1.1 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scandit-datacapture-frameworks-core",
3
- "version": "8.1.1",
3
+ "version": "8.2.0",
4
4
  "description": "Core common package",
5
5
  "author": {
6
6
  "name": "Scandit",
@@ -1,9 +1,8 @@
1
1
  import { describe, it, expect, jest, beforeEach } from '@jest/globals';
2
2
  import { Camera, CameraSettings, FrameSourceState, TorchState, CameraPosition, createNativeProxy, FactoryMaker } from '../src';
3
3
  import { MockCaller, MockNativeEventEmitter, MockDataCaptureContext, createMockCameraNativeModule, createMockDataCaptureContextNativeModule, createMockFeedbackNativeModule } from '../__mocks__/ScanditDataCaptureCore';
4
- import { CameraProxy } from '../src/camera/CameraController';
4
+ import { CoreProxy } from '../src/generated/CoreProxy';
5
5
  import { DataCaptureContextProxy } from '../src/context/controller/DataCaptureContextController';
6
- import { FeedbackProxy } from '../src/feedback/FeedbackController';
7
6
  import { loadMockDefaults } from '../__mocks__/Defaults';
8
7
 
9
8
  describe('Camera Lifecycle with Promise-based Waiting', () => {
@@ -15,22 +14,21 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
15
14
 
16
15
  beforeEach(() => {
17
16
  jest.clearAllMocks();
18
-
17
+
19
18
  (Camera as any)._cameraInstances.clear();
20
- FactoryMaker.instances.delete('CameraProxy');
19
+ FactoryMaker.instances.delete('CoreProxy');
21
20
  FactoryMaker.instances.delete('DataCaptureContextProxy');
22
- FactoryMaker.instances.delete('FeedbackProxy');
23
21
 
24
22
  mockCameraNativeModule = createMockCameraNativeModule();
25
23
  mockContextNativeModule = createMockDataCaptureContextNativeModule();
26
24
  mockFeedbackNativeModule = createMockFeedbackNativeModule();
27
25
  nativeEventEmitter = new MockNativeEventEmitter();
28
-
26
+
29
27
  loadMockDefaults();
30
28
 
31
- FactoryMaker.bindLazyInstance('CameraProxy', () => {
29
+ FactoryMaker.bindLazyInstance('CoreProxy', () => {
32
30
  const caller = new MockCaller(mockCameraNativeModule, nativeEventEmitter);
33
- return createNativeProxy<CameraProxy>(caller);
31
+ return createNativeProxy<CoreProxy>(caller);
34
32
  });
35
33
 
36
34
  FactoryMaker.bindLazyInstance('DataCaptureContextProxy', () => {
@@ -38,11 +36,6 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
38
36
  return createNativeProxy<DataCaptureContextProxy>(caller);
39
37
  });
40
38
 
41
- FactoryMaker.bindLazyInstance('FeedbackProxy', () => {
42
- const caller = new MockCaller(mockFeedbackNativeModule, nativeEventEmitter);
43
- return createNativeProxy<FeedbackProxy>(caller);
44
- });
45
-
46
39
  mockContext = new MockDataCaptureContext();
47
40
  });
48
41
 
@@ -50,10 +43,10 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
50
43
  it('operations only update properties, no native calls', () => {
51
44
  const camera = Camera.default!;
52
45
  const settings = new CameraSettings();
53
-
46
+
54
47
  camera.desiredTorchState = TorchState.On;
55
48
  camera.applySettings(settings);
56
-
49
+
57
50
  expect(camera.desiredTorchState).toBe(TorchState.On);
58
51
  expect((camera as any).settings).toBe(settings);
59
52
  expect(mockContext.update).not.toHaveBeenCalled();
@@ -63,41 +56,41 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
63
56
  describe('Phase 2: Native Creation In Progress', () => {
64
57
  it('operations wait for native camera to be ready', async () => {
65
58
  const camera = Camera.default!;
66
-
59
+
67
60
  const setFrameSourcePromise = mockContext.setFrameSource(camera);
68
-
61
+
69
62
  camera.desiredTorchState = TorchState.On;
70
-
63
+
71
64
  await setFrameSourcePromise;
72
65
  await new Promise(resolve => setTimeout(resolve, 50));
73
-
66
+
74
67
  expect(mockContext.controller.updateContextFromJSON).toHaveBeenCalled();
75
68
  });
76
69
 
77
70
  it('switchToDesiredState waits for native camera', async () => {
78
71
  const camera = Camera.default!;
79
-
72
+
80
73
  const setFrameSourcePromise = mockContext.setFrameSource(camera);
81
74
  const switchPromise = camera.switchToDesiredState(FrameSourceState.On);
82
-
75
+
83
76
  const controllerSpy = jest.spyOn((camera as any).controller, 'switchCameraToDesiredState');
84
-
77
+
85
78
  await setFrameSourcePromise;
86
79
  await switchPromise;
87
-
80
+
88
81
  expect(controllerSpy).toHaveBeenCalledWith(FrameSourceState.On);
89
82
  });
90
83
 
91
84
  it('applySettings waits for native camera', async () => {
92
85
  const camera = Camera.default!;
93
86
  const settings = new CameraSettings();
94
-
87
+
95
88
  const setFrameSourcePromise = mockContext.setFrameSource(camera);
96
89
  const applyPromise = camera.applySettings(settings);
97
-
90
+
98
91
  await setFrameSourcePromise;
99
92
  await applyPromise;
100
-
93
+
101
94
  expect(mockContext.controller.updateContextFromJSON).toHaveBeenCalled();
102
95
  });
103
96
  });
@@ -105,15 +98,15 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
105
98
  describe('Phase 3: Active State', () => {
106
99
  it('operations execute immediately', async () => {
107
100
  const camera = Camera.default!;
108
-
101
+
109
102
  await mockContext.setFrameSource(camera);
110
103
  await new Promise(resolve => setTimeout(resolve, 50));
111
-
104
+
112
105
  mockContext.controller.updateContextFromJSON.mockClear();
113
-
106
+
114
107
  camera.desiredTorchState = TorchState.On;
115
108
  await new Promise(resolve => setTimeout(resolve, 50));
116
-
109
+
117
110
  expect(mockContext.controller.updateContextFromJSON).toHaveBeenCalled();
118
111
  });
119
112
  });
@@ -121,30 +114,30 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
121
114
  describe('Phase transitions', () => {
122
115
  it('transitions from Phase 1 → Phase 2 → Phase 3 correctly', async () => {
123
116
  const camera = Camera.default!;
124
-
117
+
125
118
  camera.desiredTorchState = TorchState.On;
126
119
  expect(mockContext.controller.updateContextFromJSON).not.toHaveBeenCalled();
127
-
120
+
128
121
  const setFrameSourcePromise = mockContext.setFrameSource(camera);
129
122
  expect((camera as any).nativeReadyPromise).not.toBeNull();
130
-
123
+
131
124
  camera.desiredTorchState = TorchState.Off;
132
-
125
+
133
126
  await setFrameSourcePromise;
134
127
  await new Promise(resolve => setTimeout(resolve, 50));
135
-
128
+
136
129
  expect((camera as any).nativeReadyPromise).toBeNull();
137
130
  expect(mockContext.controller.updateContextFromJSON).toHaveBeenCalled();
138
131
  });
139
132
 
140
133
  it('context set to null clears native ready promise', async () => {
141
134
  const camera = Camera.default!;
142
-
135
+
143
136
  mockContext.setFrameSource(camera);
144
137
  expect((camera as any).nativeReadyPromise).not.toBeNull();
145
-
138
+
146
139
  (camera as any).context = null;
147
-
140
+
148
141
  expect((camera as any).nativeReadyPromise).toBeNull();
149
142
  });
150
143
  });
@@ -153,18 +146,18 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
153
146
  it('multiple operations all wait and execute after native is ready', async () => {
154
147
  const camera = Camera.default!;
155
148
  const settings = new CameraSettings();
156
-
149
+
157
150
  const setFrameSourcePromise = mockContext.setFrameSource(camera);
158
-
151
+
159
152
  camera.desiredTorchState = TorchState.On;
160
153
  const switchPromise = camera.switchToDesiredState(FrameSourceState.On);
161
154
  const applyPromise = camera.applySettings(settings);
162
-
155
+
163
156
  const controllerSpy = jest.spyOn((camera as any).controller, 'switchCameraToDesiredState');
164
-
157
+
165
158
  await setFrameSourcePromise;
166
159
  await Promise.all([switchPromise, applyPromise]);
167
-
160
+
168
161
  expect(mockContext.controller.updateContextFromJSON).toHaveBeenCalled();
169
162
  expect(controllerSpy).toHaveBeenCalledWith(FrameSourceState.On);
170
163
  });
@@ -172,17 +165,17 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
172
165
  it('property updates are preserved even when operations are waiting', async () => {
173
166
  const camera = Camera.default!;
174
167
  const settings = new CameraSettings();
175
-
168
+
176
169
  const setFrameSourcePromise = mockContext.setFrameSource(camera);
177
-
170
+
178
171
  camera.desiredTorchState = TorchState.On;
179
172
  camera.desiredTorchState = TorchState.Off;
180
-
173
+
181
174
  expect(camera.desiredTorchState).toBe(TorchState.Off);
182
-
175
+
183
176
  await setFrameSourcePromise;
184
177
  await new Promise(resolve => setTimeout(resolve, 50));
185
-
178
+
186
179
  expect(camera.desiredTorchState).toBe(TorchState.Off);
187
180
  });
188
181
  });
@@ -191,18 +184,18 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
191
184
  it('returns same camera instance for same position', () => {
192
185
  const camera1 = Camera.atPosition(CameraPosition.WorldFacing);
193
186
  const camera2 = Camera.atPosition(CameraPosition.WorldFacing);
194
-
187
+
195
188
  expect(camera1).toBe(camera2);
196
189
  });
197
190
 
198
191
  it('resetPhaseState clears promise when camera is retrieved from cache', () => {
199
192
  const camera1 = Camera.atPosition(CameraPosition.WorldFacing)!;
200
-
193
+
201
194
  mockContext.setFrameSource(camera1);
202
195
  expect((camera1 as any).nativeReadyPromise).not.toBeNull();
203
-
196
+
204
197
  const camera2 = Camera.create(CameraPosition.WorldFacing);
205
-
198
+
206
199
  expect(camera2).toBe(camera1);
207
200
  expect((camera2 as any).nativeReadyPromise).toBeNull();
208
201
  });
@@ -210,7 +203,7 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
210
203
  it('different camera positions are independent instances', () => {
211
204
  const worldCamera = Camera.atPosition(CameraPosition.WorldFacing);
212
205
  const userCamera = Camera.atPosition(CameraPosition.UserFacing);
213
-
206
+
214
207
  expect(worldCamera).not.toBe(userCamera);
215
208
  });
216
209
  });
@@ -219,37 +212,37 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
219
212
  it('switchToDesiredState in Phase 1 shows warning', async () => {
220
213
  const camera = Camera.default!;
221
214
  const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
222
-
215
+
223
216
  await camera.switchToDesiredState(FrameSourceState.On);
224
-
217
+
225
218
  expect(consoleWarnSpy).toHaveBeenCalledWith(
226
219
  expect.stringContaining('not added to the DataCaptureContext')
227
220
  );
228
-
221
+
229
222
  consoleWarnSpy.mockRestore();
230
223
  });
231
224
 
232
225
  it('multiple property changes in Phase 1 only update TS properties', () => {
233
226
  const camera = Camera.default!;
234
-
227
+
235
228
  camera.desiredTorchState = TorchState.On;
236
229
  camera.desiredTorchState = TorchState.Off;
237
230
  camera.desiredTorchState = TorchState.On;
238
-
231
+
239
232
  expect(camera.desiredTorchState).toBe(TorchState.On);
240
233
  expect(mockContext.controller.updateContextFromJSON).not.toHaveBeenCalled();
241
234
  });
242
235
 
243
236
  it('handles operations during rapid phase transitions', async () => {
244
237
  const camera = Camera.default!;
245
-
238
+
246
239
  camera.desiredTorchState = TorchState.On;
247
240
  const setFrameSourcePromise = mockContext.setFrameSource(camera);
248
241
  camera.desiredTorchState = TorchState.Off;
249
-
242
+
250
243
  await setFrameSourcePromise;
251
244
  await new Promise(resolve => setTimeout(resolve, 50));
252
-
245
+
253
246
  expect(camera.desiredTorchState).toBe(TorchState.Off);
254
247
  expect(mockContext.controller.updateContextFromJSON).toHaveBeenCalled();
255
248
  });
@@ -257,34 +250,34 @@ describe('Camera Lifecycle with Promise-based Waiting', () => {
257
250
  it('times out if native camera is not ready after 5 seconds', async () => {
258
251
  jest.useFakeTimers();
259
252
  const camera = Camera.default!;
260
-
253
+
261
254
  (camera as any).setNativeFrameSourceIsBeingCreated();
262
-
255
+
263
256
  const switchPromise = camera.switchToDesiredState(FrameSourceState.On);
264
-
257
+
265
258
  jest.advanceTimersByTime(5000);
266
-
259
+
267
260
  await expect(switchPromise).rejects.toThrow('Camera native initialization timed out after 5 seconds');
268
-
261
+
269
262
  jest.useRealTimers();
270
263
  });
271
264
 
272
265
  it('timeout is cleared when context is set', async () => {
273
266
  jest.useFakeTimers();
274
267
  const camera = Camera.default!;
275
-
268
+
276
269
  mockContext.setFrameSource(camera);
277
-
270
+
278
271
  const switchPromise = camera.switchToDesiredState(FrameSourceState.On);
279
-
272
+
280
273
  jest.advanceTimersByTime(1000);
281
-
274
+
282
275
  (camera as any).context = mockContext;
283
-
276
+
284
277
  await switchPromise;
285
-
278
+
286
279
  jest.advanceTimersByTime(5000);
287
-
280
+
288
281
  jest.useRealTimers();
289
282
  });
290
283
  });