Skip to content

Commit c05789c

Browse files
committed
Update e2e tests.
1 parent 4ffe0ed commit c05789c

6 files changed

+99
-50
lines changed

tests/cypress/integration/admin/common-feature-fields.test.js

-17
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ describe('Common Feature Fields', () => {
3737
'name',
3838
`classifai_${ feature }[status]`
3939
);
40-
cy.get( '#role_based_access' ).should(
41-
'have.attr',
42-
'name',
43-
`classifai_${ feature }[role_based_access]`
44-
);
45-
cy.get( '#user_based_access' ).should(
46-
'have.attr',
47-
'name',
48-
`classifai_${ feature }[user_based_access]`
49-
);
5040
cy.get( '#user_based_opt_out' ).should(
5141
'have.attr',
5242
'name',
@@ -57,7 +47,6 @@ describe('Common Feature Fields', () => {
5747
'name',
5848
`classifai_${ feature }[provider]`
5949
);
60-
cy.get( '#role_based_access' ).check();
6150

6251
for ( const role of allowedRoles ) {
6352
if (
@@ -79,14 +68,8 @@ describe('Common Feature Fields', () => {
7968
);
8069
}
8170

82-
cy.get( '#role_based_access' ).uncheck();
83-
cy.get( '.allowed_roles_row' ).should( 'not.be.visible' );
84-
85-
cy.get( '#user_based_access' ).check();
8671
cy.get( '.allowed_users_row' ).should( 'be.visible' );
8772

88-
cy.get( '#user_based_access' ).uncheck();
89-
cy.get( '.allowed_users_row' ).should( 'not.be.visible' );
9073
} );
9174
} );
9275
} );

tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js

+30-10
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', ()
467467
cy.visit(
468468
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_classification'
469469
);
470-
cy.get( '#role_based_access' ).check();
471470
cy.get(
472471
'#classifai_feature_classification_roles_administrator'
473472
).uncheck();
@@ -482,7 +481,6 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', ()
482481
cy.visit(
483482
'/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu'
484483
);
485-
cy.get( '#role_based_access' ).check();
486484
cy.get(
487485
'#classifai_feature_classification_roles_administrator'
488486
).check();
@@ -499,8 +497,15 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', ()
499497
cy.visit(
500498
'/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu'
501499
);
502-
cy.get( '#role_based_access' ).uncheck();
503-
cy.get( '#user_based_access' ).uncheck();
500+
501+
// Disable access for all roles.
502+
cy.get( '.allowed_roles_row input[type="checkbox"]' ).uncheck( {
503+
multiple: true,
504+
} );
505+
506+
// Disable access for all users.
507+
cy.disableFeatureForUsers();
508+
504509
cy.get( '#submit' ).click();
505510
cy.get( '.notice' ).contains( 'Settings saved.' );
506511

