From c43bcff033de25b416443832c8be6ea40babae05 Mon Sep 17 00:00:00 2001 From: Yousif Ahmed Date: Fri, 13 Sep 2024 14:07:31 +0100 Subject: [PATCH] launch navigation scenarios via commands --- .../app/react_navigation_js/app/App.js | 199 ++---------------- .../app/lib/CommandRunner.js | 38 ++++ .../app/lib/ConfigFileReader.js | 32 +++ .../app/lib/ScenarioLauncher.js | 101 +++++++++ ...ctNavigationBreadcrumbsDisabledScenario.js | 28 ++- ...actNavigationBreadcrumbsEnabledScenario.js | 28 ++- test/react-native/features/navigation.feature | 8 +- 7 files changed, 226 insertions(+), 208 deletions(-) create mode 100644 test/react-native/features/fixtures/app/react_navigation_js/app/lib/CommandRunner.js create mode 100644 test/react-native/features/fixtures/app/react_navigation_js/app/lib/ConfigFileReader.js create mode 100644 test/react-native/features/fixtures/app/react_navigation_js/app/lib/ScenarioLauncher.js diff --git a/test/react-native/features/fixtures/app/react_navigation_js/app/App.js b/test/react-native/features/fixtures/app/react_navigation_js/app/App.js index b72e94ef63..7fd9986db5 100644 --- a/test/react-native/features/fixtures/app/react_navigation_js/app/App.js +++ b/test/react-native/features/fixtures/app/react_navigation_js/app/App.js @@ -1,200 +1,35 @@ -import React, { Component } from 'react' -import Bugsnag from '@bugsnag/react-native' -import BugsnagPluginReactNavigation from '@bugsnag/plugin-react-navigation' -import { NavigationContainer } from '@react-navigation/native' -import * as Scenarios from './Scenarios' +import React, { useState, useEffect } from 'react' import { View, Text, - TextInput, - Button, StyleSheet, - NativeModules + SafeAreaView } from 'react-native' -const defaultJsConfig = () => ({ - plugins: [new BugsnagPluginReactNavigation()] -}) - -export default class App extends Component { - constructor (props) { - super(props) - this.state = { - currentScenario: '', - apiKey: '12312312312312312312312312312312', - notifyEndpoint: '', - sessionsEndpoint: '', - scenario: null, - bugsnagStarted: false - } - } - - getConfiguration = () => { - var config = { - apiKey: this.state.apiKey, - autoTrackSessions: false - } - - if (this.state.notifyEndpoint && this.state.sessionsEndpoint) { - config.endpoints = { - notify: this.state.notifyEndpoint, - sessions: this.state.sessionsEndpoint - } - } - return config - } - - setScenario = newScenario => { - this.setState(() => ({ currentScenario: newScenario })) - } - - setApiKey = newApiKey => { - this.setState(() => ({ apiKey: newApiKey })) - } - - setNotifyEndpoint = newNotifyEndpoint => { - this.setState(() => ({ notifyEndpoint: newNotifyEndpoint })) - } - - setSessionsEndpoint = newSessionsEndpoint => { - this.setState(() => ({ sessionsEndpoint: newSessionsEndpoint })) - } - - useRealEndpoints = () => { - this.setState({ notifyEndpoint: 'https://notify.bugsnag.com' }) - this.setState({ sessionsEndpoint: 'https://sessions.bugsnag.com' }) - } - - clearPersistentData = () => { - NativeModules.BugsnagTestInterface.clearPersistentData() - } - - pollBugsnagStarted = () => { - setTimeout(() => { - if (Bugsnag.isStarted()) { - this.setState(() => ({ bugsnagStarted: true })) - } else { - this.pollBugsnagStarted() - } - }, 50) - } +import { launchScenario } from './lib/ScenarioLauncher' - startScenario = () => { - console.log(`Running scenario: ${this.state.currentScenario}`) - const scenarioName = this.state.currentScenario - const configuration = this.getConfiguration() - const jsConfig = defaultJsConfig() - const scenario = new Scenarios[scenarioName](configuration, jsConfig) - console.log(` with config: ${JSON.stringify(configuration)} (native) and ${JSON.stringify(jsConfig)} (js)`) - this.setState({ scenario: scenario }) - this.pollBugsnagStarted() - scenario.run() - } +const App = () => { + const [scenario, setScenario] = useState(null) - startBugsnag = () => { - console.log(`Starting Bugsnag for scenario: ${this.state.currentScenario}`) - const scenarioName = this.state.currentScenario - const configuration = this.getConfiguration() - const jsConfig = defaultJsConfig() - // eslint-disable-next-line no-new - new Scenarios[scenarioName](configuration, jsConfig) - console.log(` with config: ${JSON.stringify(configuration)} (native) and ${JSON.stringify(jsConfig)} (js)`) - NativeModules.BugsnagTestInterface.startBugsnag(configuration) - .then(() => { - Bugsnag.start(jsConfig) - }) - } + useEffect(() => { + launchScenario(setScenario) + }, []) - waiting () { - return ( - - + return ( + scenario ? scenario() : ( + + React Navigation Test App - - -