瀏覽代碼

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,5 +1,7 @@
1 1
 /* @flow */
2 2
 
3
+import { isTestModeEnabled } from '../functions';
4
+
3 5
 /**
4 6
  * Describes the {@link TestHint}'s properties.
5 7
  *
@@ -10,6 +12,13 @@
10 12
  */
11 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 23
      * The test hint's identifier string. Must be unique in the app instance
15 24
      * scope.
@@ -21,3 +30,26 @@ export type TestHintProps = {
21 30
      */
22 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,6 +11,7 @@ import { getLocalParticipant } from '../../participants';
11 11
 import { statsEmitter } from '../../../connection-indicator';
12 12
 
13 13
 import { TestHint } from './index';
14
+import { isTestModeEnabled } from '../functions';
14 15
 
15 16
 /**
16 17
  * Defines the TestConnectionInfo's properties.
@@ -209,14 +210,11 @@ function _mapStateToProps(state) {
209 210
         = Boolean(state['features/base/conference'].conference);
210 211
     const localParticipant = getLocalParticipant(state);
211 212
 
212
-    const testingConfig = state['features/base/config'].testing;
213
-    const testMode = Boolean(testingConfig && testingConfig.testMode);
214
-
215 213
     return {
216 214
         _conferenceConnectionState: state['features/testing'].connectionState,
217 215
         _conferenceJoinedState: conferenceJoined.toString(),
218 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,9 +1,11 @@
1 1
 /* @flow */
2 2
 
3 3
 import React, { Component } from 'react';
4
+import { connect } from 'react-redux';
4 5
 import { Text } from 'react-native';
5 6
 
6 7
 import type { TestHintProps } from './AbstractTestHint';
8
+import { _mapStateToProps } from './AbstractTestHint';
7 9
 
8 10
 /**
9 11
  * The Android version of <code>TestHint</code>. It will put the identifier,
@@ -22,7 +24,7 @@ import type { TestHintProps } from './AbstractTestHint';
22 24
  * the TestHint class is to be the abstraction layer which masks the problem by
23 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 30
      * Renders the test hint on Android.
@@ -30,6 +32,10 @@ export default class TestHint extends Component<TestHintProps> {
30 32
      * @returns {ReactElement}
31 33
      */
32 34
     render() {
35
+        if (!this.props._testModeEnabled) {
36
+            return null;
37
+        }
38
+
33 39
         return (
34 40
             <Text accessibilityLabel = { this.props.id } >
35 41
                 { this.props.value }
@@ -37,3 +43,5 @@ export default class TestHint extends Component<TestHintProps> {
37 43
         );
38 44
     }
39 45
 }
46
+
47
+export default connect(_mapStateToProps)(TestHint);

+ 9
- 1
react/features/base/testing/components/TestHint.ios.js 查看文件

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

+ 15
- 0
react/features/base/testing/functions.js 查看文件

@@ -0,0 +1,15 @@
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,4 +1,5 @@
1 1
 export * from './components';
2
+export * from './functions';
2 3
 
3 4
 import './middleware';
4 5
 import './reducer';

Loading…
取消
儲存