@@ -511,8 +516,12 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', ()
511516
cy.visit(
512517
'/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu'
513518
);
514-
cy.get( '#role_based_access' ).uncheck();
515-
cy.get( '#user_based_access' ).check();
519+
520+
// Disable access for all roles.
521+
cy.get( '.allowed_roles_row input[type="checkbox"]' ).uncheck( {
522+
multiple: true,
523+
} );
524+
516525
cy.get( 'body' ).then( ( $body ) => {
517526
if (
518527
$body.find(
@@ -543,8 +552,14 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', ()
543552
cy.visit(
544553
'/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu'
545554
);
546-
cy.get( '#role_based_access' ).check();
547-
cy.get( '#user_based_access' ).uncheck();
555+
556+
// Enable access for all roles.
557+
cy.get( '.allowed_roles_row input[type="checkbox"]' ).check( {
558+
multiple: true,
559+
} );
560+
561+
// Disable access for all users.
562+
cy.disableFeatureForUsers();
548563

549564
cy.get( '#submit' ).click();
550565
cy.get( '.notice' ).contains( 'Settings saved.' );
@@ -555,8 +570,13 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', ()
555570
cy.visit(
556571
'/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu'
557572
);
558-
cy.get( '#role_based_access' ).check();
559-
cy.get( '#user_based_access' ).check();
573+
// Enable access for all roles.
574+
cy.get( '.allowed_roles_row input[type="checkbox"]' ).check( {
575+
multiple: true,
576+
} );
577+
578+
// Disable access for all users.
579+
cy.disableFeatureForUsers();
560580
cy.get( '#user_based_opt_out' ).check();
561581

562582
cy.get( '#submit' ).click();

tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => {
223223
'/wp-admin/tools.php?page=classifai&tab=language_processing'
224224
);
225225

226-
// Disable user-based access.
227-
cy.get( '#user_based_access' ).uncheck();
226+
// Disable access for all users.
227+
cy.disableFeatureForUsers();
228228

229229
cy.get( '#submit' ).click();
230230

tests/cypress/integration/language-processing/excerpt-generation-openapi-chatgpt.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ describe( '[Language processing] Excerpt Generation Tests', () => {
2727
cy.get( '#api_key' ).clear().type( 'password' );
2828

2929
cy.get( '#status' ).check();
30-
cy.get( '#role_based_access' ).check();
3130
cy.get(
3231
'#classifai_feature_excerpt_generation_roles_administrator'
3332
).check();

tests/cypress/integration/language-processing/moderation-openai-moderation.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe( '[Language processing] Moderation Tests', () => {
2323
cy.get(
2424
'#classifai_feature_moderation_content_types_comments'
2525
).check();
26-
cy.get( '#role_based_access' ).check();
2726
cy.get( '#classifai_feature_moderation_roles_administrator' ).check();
2827
cy.get( '#submit' ).click();
2928
} );

tests/cypress/support/commands.js

+67-19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
2626
import { getNLUData } from '../plugins/functions';
2727

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+
2837
/**
2938
* Verify that the post has the expected taxonomy terms.
3039
*
@@ -130,10 +139,22 @@ Cypress.Commands.add( 'optInAllFeatures', () => {
130139
* @param {string} roles The roles to enable.
131140
*/
132141
Cypress.Commands.add( 'enableFeatureForRoles', ( feature, roles ) => {
142+
let tab = 'language_processing';
143+
if ( imageProcessingFeatures.includes( feature ) ) {
144+
tab = 'image_processing';
145+
}
133146
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 }`
135148
);
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+
137158
roles.forEach( ( role ) => {
138159
cy.get( `#classifai_${ feature }_roles_${ role }` ).check();
139160
} );
@@ -148,14 +169,22 @@ Cypress.Commands.add( 'enableFeatureForRoles', ( feature, roles ) => {
148169
* @param {string} roles The roles to disable.
149170
*/
150171
Cypress.Commands.add( 'disableFeatureForRoles', ( feature, roles ) => {
172+
let tab = 'language_processing';
173+
if ( imageProcessingFeatures.includes( feature ) ) {
174+
tab = 'image_processing';
175+
}
151176
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 }`
153178
);
154179
cy.get( '#status' ).check();
155-
cy.get( `#role_based_access` ).check();
180+
156181
roles.forEach( ( role ) => {
157182
cy.get( `#classifai_${ feature }_roles_${ role }` ).uncheck();
158183
} );
184+
185+
// Disable access for all users.
186+
cy.disableFeatureForUsers();
187+
159188
cy.get( '#submit' ).click();
160189
cy.get( '.notice' ).contains( 'Settings saved.' );
161190
} );
@@ -167,22 +196,22 @@ Cypress.Commands.add( 'disableFeatureForRoles', ( feature, roles ) => {
167196
* @param {string} users The users to enable.
168197
*/
169198
Cypress.Commands.add( 'enableFeatureForUsers', ( feature, users ) => {
199+
let tab = 'language_processing';
200+
if ( imageProcessingFeatures.includes( feature ) ) {
201+
tab = 'image_processing';
202+
}
170203
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 }`
172205
);
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,
184210
} );
185211

212+
// Disable access for all users.
213+
cy.disableFeatureForUsers();
214+
186215
users.forEach( ( user ) => {
187216
cy.get(
188217
`.allowed_users_row input.components-form-token-field__input`
@@ -194,18 +223,37 @@ Cypress.Commands.add( 'enableFeatureForUsers', ( feature, users ) => {
194223
cy.get( '.notice' ).contains( 'Settings saved.' );
195224
} );
196225

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+
197243
/**
198244
* Enable user based opt-out for a feature.
199245
*
200246
* @param {string} feature The feature to enable.
201247
*/
202248
Cypress.Commands.add( 'enableFeatureOptOut', ( feature ) => {
249+
let tab = 'language_processing';
250+
if ( imageProcessingFeatures.includes( feature ) ) {
251+
tab = 'image_processing';
252+
}
203253
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 }`
205255
);
206-
cy.get( `#role_based_access` ).check();
207256
cy.get( `#classifai_${ feature }_roles_administrator` ).check();
208-
cy.get( `#user_based_access` ).uncheck();
209257
cy.get( `#user_based_opt_out` ).check();
210258

211259
cy.get( '#submit' ).click();

0 commit comments

Comments
 (0)