Skip to content

Commit

Permalink
test(react-native): move scenario logic into scenario classes
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Sep 20, 2024
1 parent e4ed494 commit 147245f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { Navigation } from 'react-native-navigation'
import { View, Text, SafeAreaView, StyleSheet } from 'react-native'
import React, { useEffect } from 'react'
import { launchScenario } from '@bugsnag/react-native-scenarios'
import Bugsnag from '@bugsnag/react-native'

console.reportErrorsAsExceptions = false

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
console.reportErrorsAsExceptions = false

export const AppScreen = () => {
useEffect(() => {
Expand All @@ -22,60 +20,14 @@ export const AppScreen = () => {
)
}

const HomeScreen = (props) => {
useEffect(() => {
(async () => {
await delay(1000)
Bugsnag.notify(new Error('HomeNavigationError'))
await delay(250)
Navigation.push(props.componentId, {
component: {
name: 'Details'
}
})
})()
}, [])

return (
<View style={ { flex: 1, alignItems: 'center', justifyContent: 'center' } }>
<Text>Home Screen</Text>
</View>
)
}

const DetailsScreen = (props) => {
useEffect(() => {
(async () => {
await delay(1000)
Bugsnag.notify(new Error('DetailsNavigationError'))
await delay(250)
throw new Error('DetailsNavigationUnhandledError')
})()
}, [])

return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
</View>
)
}

Navigation.registerComponent('App', () => AppScreen)
Navigation.registerComponent('Home', () => HomeScreen)
Navigation.registerComponent('Details', () => DetailsScreen)
Navigation.events().registerAppLaunchedListener(async () => {
Navigation.setRoot({
root: {
stack: {
children: [
{
component: {
root: {
component: {
name: 'App'
}
}
]
}
}
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
import Scenario from './Scenario'
import { Navigation } from 'react-native-navigation'
import Bugsnag from '@bugsnag/react-native'
import BugsnagReactNativeNavigation from '@bugsnag/plugin-react-native-navigation'
import React, { useEffect } from 'react'
import { Text, View } from 'react-native'
import { Navigation } from 'react-native-navigation'

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))

const HomeScreen = (props) => {
useEffect(() => {
(async () => {
await delay(1000)
Bugsnag.notify(new Error('HomeNavigationError'))
await delay(250)
Navigation.push(props.componentId, {
component: {
name: 'Details'
}
})
})()
}, [])

return (
<View style={ { flex: 1, alignItems: 'center', justifyContent: 'center' } }>
<Text>Home Screen</Text>
</View>
)
}

const DetailsScreen = (props) => {
useEffect(() => {
(async () => {
await delay(1000)
Bugsnag.notify(new Error('DetailsNavigationError'))
await delay(250)
throw new Error('DetailsNavigationUnhandledError')
})()
}, [])

return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
</View>
)
}

export class ReactNativeNavigationBreadcrumbsDisabledScenario extends Scenario {
constructor (configuration, jsConfig) {
Expand All @@ -10,6 +53,9 @@ export class ReactNativeNavigationBreadcrumbsDisabledScenario extends Scenario {
}

run () {
Navigation.registerComponent('Home', () => HomeScreen)
Navigation.registerComponent('Details', () => DetailsScreen)

Navigation.setRoot({
root: {
stack: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
import Scenario from './Scenario'
import Bugsnag from '@bugsnag/react-native'
import BugsnagReactNativeNavigation from '@bugsnag/plugin-react-native-navigation'
import React, { useEffect } from 'react'
import { Text, View } from 'react-native'
import { Navigation } from 'react-native-navigation'

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))

const HomeScreen = (props) => {
useEffect(() => {
(async () => {
await delay(1000)
Bugsnag.notify(new Error('HomeNavigationError'))
await delay(250)
Navigation.push(props.componentId, {
component: {
name: 'Details'
}
})
})()
}, [])

return (
<View style={ { flex: 1, alignItems: 'center', justifyContent: 'center' } }>
<Text>Home Screen</Text>
</View>
)
}

const DetailsScreen = (props) => {
useEffect(() => {
(async () => {
await delay(1000)
Bugsnag.notify(new Error('DetailsNavigationError'))
await delay(250)
throw new Error('DetailsNavigationUnhandledError')
})()
}, [])

return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
</View>
)
}

export class ReactNativeNavigationBreadcrumbsEnabledScenario extends Scenario {
constructor (configuration, jsConfig) {
super()
jsConfig.plugins = [new BugsnagReactNativeNavigation(Navigation)]
}

run () {
Navigation.registerComponent('Home', () => HomeScreen)
Navigation.registerComponent('Details', () => DetailsScreen)

Navigation.setRoot({
root: {
stack: {
Expand Down

0 comments on commit 147245f

Please sign in to comment.