|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import App from '../App'; |
| 3 | +import { flat, hosts, renderScreen, scenes, tabButton } from './harness'; |
| 4 | +import { Platform } from './mocks/react-native'; |
| 5 | +import { setMockSafeAreaInsets } from './mocks/react-native-safe-area-context'; |
| 6 | + |
| 7 | +// Native geometry is exercised separately with the APK. These tests pin the |
| 8 | +// platform wiring so mocked native components cannot claim to prove IME layout. |
| 9 | +describe('shell keyboard avoidance', () => { |
| 10 | + it('resizes the Android shell containing the scenes and tabs', async () => { |
| 11 | + const renderer = await renderScreen(<App />); |
| 12 | + const shell = hosts(renderer.root, 'KeyboardAvoidingView').find( |
| 13 | + (node) => node.props.enabled === true, |
| 14 | + ); |
| 15 | + expect(shell).toBeDefined(); |
| 16 | + expect(shell!.props.behavior).toBe('height'); |
| 17 | + expect(shell!.props.keyboardVerticalOffset).toBe(0); |
| 18 | + expect(scenes(shell!)).toHaveLength(4); |
| 19 | + expect(tabButton(shell!, 'Chat')).toBeDefined(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('keeps system insets inside the keyboard-aware root without a second offset', async () => { |
| 23 | + setMockSafeAreaInsets({ top: 37, right: 12, bottom: 48, left: 12 }); |
| 24 | + const renderer = await renderScreen(<App />); |
| 25 | + const shell = hosts(renderer.root, 'KeyboardAvoidingView').find( |
| 26 | + (node) => node.props.enabled === true, |
| 27 | + ); |
| 28 | + expect(shell).toBeDefined(); |
| 29 | + expect(flat(shell!)).toMatchObject({ paddingTop: 37, paddingLeft: 12, paddingRight: 12 }); |
| 30 | + expect(shell!.props.keyboardVerticalOffset).toBe(0); |
| 31 | + }); |
| 32 | + |
| 33 | + it('does not add a second keyboard adjustment to the existing iOS chat', async () => { |
| 34 | + Platform.OS = 'ios'; |
| 35 | + const renderer = await renderScreen(<App />); |
| 36 | + const views = hosts(renderer.root, 'KeyboardAvoidingView'); |
| 37 | + const shell = views.find((node) => node.props.enabled === false); |
| 38 | + expect(shell).toBeDefined(); |
| 39 | + expect(shell!.props.behavior).toBeUndefined(); |
| 40 | + expect(views.some((node) => node.props.behavior === 'padding')).toBe(true); |
| 41 | + }); |
| 42 | +}); |
0 commit comments