import { describe, it, expect } from '@jest/globals'; import { parseDefaults } from '../src/defaults/CoreDefaults'; import { mockCoreDefaultsData } from '../__mocks__/Defaults'; import { SwipeToZoom } from '../src/camera/SwipeToZoom'; import { PinchToZoom } from '../src/camera/PinchToZoom'; describe('parseDefaults — DataCaptureView.zoomGestures', () => { // Cordova / React Native bridge shape: the whole field arrives as a // single JSON-encoded string and is parsed once at the top level. it('parses zoomGestures when sent as a stringified array', () => { const json = { ...mockCoreDefaultsData, DataCaptureView: { ...mockCoreDefaultsData.DataCaptureView, zoomGestures: '[{"type":"swipeToZoom"},{"type":"pinchToZoom"}]', }, }; const defaults = parseDefaults(json); expect(defaults.DataCaptureView.zoomGestures).toHaveLength(2); expect(defaults.DataCaptureView.zoomGestures[0]).toBeInstanceOf(SwipeToZoom); expect(defaults.DataCaptureView.zoomGestures[1]).toBeInstanceOf(PinchToZoom); }); // Capacitor bridge shape: arrays come through as arrays whose elements // are still JSON-encoded strings. The previous implementation cast the // array directly and lost every element. it('parses zoomGestures when sent as an array of JSON strings (Capacitor)', () => { const json = { ...mockCoreDefaultsData, DataCaptureView: { ...mockCoreDefaultsData.DataCaptureView, zoomGestures: ['{"type":"swipeToZoom"}', '{"type":"pinchToZoom"}'], }, }; const defaults = parseDefaults(json); expect(defaults.DataCaptureView.zoomGestures).toHaveLength(2); expect(defaults.DataCaptureView.zoomGestures[0]).toBeInstanceOf(SwipeToZoom); expect(defaults.DataCaptureView.zoomGestures[1]).toBeInstanceOf(PinchToZoom); }); // Older native that doesn't send zoomGestures at all — fall back to the // legacy singular zoomGesture and wrap it. it('falls back to singular zoomGesture when zoomGestures is missing', () => { const { zoomGestures, ...rest } = mockCoreDefaultsData.DataCaptureView; const json = { ...mockCoreDefaultsData, DataCaptureView: { ...rest, zoomGesture: '{"type":"swipeToZoom"}', }, }; const defaults = parseDefaults(json); expect(defaults.DataCaptureView.zoomGestures).toHaveLength(1); expect(defaults.DataCaptureView.zoomGestures[0]).toBeInstanceOf(SwipeToZoom); }); });