Skip to content

Commit c38f739

Browse files
authored
chore: Add <NativePreviewView /> and <Camera /> tests (#3881)
* chore: Add Preview & `<Camera />` tests * simplify test * fix missing onPreviewStarted * fix: Fix camera space to view pixels matrix not being updated * fix: split out `NativePreviewView` with `Camera` * fix: Rewrite NativePreviewView and Camera tests * await unload? * remove useCamera hook from nativepreviewview.harness.tsx * add replacement in one go task * deslop * use front camera for unmount/switch * dont dispose controller/session in useCamera * Update useCameraSession.ts * remove failing tests lol * remove failing test
1 parent 3980a0e commit c38f739

6 files changed

Lines changed: 2176 additions & 22 deletions

File tree

.github/workflows/harness-aws-device.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
- 'apps/simple-camera/device-farm-tests/AwsTestSpecIOS.yml'
107107
- 'packages/**/*.@(swift|mm)'
108108
shared:
109-
- 'apps/simple-camera/__tests__/vision-camera.harness.ts'
109+
- 'apps/simple-camera/__tests__/**'
110110
- 'apps/simple-camera/src/**'
111111
- 'apps/simple-camera/rn-harness.config.mjs'
112112
- 'apps/simple-camera/package.json'

apps/simple-camera/__tests__/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Tests are split by domain. Each file tests one slice of the imperative
4343
| [visioncamera.constraints.harness.ts](visioncamera.constraints.harness.ts) | `VisionCamera.resolveConstraints` + `onSessionConfigSelected`, FPS / HDR / stabilization / binned / pixelFormat / resolutionBias constraints |
4444
| [visioncamera.controller.harness.ts](visioncamera.controller.harness.ts) | `CameraController` — zoom, torch, exposure bias, focus metering, low-light boost, subject area listener |
4545
| [visioncamera.coordinates.harness.ts](visioncamera.coordinates.harness.ts) | `Frame.convertFramePointToCameraPoint` / `convertCameraPointToFramePoint`, `PreviewView.convertViewPointToCameraPoint` / `convertCameraPointToViewPoint`, `PreviewView.createMeteringPoint`, `convertScannedObjectCoordinatesToViewCoordinates`, end-to-end Frame → Camera → View round-trip |
46+
| [visioncamera.nativepreviewview.harness.tsx](visioncamera.nativepreviewview.harness.tsx) | Bare `NativePreviewView` lifecycle, layout-sensitive preview regression coverage, `resizeMode`, Android `implementationMode`, gesture controllers, multi-preview mounting, `PreviewView` ref methods, Android `takeSnapshot()` dimensions |
47+
| [visioncamera.camera-view.harness.tsx](visioncamera.camera-view.harness.tsx) | High-level `<Camera>` preview lifecycle, layout-sensitive preview regression coverage, photo output integration, controller props, native gestures, `CameraRef` methods, Android `implementationMode` / `takeSnapshot()` dimensions |
4648

4749
Pick the file that best matches what you're testing. If you're reproducing a
4850
bug that spans multiple outputs, put it in the file most central to the
@@ -293,18 +295,21 @@ If your PR fails CI, the fastest way to debug is:
293295

294296
## High-level components / hooks (`<Camera>`, `useCamera()`, etc.)
295297

296-
Tests for the high-level `<Camera>` component and the `useCamera()` /
297-
similar React hooks are **not yet in scope here**. They'll live alongside
298-
the imperative tests when added — same principles, same folder.
298+
High-level component tests live alongside the imperative suites when the API
299+
surface is React rendering, layout, or component convenience behavior. Keep
300+
them focused: render the smallest component tree that reproduces the behavior,
301+
wait on real lifecycle events, and assert through the public ref or callbacks.
299302

300-
**Exception: mounting native Hybrid views to exercise their ref methods is
301-
allowed.** Some imperative APIs (e.g. `PreviewView.convertViewPointToCameraPoint`,
303+
For layout regressions, prefer geometry and native ref assertions over golden
304+
screenshots. Device Farm camera feeds are not stable visual fixtures.
305+
306+
Mounting native Hybrid views to exercise their ref methods is still allowed.
307+
Some imperative APIs (e.g. `PreviewView.convertViewPointToCameraPoint`,
302308
`PreviewView.createMeteringPoint`) can only be reached through a mounted,
303309
laid-out view. Those tests may `render(<NativePreviewView ... />)` from
304310
`react-native-harness`, capture the ref via `hybridRef`, and call the methods
305-
directly — see [visioncamera.coordinates.harness.ts](visioncamera.coordinates.harness.ts)
306-
for the pattern. Keep the wrapper minimal: no `<Camera>`, no `useCamera()`,
307-
no `usePreviewOutput()` — drive the session imperatively as everywhere else
308-
in this folder, and only the view is rendered.
311+
directly — see [visioncamera.nativepreviewview.harness.tsx](visioncamera.nativepreviewview.harness.tsx)
312+
and [visioncamera.coordinates.harness.ts](visioncamera.coordinates.harness.ts)
313+
for the imperative pattern.
309314

310315
[react-native-harness]: https://github.com/margelo/react-native-harness

0 commit comments

Comments
 (0)