11import * as React from 'react' ;
2- import { Dimensions , Text , View } from 'react-native' ;
3- import type { GestureResponderEvent } from 'react-native' ;
2+ import { Dimensions , Pressable , Text , View } from 'react-native' ;
3+ import type { GestureResponderEvent , ViewStyle } from 'react-native' ;
44
55import { describe , expect , it , jest } from '@jest/globals' ;
6+ import {
7+ getAnimatedStyle ,
8+ useAnimatedStyle ,
9+ useSharedValue ,
10+ } from 'react-native-reanimated' ;
611import { SafeAreaProvider } from 'react-native-safe-area-context' ;
712
813import { render , screen , userEvent , waitFor } from '../../../test-utils' ;
@@ -21,6 +26,28 @@ const writtenHeadlineVariants: Exclude<AppbarVariant, 'search'>[] = [
2126 'large-flexible' ,
2227] ;
2328
29+ const AnimatedAppbar = ( { staticStyle } : { staticStyle ?: ViewStyle } ) => {
30+ const opacity = useSharedValue ( 0 ) ;
31+ const animatedStyle = useAnimatedStyle ( ( ) => ( { opacity : opacity . value } ) ) ;
32+
33+ return (
34+ < >
35+ < Pressable
36+ testID = "reveal-appbar"
37+ onPress = { ( ) => {
38+ opacity . value = 1 ;
39+ } }
40+ />
41+ < Appbar
42+ variant = "small"
43+ headline = "Inbox"
44+ style = { staticStyle ? [ staticStyle , animatedStyle ] : animatedStyle }
45+ testID = { testIDPrefix }
46+ />
47+ </ >
48+ ) ;
49+ } ;
50+
2451const decorativeHeadlineImage = (
2552 < View >
2653 < View accessible role = "img" accessibilityLabel = "Brand artwork" />
@@ -229,7 +256,7 @@ describe('Appbar surface', () => {
229256 < Appbar variant = "small" headline = "Inbox" testID = { testIDPrefix } />
230257 ) ;
231258
232- expect ( screen . getByTestId ( testIDPrefix ) . parent ) . toHaveStyle ( {
259+ expect ( screen . getByTestId ( testIDPrefix ) ) . toHaveStyle ( {
233260 backgroundColor : LightTheme . colors . surface ,
234261 } ) ;
235262
@@ -242,7 +269,7 @@ describe('Appbar surface', () => {
242269 />
243270 ) ;
244271
245- expect ( screen . getByTestId ( testIDPrefix ) . parent ) . toHaveStyle ( {
272+ expect ( screen . getByTestId ( testIDPrefix ) ) . toHaveStyle ( {
246273 backgroundColor : LightTheme . colors . surfaceContainer ,
247274 } ) ;
248275
@@ -256,7 +283,7 @@ describe('Appbar surface', () => {
256283 />
257284 ) ;
258285
259- expect ( screen . getByTestId ( testIDPrefix ) . parent ) . toHaveStyle ( {
286+ expect ( screen . getByTestId ( testIDPrefix ) ) . toHaveStyle ( {
260287 backgroundColor : customBackground ,
261288 } ) ;
262289 } ) ;
@@ -283,13 +310,69 @@ describe('Appbar surface', () => {
283310 </ SafeAreaProvider >
284311 ) ;
285312
286- expect ( screen . getByTestId ( testIDPrefix ) . parent ) . toHaveStyle ( {
313+ expect ( screen . getByTestId ( testIDPrefix ) ) . toHaveStyle ( {
287314 borderBottomLeftRadius : 16 ,
288315 borderBottomRightRadius : 16 ,
289316 paddingTop : 20 ,
290317 paddingHorizontal : 12 ,
291318 } ) ;
292319 } ) ;
320+
321+ it ( 'animates the app bar with a Reanimated style' , async ( ) => {
322+ await render ( < AnimatedAppbar /> ) ;
323+
324+ const appbar = screen . getByTestId ( testIDPrefix ) ;
325+ expect ( getAnimatedStyle ( appbar ) ) . toMatchObject ( { opacity : 0 } ) ;
326+
327+ await userEvent . press ( screen . getByTestId ( 'reveal-appbar' ) ) ;
328+ await jest . runAllTimersAsync ( ) ;
329+
330+ expect ( getAnimatedStyle ( appbar ) ) . toMatchObject ( { opacity : 1 } ) ;
331+ } ) ;
332+
333+ it ( 'positions the whole app bar, including its safe-area padding' , async ( ) => {
334+ await render (
335+ < Appbar
336+ variant = "small"
337+ headline = "Inbox"
338+ statusBarHeight = { 20 }
339+ style = { { position : 'absolute' , top : 0 , left : 0 , right : 0 , zIndex : 1 } }
340+ testID = { testIDPrefix }
341+ />
342+ ) ;
343+
344+ expect ( screen . getByTestId ( testIDPrefix ) ) . toHaveStyle ( {
345+ position : 'absolute' ,
346+ top : 0 ,
347+ zIndex : 1 ,
348+ paddingTop : 20 ,
349+ } ) ;
350+ } ) ;
351+
352+ it ( 'keeps static styles combined with an animated style' , async ( ) => {
353+ const customBackground = 'rebeccapurple' ;
354+ await render (
355+ < AnimatedAppbar
356+ staticStyle = { {
357+ position : 'absolute' ,
358+ top : 0 ,
359+ backgroundColor : customBackground ,
360+ } }
361+ />
362+ ) ;
363+
364+ const appbar = screen . getByTestId ( testIDPrefix ) ;
365+ expect ( appbar ) . toHaveStyle ( {
366+ position : 'absolute' ,
367+ top : 0 ,
368+ backgroundColor : customBackground ,
369+ } ) ;
370+
371+ await userEvent . press ( screen . getByTestId ( 'reveal-appbar' ) ) ;
372+ await jest . runAllTimersAsync ( ) ;
373+
374+ expect ( getAnimatedStyle ( appbar ) ) . toMatchObject ( { opacity : 1 } ) ;
375+ } ) ;
293376} ) ;
294377
295378describe ( 'Appbar actions' , ( ) => {
0 commit comments