Skip to content

Commit

Permalink
test(register): additional test to verify screen background
Browse files Browse the repository at this point in the history
  • Loading branch information
tobua committed Oct 3, 2023
1 parent ffe40c7 commit 2497d9c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
40 changes: 40 additions & 0 deletions test/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,43 @@ test('Initially shown screen can be configured though register.', () => {

destroy()
})

test('Background of screen can be configured initially and with go().', () => {
const names = [
{ name: 'FirstScreen' },
{ name: 'SecondScreen', options: { background: 'red' } },
{ name: 'ThirdScreen', options: { background: 'blue', transition: Transition.peek } },
]
setupScreens(names)

const { root } = render(<Navigation headless={false} />)

let screen = root.findAllByType(Animated.View)
let top = screen[0]

expect(top.props.style[1].backgroundColor).toBe('white')

act(() => {
go(names[1].name)
})

screen = root.findAllByType(Animated.View)
top = screen[1]

// @ts-ignore
expect(top._fiber.key).toEqual('SecondScreen_top')
expect(top.props.style[1].backgroundColor).toBe('red')

act(() => {
go(names[2].name)
})

screen = root.findAllByType(Animated.View)
top = screen[2] // TouchableOpacity adds another Animated.View

// @ts-ignore
expect(top._fiber.key).toEqual('ThirdScreen_top')
expect(top.props.style[1].backgroundColor).toBe('blue')

destroy()
})
4 changes: 3 additions & 1 deletion test/utils/setup-screens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import { register } from 'reactigation'
import createTestScreen from '../components/Screen'

export default (screens: (string | { name: string; options?: { initial?: boolean } })[]) => {
export default (
screens: (string | { name: string; options?: { initial?: boolean; background?: string } })[],
) => {
return screens.map((screen) => {
let name
let options = {} as any
Expand Down

0 comments on commit 2497d9c

Please sign in to comment.