@@ -15,15 +15,14 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from "react" ;
18
- import { render , screen } from "@testing-library/react" ;
18
+ import { fireEvent , render , screen } from "@testing-library/react" ;
19
19
20
20
import LabsUserSettingsTab from "../../../../../../src/components/views/settings/tabs/user/LabsUserSettingsTab" ;
21
21
import SettingsStore from "../../../../../../src/settings/SettingsStore" ;
22
22
import SdkConfig from "../../../../../../src/SdkConfig" ;
23
+ import { SettingLevel } from "../../../../../../src/settings/SettingLevel" ;
23
24
24
25
describe ( "<LabsUserSettingsTab />" , ( ) => {
25
- const sdkConfigSpy = jest . spyOn ( SdkConfig , "get" ) ;
26
-
27
26
const defaultProps = {
28
27
closeSettingsFn : jest . fn ( ) ,
29
28
} ;
@@ -34,7 +33,9 @@ describe("<LabsUserSettingsTab />", () => {
34
33
beforeEach ( ( ) => {
35
34
jest . clearAllMocks ( ) ;
36
35
settingsValueSpy . mockReturnValue ( false ) ;
37
- sdkConfigSpy . mockReturnValue ( false ) ;
36
+ SdkConfig . reset ( ) ;
37
+ SdkConfig . add ( { brand : "BrandedClient" } ) ;
38
+ localStorage . clear ( ) ;
38
39
} ) ;
39
40
40
41
it ( "renders settings marked as beta as beta cards" , ( ) => {
@@ -43,6 +44,7 @@ describe("<LabsUserSettingsTab />", () => {
43
44
} ) ;
44
45
45
46
it ( "does not render non-beta labs settings when disabled in config" , ( ) => {
47
+ const sdkConfigSpy = jest . spyOn ( SdkConfig , "get" ) ;
46
48
render ( getComponent ( ) ) ;
47
49
expect ( sdkConfigSpy ) . toHaveBeenCalledWith ( "show_labs_settings" ) ;
48
50
@@ -52,12 +54,90 @@ describe("<LabsUserSettingsTab />", () => {
52
54
53
55
it ( "renders non-beta labs settings when enabled in config" , ( ) => {
54
56
// enable labs
55
- sdkConfigSpy . mockImplementation ( ( configName ) => configName === "show_labs_settings" ) ;
57
+ SdkConfig . add ( { show_labs_settings : true } ) ;
56
58
const { container } = render ( getComponent ( ) ) ;
57
59
58
60
// non-beta labs section
59
61
expect ( screen . getByText ( "Early previews" ) ) . toBeInTheDocument ( ) ;
60
62
const labsSections = container . getElementsByClassName ( "mx_SettingsSubsection" ) ;
61
63
expect ( labsSections ) . toHaveLength ( 9 ) ;
62
64
} ) ;
65
+
66
+ describe ( "Rust crypto setting" , ( ) => {
67
+ const SETTING_NAME = "Rust cryptography implementation" ;
68
+
69
+ beforeEach ( ( ) => {
70
+ SdkConfig . add ( { show_labs_settings : true } ) ;
71
+ } ) ;
72
+
73
+ describe ( "Not enabled in config" , ( ) => {
74
+ it ( "can be turned on if not already" , async ( ) => {
75
+ // By the time the settings panel is shown, `MatrixClientPeg.initClientCrypto` has saved the current
76
+ // value to the settings store.
77
+ await SettingsStore . setValue ( "feature_rust_crypto" , null , SettingLevel . DEVICE , false ) ;
78
+
79
+ const rendered = render ( getComponent ( ) ) ;
80
+ const toggle = rendered . getByRole ( "switch" , { name : SETTING_NAME } ) ;
81
+ expect ( toggle . getAttribute ( "aria-disabled" ) ) . toEqual ( "false" ) ;
82
+ expect ( toggle . getAttribute ( "aria-checked" ) ) . toEqual ( "false" ) ;
83
+
84
+ const description = toggle . closest ( ".mx_SettingsFlag" ) ?. querySelector ( ".mx_SettingsFlag_microcopy" ) ;
85
+ expect ( description ) . toHaveTextContent ( / T o d i s a b l e y o u w i l l n e e d t o l o g o u t a n d b a c k i n / ) ;
86
+ } ) ;
87
+
88
+ it ( "cannot be turned off once enabled" , async ( ) => {
89
+ await SettingsStore . setValue ( "feature_rust_crypto" , null , SettingLevel . DEVICE , true ) ;
90
+
91
+ const rendered = render ( getComponent ( ) ) ;
92
+ const toggle = rendered . getByRole ( "switch" , { name : SETTING_NAME } ) ;
93
+ expect ( toggle . getAttribute ( "aria-disabled" ) ) . toEqual ( "true" ) ;
94
+ expect ( toggle . getAttribute ( "aria-checked" ) ) . toEqual ( "true" ) ;
95
+
96
+ // Hover over the toggle to make it show the tooltip
97
+ fireEvent . mouseOver ( toggle ) ;
98
+
99
+ const tooltip = rendered . getByRole ( "tooltip" ) ;
100
+ expect ( tooltip ) . toHaveTextContent (
101
+ "Once enabled, Rust cryptography can only be disabled by logging out and in again" ,
102
+ ) ;
103
+ } ) ;
104
+ } ) ;
105
+
106
+ describe ( "Enabled in config" , ( ) => {
107
+ beforeEach ( ( ) => {
108
+ SdkConfig . add ( { features : { feature_rust_crypto : true } } ) ;
109
+ } ) ;
110
+
111
+ it ( "can be turned on if not already" , async ( ) => {
112
+ // By the time the settings panel is shown, `MatrixClientPeg.initClientCrypto` has saved the current
113
+ // value to the settings store.
114
+ await SettingsStore . setValue ( "feature_rust_crypto" , null , SettingLevel . DEVICE , false ) ;
115
+
116
+ const rendered = render ( getComponent ( ) ) ;
117
+ const toggle = rendered . getByRole ( "switch" , { name : SETTING_NAME } ) ;
118
+ expect ( toggle . getAttribute ( "aria-disabled" ) ) . toEqual ( "false" ) ;
119
+ expect ( toggle . getAttribute ( "aria-checked" ) ) . toEqual ( "false" ) ;
120
+
121
+ const description = toggle . closest ( ".mx_SettingsFlag" ) ?. querySelector ( ".mx_SettingsFlag_microcopy" ) ;
122
+ expect ( description ) . toHaveTextContent ( / I t c a n n o t b e d i s a b l e d / ) ;
123
+ } ) ;
124
+
125
+ it ( "cannot be turned off once enabled" , async ( ) => {
126
+ await SettingsStore . setValue ( "feature_rust_crypto" , null , SettingLevel . DEVICE , true ) ;
127
+
128
+ const rendered = render ( getComponent ( ) ) ;
129
+ const toggle = rendered . getByRole ( "switch" , { name : SETTING_NAME } ) ;
130
+ expect ( toggle . getAttribute ( "aria-disabled" ) ) . toEqual ( "true" ) ;
131
+ expect ( toggle . getAttribute ( "aria-checked" ) ) . toEqual ( "true" ) ;
132
+
133
+ // Hover over the toggle to make it show the tooltip
134
+ fireEvent . mouseOver ( toggle ) ;
135
+
136
+ const tooltip = rendered . getByRole ( "tooltip" ) ;
137
+ expect ( tooltip ) . toHaveTextContent (
138
+ "Rust cryptography cannot be disabled on this deployment of BrandedClient" ,
139
+ ) ;
140
+ } ) ;
141
+ } ) ;
142
+ } ) ;
63
143
} ) ;
0 commit comments