test: add device orientation tests - #308
Conversation
WalkthroughAdds an iOS Simulator test that relaunches the playground app, opens the Basic UI screen, verifies orientation-specific elements, and checks screenshot dimensions in portrait and landscape. Adds helpers for tapping named elements, reading and setting device orientation, and asserting that elements are absent from the UI hierarchy. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/simulator.spec.ts`:
- Around line 264-304: Update the “should rotate the playground app between
portrait and landscape” test to capture the simulator’s original orientation,
set portrait before app navigation and initial assertions, and wrap the rotation
flow in try/finally. In the finally block, restore the captured orientation so
failures cannot leave the simulator in landscape.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ff103dd4-4d6a-4f74-9172-b0db22d1cc27
📒 Files selected for processing (1)
test/simulator.spec.ts
| test('should rotate the playground app between portrait and landscape', async () => { | ||
| test.skip(!simulatorId, 'simulator not found'); | ||
|
|
||
| // starting the device agent dismisses whatever is in the foreground, | ||
| // so warm it up before launching the app under test | ||
| dumpUI(simulatorId); | ||
|
|
||
| // relaunch so the app starts at its root menu instead of a previously visited screen | ||
| terminateApp(simulatorId, 'com.mobilenext.playground'); | ||
| await new Promise(resolve => setTimeout(resolve, 2000)); | ||
| launchApp(simulatorId, 'com.mobilenext.playground'); | ||
| await new Promise(resolve => setTimeout(resolve, 5000)); | ||
|
|
||
| tapElementByName(simulatorId, 'Basic UI'); | ||
| await new Promise(resolve => setTimeout(resolve, 3000)); | ||
| verifyElementExists(dumpUI(simulatorId), 'Reset Counter'); | ||
|
|
||
| expect(getOrientation(simulatorId)).toBe('portrait'); | ||
| const portraitScreenshot = getScreenshotDimensions(simulatorId); | ||
| expect(portraitScreenshot.height).toBeGreaterThan(portraitScreenshot.width); | ||
|
|
||
| setOrientation(simulatorId, 'landscape'); | ||
| await new Promise(resolve => setTimeout(resolve, 3000)); | ||
| expect(getOrientation(simulatorId)).toBe('landscape'); | ||
|
|
||
| // the shorter landscape viewport pushes Reset Counter below the fold, | ||
| // while Text Input stays visible at the top of the form | ||
| const landscapeDump = dumpUI(simulatorId); | ||
| verifyElementDoesNotExist(landscapeDump, 'Reset Counter'); | ||
| verifyElementExists(landscapeDump, 'Text Input'); | ||
|
|
||
| const landscapeScreenshot = getScreenshotDimensions(simulatorId); | ||
| expect(landscapeScreenshot.width).toBeGreaterThan(landscapeScreenshot.height); | ||
|
|
||
| setOrientation(simulatorId, 'portrait'); | ||
| await new Promise(resolve => setTimeout(resolve, 3000)); | ||
| expect(getOrientation(simulatorId)).toBe('portrait'); | ||
|
|
||
| const restoredScreenshot = getScreenshotDimensions(simulatorId); | ||
| expect(restoredScreenshot.height).toBeGreaterThan(restoredScreenshot.width); | ||
| }); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Make orientation setup and cleanup failure-safe.
The simulator can begin in landscape, causing the portrait assertions to fail before line 285. Also, any failure after rotation skips lines 298-300 and leaks landscape state into subsequent tests. Capture the original orientation, explicitly set portrait before navigating, and restore the original state in try/finally.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/simulator.spec.ts` around lines 264 - 304, Update the “should rotate the
playground app between portrait and landscape” test to capture the simulator’s
original orientation, set portrait before app navigation and initial assertions,
and wrap the rotation flow in try/finally. In the finally block, restore the
captured orientation so failures cannot leave the simulator in landscape.
No description provided.