@@ -17,11 +17,17 @@ limitations under the License.
1717/// <reference types="cypress" />
1818
1919import Chainable = Cypress . Chainable ;
20+ import type { SettingLevel } from "../../src/settings/SettingLevel" ;
21+ import SettingsStore from "../../src/settings/SettingsStore" ;
2022
2123declare global {
2224 // eslint-disable-next-line @typescript-eslint/no-namespace
2325 namespace Cypress {
2426 interface Chainable {
27+ /**
28+ * Returns the SettingsStore
29+ */
30+ getSettingsStore ( ) : Chainable < typeof SettingsStore | undefined > ;
2531 /**
2632 * Open the top left user menu, returning a handle to the resulting context menu.
2733 */
@@ -63,10 +69,59 @@ declare global {
6369 * @param name the name of the beta to leave.
6470 */
6571 leaveBeta ( name : string ) : Chainable < JQuery < HTMLElement > > ;
72+
73+ /**
74+ * Sets the value for a setting. The room ID is optional if the
75+ * setting is not being set for a particular room, otherwise it
76+ * should be supplied. The value may be null to indicate that the
77+ * level should no longer have an override.
78+ * @param {string } settingName The name of the setting to change.
79+ * @param {String } roomId The room ID to change the value in, may be
80+ * null.
81+ * @param {SettingLevel } level The level to change the value at.
82+ * @param {* } value The new value of the setting, may be null.
83+ * @return {Promise } Resolves when the setting has been changed.
84+ */
85+ setSettingValue ( name : string , roomId : string , level : SettingLevel , value : any ) : Chainable < void > ;
86+
87+ /**
88+ * Gets the value of a setting. The room ID is optional if the
89+ * setting is not to be applied to any particular room, otherwise it
90+ * should be supplied.
91+ * @param {string } settingName The name of the setting to read the
92+ * value of.
93+ * @param {String } roomId The room ID to read the setting value in,
94+ * may be null.
95+ * @param {boolean } excludeDefault True to disable using the default
96+ * value.
97+ * @return {* } The value, or null if not found
98+ */
99+ getSettingValue < T > ( name : string , roomId ?: string ) : Chainable < T > ;
66100 }
67101 }
68102}
69103
104+ Cypress . Commands . add ( "getSettingsStore" , ( ) : Chainable < typeof SettingsStore > => {
105+ return cy . window ( { log : false } ) . then ( win => win . mxSettingsStore ) ;
106+ } ) ;
107+
108+ Cypress . Commands . add ( "setSettingValue" , (
109+ name : string ,
110+ roomId : string ,
111+ level : SettingLevel ,
112+ value : any ,
113+ ) : Chainable < void > => {
114+ return cy . getSettingsStore ( ) . then ( async ( store : typeof SettingsStore ) => {
115+ return store . setValue ( name , roomId , level , value ) ;
116+ } ) ;
117+ } ) ;
118+
119+ Cypress . Commands . add ( "getSettingValue" , < T = any > ( name : string , roomId ?: string ) : Chainable < T > => {
120+ return cy . getSettingsStore ( ) . then ( < T > ( store : typeof SettingsStore ) => {
121+ return store . getValue < T > ( name , roomId ) ;
122+ } ) ;
123+ } ) ;
124+
70125Cypress . Commands . add ( "openUserMenu" , ( ) : Chainable < JQuery < HTMLElement > > => {
71126 cy . get ( '[aria-label="User menu"]' ) . click ( ) ;
72127 return cy . get ( ".mx_ContextualMenu" ) ;
0 commit comments