25
25
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26
26
import { getNLUData } from '../plugins/functions' ;
27
27
28
+ const imageProcessingFeatures = [
29
+ 'feature_descriptive_text_generator' ,
30
+ 'feature_image_tags_generator' ,
31
+ 'feature_image_cropping' ,
32
+ 'feature_image_to_text_generator' ,
33
+ 'feature_image_generation' ,
34
+ 'feature_pdf_to_text_generation' ,
35
+ ] ;
36
+
28
37
/**
29
38
* Verify that the post has the expected taxonomy terms.
30
39
*
@@ -130,10 +139,22 @@ Cypress.Commands.add( 'optInAllFeatures', () => {
130
139
* @param {string } roles The roles to enable.
131
140
*/
132
141
Cypress . Commands . add ( 'enableFeatureForRoles' , ( feature , roles ) => {
142
+ let tab = 'language_processing' ;
143
+ if ( imageProcessingFeatures . includes ( feature ) ) {
144
+ tab = 'image_processing' ;
145
+ }
133
146
cy . visit (
134
- `/wp-admin/tools.php?page=classifai&tab=language_processing &feature=${ feature } `
147
+ `/wp-admin/tools.php?page=classifai&tab=${ tab } &feature=${ feature } `
135
148
) ;
136
- cy . get ( `#role_based_access` ) . check ( ) ;
149
+
150
+ // Disable access for all roles.
151
+ cy . get ( '.allowed_roles_row input[type="checkbox"]' ) . uncheck ( {
152
+ multiple : true ,
153
+ } ) ;
154
+
155
+ // Disable access for all users.
156
+ cy . disableFeatureForUsers ( ) ;
157
+
137
158
roles . forEach ( ( role ) => {
138
159
cy . get ( `#classifai_${ feature } _roles_${ role } ` ) . check ( ) ;
139
160
} ) ;
@@ -148,14 +169,22 @@ Cypress.Commands.add( 'enableFeatureForRoles', ( feature, roles ) => {
148
169
* @param {string } roles The roles to disable.
149
170
*/
150
171
Cypress . Commands . add ( 'disableFeatureForRoles' , ( feature , roles ) => {
172
+ let tab = 'language_processing' ;
173
+ if ( imageProcessingFeatures . includes ( feature ) ) {
174
+ tab = 'image_processing' ;
175
+ }
151
176
cy . visit (
152
- `/wp-admin/tools.php?page=classifai&tab=language_processing &feature=${ feature } `
177
+ `/wp-admin/tools.php?page=classifai&tab=${ tab } &feature=${ feature } `
153
178
) ;
154
179
cy . get ( '#status' ) . check ( ) ;
155
- cy . get ( `#role_based_access` ) . check ( ) ;
180
+
156
181
roles . forEach ( ( role ) => {
157
182
cy . get ( `#classifai_${ feature } _roles_${ role } ` ) . uncheck ( ) ;
158
183
} ) ;
184
+
185
+ // Disable access for all users.
186
+ cy . disableFeatureForUsers ( ) ;
187
+
159
188
cy . get ( '#submit' ) . click ( ) ;
160
189
cy . get ( '.notice' ) . contains ( 'Settings saved.' ) ;
161
190
} ) ;
@@ -167,22 +196,22 @@ Cypress.Commands.add( 'disableFeatureForRoles', ( feature, roles ) => {
167
196
* @param {string } users The users to enable.
168
197
*/
169
198
Cypress . Commands . add ( 'enableFeatureForUsers' , ( feature , users ) => {
199
+ let tab = 'language_processing' ;
200
+ if ( imageProcessingFeatures . includes ( feature ) ) {
201
+ tab = 'image_processing' ;
202
+ }
170
203
cy . visit (
171
- `/wp-admin/tools.php?page=classifai&tab=language_processing &feature=${ feature } `
204
+ `/wp-admin/tools.php?page=classifai&tab=${ tab } &feature=${ feature } `
172
205
) ;
173
- cy . get ( `#user_based_access` ) . check ( ) ;
174
- cy . wait ( 1000 ) ;
175
- cy . get ( '.allowed_users_row' ) . then ( ( $body ) => {
176
- if (
177
- $body . find ( `.components-form-token-field__remove-token` ) . length >
178
- 0
179
- ) {
180
- cy . get ( `.components-form-token-field__remove-token` ) . click ( {
181
- multiple : true ,
182
- } ) ;
183
- }
206
+
207
+ // Disable access for all roles.
208
+ cy . get ( 'tr.allowed_roles_row input[type="checkbox"]' ) . uncheck ( {
209
+ multiple : true ,
184
210
} ) ;
185
211
212
+ // Disable access for all users.
213
+ cy . disableFeatureForUsers ( ) ;
214
+
186
215
users . forEach ( ( user ) => {
187
216
cy . get (
188
217
`.allowed_users_row input.components-form-token-field__input`
@@ -194,18 +223,37 @@ Cypress.Commands.add( 'enableFeatureForUsers', ( feature, users ) => {
194
223
cy . get ( '.notice' ) . contains ( 'Settings saved.' ) ;
195
224
} ) ;
196
225
226
+ /**
227
+ * Disable user based access of all users for a feature.
228
+ */
229
+ Cypress . Commands . add ( 'disableFeatureForUsers' , ( ) => {
230
+ // Disable access for all users.
231
+ cy . get ( '.allowed_users_row' ) . then ( ( $body ) => {
232
+ if (
233
+ $body . find ( `.components-form-token-field__remove-token` ) . length >
234
+ 0
235
+ ) {
236
+ cy . get ( `.components-form-token-field__remove-token` ) . click ( {
237
+ multiple : true ,
238
+ } ) ;
239
+ }
240
+ } ) ;
241
+ } ) ;
242
+
197
243
/**
198
244
* Enable user based opt-out for a feature.
199
245
*
200
246
* @param {string } feature The feature to enable.
201
247
*/
202
248
Cypress . Commands . add ( 'enableFeatureOptOut' , ( feature ) => {
249
+ let tab = 'language_processing' ;
250
+ if ( imageProcessingFeatures . includes ( feature ) ) {
251
+ tab = 'image_processing' ;
252
+ }
203
253
cy . visit (
204
- `/wp-admin/tools.php?page=classifai&tab=language_processing &feature=${ feature } `
254
+ `/wp-admin/tools.php?page=classifai&tab=${ tab } &feature=${ feature } `
205
255
) ;
206
- cy . get ( `#role_based_access` ) . check ( ) ;
207
256
cy . get ( `#classifai_${ feature } _roles_administrator` ) . check ( ) ;
208
- cy . get ( `#user_based_access` ) . uncheck ( ) ;
209
257
cy . get ( `#user_based_opt_out` ) . check ( ) ;
210
258
211
259
cy . get ( '#submit' ) . click ( ) ;
0 commit comments