Переглянути джерело

ref(TestHint): render only in test mode

Adds the logic to render TestHint only when the test mode is enabled
in order to be able to put independent TestHints in other places than
the TestConnectionInfo component.
master
paweldomas 7 роки тому
джерело
коміт
adec8e6438

+ 32
- 0
react/features/base/testing/components/AbstractTestHint.js Переглянути файл

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
+import { isTestModeEnabled } from '../functions';
4
+
3
 /**
5
 /**
4
  * Describes the {@link TestHint}'s properties.
6
  * Describes the {@link TestHint}'s properties.
5
  *
7
  *
10
  */
12
  */
11
 export type TestHintProps = {
13
 export type TestHintProps = {
12
 
14
 
15
+    /**
16
+     * The indicator which determines whether the test mode is enabled.
17
+     * {@link TestHint} components are rendered only if this flag is set to
18
+     * {@code true}.
19
+     */
20
+    _testModeEnabled: boolean,
21
+
13
     /**
22
     /**
14
      * The test hint's identifier string. Must be unique in the app instance
23
      * The test hint's identifier string. Must be unique in the app instance
15
      * scope.
24
      * scope.
21
      */
30
      */
22
     value: string
31
     value: string
23
 }
32
 }
33
+
34
+/**
35
+ * Maps (parts of) the redux state to {@link TestHint}'s React {@code Component}
36
+ * props.
37
+ *
38
+ * @param {Object} state - The redux store/state.
39
+ * @private
40
+ * @returns {{
41
+ *     _testModeEnabled: boolean
42
+ * }}
43
+ */
44
+export function _mapStateToProps(state: Object) {
45
+    return {
46
+
47
+        /**
48
+         * The indicator which determines whether the test mode is enabled.
49
+         *
50
+         * @protected
51
+         * @type {boolean}
52
+         */
53
+        _testModeEnabled: isTestModeEnabled(state)
54
+    };
55
+}

+ 2
- 4
react/features/base/testing/components/TestConnectionInfo.js Переглянути файл

11
 import { statsEmitter } from '../../../connection-indicator';
11
 import { statsEmitter } from '../../../connection-indicator';
12
 
12
 
13
 import { TestHint } from './index';
13
 import { TestHint } from './index';
14
+import { isTestModeEnabled } from '../functions';
14
 
15
 
15
 /**
16
 /**
16
  * Defines the TestConnectionInfo's properties.
17
  * Defines the TestConnectionInfo's properties.
209
         = Boolean(state['features/base/conference'].conference);
210
         = Boolean(state['features/base/conference'].conference);
210
     const localParticipant = getLocalParticipant(state);
211
     const localParticipant = getLocalParticipant(state);
211
 
212
 
212
-    const testingConfig = state['features/base/config'].testing;
213
-    const testMode = Boolean(testingConfig && testingConfig.testMode);
214
-
215
     return {
213
     return {
216
         _conferenceConnectionState: state['features/testing'].connectionState,
214
         _conferenceConnectionState: state['features/testing'].connectionState,
217
         _conferenceJoinedState: conferenceJoined.toString(),
215
         _conferenceJoinedState: conferenceJoined.toString(),
218
         _localUserId: localParticipant && localParticipant.id,
216
         _localUserId: localParticipant && localParticipant.id,
219
-        _testMode: testMode
217
+        _testMode: isTestModeEnabled(state)
220
     };
218
     };
221
 }
219
 }
222
 
220
 

+ 9
- 1
react/features/base/testing/components/TestHint.android.js Переглянути файл

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
4
+import { connect } from 'react-redux';
4
 import { Text } from 'react-native';
5
 import { Text } from 'react-native';
5
 
6
 
6
 import type { TestHintProps } from './AbstractTestHint';
7
 import type { TestHintProps } from './AbstractTestHint';
8
+import { _mapStateToProps } from './AbstractTestHint';
7
 
9
 
8
 /**
10
 /**
9
  * The Android version of <code>TestHint</code>. It will put the identifier,
11
  * The Android version of <code>TestHint</code>. It will put the identifier,
22
  * the TestHint class is to be the abstraction layer which masks the problem by
24
  * the TestHint class is to be the abstraction layer which masks the problem by
23
  * exposing id and value properties.
25
  * exposing id and value properties.
24
  */
26
  */
25
-export default class TestHint extends Component<TestHintProps> {
27
+class TestHint extends Component<TestHintProps> {
26
 
28
 
27
     /**
29
     /**
28
      * Renders the test hint on Android.
30
      * Renders the test hint on Android.
30
      * @returns {ReactElement}
32
      * @returns {ReactElement}
31
      */
33
      */
32
     render() {
34
     render() {
35
+        if (!this.props._testModeEnabled) {
36
+            return null;
37
+        }
38
+
33
         return (
39
         return (
34
             <Text accessibilityLabel = { this.props.id } >
40
             <Text accessibilityLabel = { this.props.id } >
35
                 { this.props.value }
41
                 { this.props.value }
37
         );
43
         );
38
     }
44
     }
39
 }
45
 }
46
+
47
+export default connect(_mapStateToProps)(TestHint);

+ 9
- 1
react/features/base/testing/components/TestHint.ios.js Переглянути файл

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
4
+import { connect } from 'react-redux';
4
 import { Text } from 'react-native';
5
 import { Text } from 'react-native';
5
 
6
 
6
 import type { TestHintProps } from './AbstractTestHint';
7
 import type { TestHintProps } from './AbstractTestHint';
8
+import { _mapStateToProps } from './AbstractTestHint';
7
 
9
 
8
 /**
10
 /**
9
  * This is the iOS version of the TestHint.
11
  * This is the iOS version of the TestHint.
12
  * files to understand what a test hint is and why different iOS and Android
14
  * files to understand what a test hint is and why different iOS and Android
13
  * components are necessary.
15
  * components are necessary.
14
  */
16
  */
15
-export default class TestHint extends Component<TestHintProps> {
17
+class TestHint extends Component<TestHintProps> {
16
     /**
18
     /**
17
      *  Renders the test hint on Android.
19
      *  Renders the test hint on Android.
18
      *
20
      *
19
      * @returns {ReactElement}
21
      * @returns {ReactElement}
20
      */
22
      */
21
     render() {
23
     render() {
24
+        if (!this.props._testModeEnabled) {
25
+            return null;
26
+        }
27
+
22
         return (
28
         return (
23
             <Text
29
             <Text
24
                 accessibilityLabel = { this.props.value }
30
                 accessibilityLabel = { this.props.value }
26
         );
32
         );
27
     }
33
     }
28
 }
34
 }
35
+
36
+export default connect(_mapStateToProps)(TestHint);

+ 15
- 0
react/features/base/testing/functions.js Переглянути файл

1
+// @flow
2
+
3
+/**
4
+ * Indicates whether the test mode is enabled. When it's enabled
5
+ * {@link TestHint} and other components from the testing package will be
6
+ * rendered in various places across the app to help with automatic testing.
7
+ *
8
+ * @param {Object} state - The redux store state.
9
+ * @returns {boolean}
10
+ */
11
+export function isTestModeEnabled(state: Object): boolean {
12
+    const testingConfig = state['features/base/config'].testing;
13
+
14
+    return Boolean(testingConfig && testingConfig.testMode);
15
+}

+ 1
- 0
react/features/base/testing/index.js Переглянути файл

1
 export * from './components';
1
 export * from './components';
2
+export * from './functions';
2
 
3
 
3
 import './middleware';
4
 import './middleware';
4
 import './reducer';
5
 import './reducer';

Завантаження…
Відмінити
Зберегти