scandit-datacapture-frameworks-core 8.3.1 → 8.4.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.3.1",
3
+ "version": "8.4.0",
4
4
  "description": "Core common package",
5
5
  "author": {
6
6
  "name": "Scandit",
@@ -306,6 +306,50 @@ describe('CameraSettings', () => {
306
306
  });
307
307
  });
308
308
 
309
+ describe('zoomLevels', () => {
310
+ it('initializes with default zoomLevels from defaults', () => {
311
+ const settings = new CameraSettings();
312
+ expect(settings.zoomLevels).toEqual([1, 2]);
313
+ });
314
+
315
+ it('can be set to custom zoom levels', () => {
316
+ const settings = new CameraSettings();
317
+ settings.zoomLevels = [0.5, 1, 2, 3];
318
+ expect(settings.zoomLevels).toEqual([0.5, 1, 2, 3]);
319
+ });
320
+
321
+ it('is deserialized from JSON', () => {
322
+ const json = {
323
+ preferredResolution: 'auto',
324
+ zoomFactor: 1,
325
+ zoomGestureZoomFactor: 2,
326
+ zoomLevels: [1, 2, 5],
327
+ };
328
+
329
+ const settings = (CameraSettings as any).fromJSON(json);
330
+ expect(settings.zoomLevels).toEqual([1, 2, 5]);
331
+ });
332
+
333
+ it('defaults to [1, 2] when absent from JSON', () => {
334
+ const json = {
335
+ preferredResolution: 'auto',
336
+ zoomFactor: 1,
337
+ zoomGestureZoomFactor: 2,
338
+ };
339
+
340
+ const settings = (CameraSettings as any).fromJSON(json);
341
+ expect(settings.zoomLevels).toEqual([1, 2]);
342
+ });
343
+
344
+ it('is serialized to JSON', () => {
345
+ const settings = new CameraSettings();
346
+ settings.zoomLevels = [0.5, 1, 3];
347
+
348
+ const json = JSON.parse(JSON.stringify(settings));
349
+ expect(json.zoomLevels).toEqual([0.5, 1, 3]);
350
+ });
351
+ });
352
+
309
353
  describe('copy constructor', () => {
310
354
  it('copies all settings including focus sub-fields', () => {
311
355
  const original = new CameraSettings();
@@ -0,0 +1,62 @@
1
+ import { describe, it, expect } from '@jest/globals';
2
+ import { parseDefaults } from '../src/defaults/CoreDefaults';
3
+ import { mockCoreDefaultsData } from '../__mocks__/Defaults';
4
+ import { SwipeToZoom } from '../src/camera/SwipeToZoom';
5
+ import { PinchToZoom } from '../src/camera/PinchToZoom';
6
+
7
+ describe('parseDefaults — DataCaptureView.zoomGestures', () => {
8
+ // Cordova / React Native bridge shape: the whole field arrives as a
9
+ // single JSON-encoded string and is parsed once at the top level.
10
+ it('parses zoomGestures when sent as a stringified array', () => {
11
+ const json = {
12
+ ...mockCoreDefaultsData,
13
+ DataCaptureView: {
14
+ ...mockCoreDefaultsData.DataCaptureView,
15
+ zoomGestures: '[{"type":"swipeToZoom"},{"type":"pinchToZoom"}]',
16
+ },
17
+ };
18
+
19
+ const defaults = parseDefaults(json);
20
+
21
+ expect(defaults.DataCaptureView.zoomGestures).toHaveLength(2);
22
+ expect(defaults.DataCaptureView.zoomGestures[0]).toBeInstanceOf(SwipeToZoom);
23
+ expect(defaults.DataCaptureView.zoomGestures[1]).toBeInstanceOf(PinchToZoom);
24
+ });
25
+
26
+ // Capacitor bridge shape: arrays come through as arrays whose elements
27
+ // are still JSON-encoded strings. The previous implementation cast the
28
+ // array directly and lost every element.
29
+ it('parses zoomGestures when sent as an array of JSON strings (Capacitor)', () => {
30
+ const json = {
31
+ ...mockCoreDefaultsData,
32
+ DataCaptureView: {
33
+ ...mockCoreDefaultsData.DataCaptureView,
34
+ zoomGestures: ['{"type":"swipeToZoom"}', '{"type":"pinchToZoom"}'],
35
+ },
36
+ };
37
+
38
+ const defaults = parseDefaults(json);
39
+
40
+ expect(defaults.DataCaptureView.zoomGestures).toHaveLength(2);
41
+ expect(defaults.DataCaptureView.zoomGestures[0]).toBeInstanceOf(SwipeToZoom);
42
+ expect(defaults.DataCaptureView.zoomGestures[1]).toBeInstanceOf(PinchToZoom);
43
+ });
44
+
45
+ // Older native that doesn't send zoomGestures at all — fall back to the
46
+ // legacy singular zoomGesture and wrap it.
47
+ it('falls back to singular zoomGesture when zoomGestures is missing', () => {
48
+ const { zoomGestures, ...rest } = mockCoreDefaultsData.DataCaptureView;
49
+ const json = {
50
+ ...mockCoreDefaultsData,
51
+ DataCaptureView: {
52
+ ...rest,
53
+ zoomGesture: '{"type":"swipeToZoom"}',
54
+ },
55
+ };
56
+
57
+ const defaults = parseDefaults(json);
58
+
59
+ expect(defaults.DataCaptureView.zoomGestures).toHaveLength(1);
60
+ expect(defaults.DataCaptureView.zoomGestures[0]).toBeInstanceOf(SwipeToZoom);
61
+ });
62
+ });
@@ -0,0 +1,130 @@
1
+ import { describe, it, expect, beforeEach } from '@jest/globals';
2
+ import { ZoomSwitchControl, ZoomSwitchOrientation } from '../src';
3
+ import { loadMockDefaults } from '../__mocks__/Defaults';
4
+
5
+ beforeEach(() => {
6
+ loadMockDefaults();
7
+ });
8
+
9
+ describe('ZoomSwitchControl', () => {
10
+ describe('default constructor', () => {
11
+ it('initializes with default v2 properties', () => {
12
+ const control = new ZoomSwitchControl();
13
+
14
+ expect(control.orientation).toBe(ZoomSwitchOrientation.Horizontal);
15
+ expect(control.isAlwaysExpanded).toBe(false);
16
+ expect(control.isExpanded).toBe(false);
17
+ expect(control.accessibilityLabel).toBe('Zoom <level>');
18
+ expect(control.accessibilityHint).toBe('Adjusts the camera zoom level');
19
+ expect(control.selectedZoomLevel).toBe(1);
20
+ });
21
+
22
+ it('initializes with null legacy accessibility properties', () => {
23
+ const control = new ZoomSwitchControl();
24
+
25
+ expect(control.contentDescriptionWhenZoomedOut).toBeNull();
26
+ expect(control.contentDescriptionWhenZoomedIn).toBeNull();
27
+ expect(control.accessibilityLabelWhenZoomedOut).toBeNull();
28
+ expect(control.accessibilityLabelWhenZoomedIn).toBeNull();
29
+ expect(control.accessibilityHintWhenZoomedOut).toBeNull();
30
+ expect(control.accessibilityHintWhenZoomedIn).toBeNull();
31
+ });
32
+ });
33
+
34
+ describe('v2 property setters', () => {
35
+ it('allows setting orientation to Vertical', () => {
36
+ const control = new ZoomSwitchControl();
37
+ control.orientation = ZoomSwitchOrientation.Vertical;
38
+ expect(control.orientation).toBe(ZoomSwitchOrientation.Vertical);
39
+ });
40
+
41
+ it('allows setting isAlwaysExpanded', () => {
42
+ const control = new ZoomSwitchControl();
43
+ control.isAlwaysExpanded = true;
44
+ expect(control.isAlwaysExpanded).toBe(true);
45
+ });
46
+
47
+ it('allows setting isExpanded', () => {
48
+ const control = new ZoomSwitchControl();
49
+ control.isExpanded = true;
50
+ expect(control.isExpanded).toBe(true);
51
+ });
52
+
53
+ it('allows setting accessibilityLabel', () => {
54
+ const control = new ZoomSwitchControl();
55
+ control.accessibilityLabel = 'Camera zoom';
56
+ expect(control.accessibilityLabel).toBe('Camera zoom');
57
+ });
58
+
59
+ it('allows setting accessibilityHint', () => {
60
+ const control = new ZoomSwitchControl();
61
+ control.accessibilityHint = 'Double tap to zoom';
62
+ expect(control.accessibilityHint).toBe('Double tap to zoom');
63
+ });
64
+ });
65
+
66
+ describe('selectedZoomLevel', () => {
67
+ it('is read-only (no public setter)', () => {
68
+ const control = new ZoomSwitchControl();
69
+ expect(control.selectedZoomLevel).toBe(1);
70
+ });
71
+ });
72
+
73
+ describe('JSON serialization', () => {
74
+ it('serializes v2 properties with correct JSON keys', () => {
75
+ const control = new ZoomSwitchControl();
76
+ control.orientation = ZoomSwitchOrientation.Vertical;
77
+ control.isAlwaysExpanded = true;
78
+ control.isExpanded = true;
79
+ control.accessibilityLabel = 'Camera zoom';
80
+ control.accessibilityHint = 'Double tap';
81
+
82
+ const json = JSON.parse(JSON.stringify(control));
83
+
84
+ expect(json.type).toBe('zoom');
85
+ expect(json.orientation).toBe('vertical');
86
+ expect(json.isAlwaysExpanded).toBe(true);
87
+ expect(json.isExpanded).toBe(true);
88
+ expect(json.accessibilityLabel).toBe('Camera zoom');
89
+ expect(json.accessibilityHint).toBe('Double tap');
90
+ });
91
+
92
+ it('does not serialize selectedZoomLevel', () => {
93
+ const control = new ZoomSwitchControl();
94
+
95
+ const json = JSON.parse(JSON.stringify(control));
96
+
97
+ expect(json.selectedZoomLevel).toBeUndefined();
98
+ expect(json._selectedZoomLevel).toBeUndefined();
99
+ });
100
+
101
+ it('serializes default values correctly', () => {
102
+ const control = new ZoomSwitchControl();
103
+
104
+ const json = JSON.parse(JSON.stringify(control));
105
+
106
+ expect(json.orientation).toBe('horizontal');
107
+ expect(json.isAlwaysExpanded).toBe(false);
108
+ expect(json.isExpanded).toBe(false);
109
+ expect(json.accessibilityLabel).toBe('Zoom <level>');
110
+ expect(json.accessibilityHint).toBe('Adjusts the camera zoom level');
111
+ });
112
+
113
+ it('still serializes legacy icon properties', () => {
114
+ const control = new ZoomSwitchControl();
115
+
116
+ const json = JSON.parse(JSON.stringify(control));
117
+
118
+ expect(json.icon).toBeDefined();
119
+ expect(json.icon.zoomedOut).toBeDefined();
120
+ expect(json.icon.zoomedIn).toBeDefined();
121
+ });
122
+ });
123
+ });
124
+
125
+ describe('ZoomSwitchOrientation', () => {
126
+ it('has correct string values for JSON serialization', () => {
127
+ expect(ZoomSwitchOrientation.Horizontal).toBe('horizontal');
128
+ expect(ZoomSwitchOrientation.Vertical).toBe('vertical');
129
+ });
130
+ });