diff --git a/src/js/settings/components/user-permissions/index.js b/src/js/settings/components/user-permissions/index.js index 4d16ab948..033ae379a 100644 --- a/src/js/settings/components/user-permissions/index.js +++ b/src/js/settings/components/user-permissions/index.js @@ -39,6 +39,7 @@ export const UserPermissions = () => { onToggle={ ( opened ) => { setIsOpen( opened ); } } + className="classifai-settings__user-permissions" > diff --git a/tests/cypress/integration/admin/common-feature-fields.test.js b/tests/cypress/integration/admin/common-feature-fields.test.js index 08e1ddf44..fb3ea9f61 100644 --- a/tests/cypress/integration/admin/common-feature-fields.test.js +++ b/tests/cypress/integration/admin/common-feature-fields.test.js @@ -27,6 +27,7 @@ describe( 'Common Feature Fields', () => { cy.get( '.classifai-enable-feature-toggle input' ).should( 'exist' ); + cy.openUserPermissionsPanel(); cy.get( '.classifai-settings__user-based-opt-out input[type="checkbox"]' ).should( 'exist' ); diff --git a/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js b/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js index 81ec40843..bdd789930 100644 --- a/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js +++ b/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js @@ -21,7 +21,7 @@ describe( 'Image Generation (OpenAI DALL·E) Tests', () => { cy.get( 'select#openai_dalle_image_size' ).select( '1024x1792' ); cy.get( 'select#openai_dalle_style' ).select( 'natural' ); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); } ); @@ -113,7 +113,7 @@ describe( 'Image Generation (OpenAI DALL·E) Tests', () => { cy.visitFeatureSettings( 'image_processing/feature_image_generation' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); cy.visit( '/wp-admin/upload.php' ); diff --git a/tests/cypress/integration/image-processing/image-processing-microsoft-azure.test.js b/tests/cypress/integration/image-processing/image-processing-microsoft-azure.test.js index 79a53a4be..1d0fd3af1 100644 --- a/tests/cypress/integration/image-processing/image-processing-microsoft-azure.test.js +++ b/tests/cypress/integration/image-processing/image-processing-microsoft-azure.test.js @@ -23,7 +23,7 @@ describe( 'Image processing Tests', () => { .clear() .type( 'http://e2e-test-image-processing.test' ); cy.get( '#ms_computer_vision_api_key' ).clear().type( 'password' ); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.get( '.classifai-settings__user-based-opt-out input' ).uncheck(); // Disable access for all users. cy.disableFeatureForUsers(); diff --git a/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js b/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js index 963ec47ad..4af11d6f5 100644 --- a/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js +++ b/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js @@ -31,7 +31,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { cy.get( 'input#azure_openai_deployment' ).clear().type( 'test' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.get( '#excerpt_length' ).clear().type( 35 ); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js b/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js index eedf31ec9..818423627 100644 --- a/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js +++ b/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js @@ -29,7 +29,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { .type( 'password' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.get( '#excerpt_length' ).clear().type( 35 ); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/integration/language-processing/excerpt-generation-openai-chatgpt.test.js b/tests/cypress/integration/language-processing/excerpt-generation-openai-chatgpt.test.js index 66b3652f3..021a7d349 100644 --- a/tests/cypress/integration/language-processing/excerpt-generation-openai-chatgpt.test.js +++ b/tests/cypress/integration/language-processing/excerpt-generation-openai-chatgpt.test.js @@ -27,7 +27,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { cy.get( '#openai_chatgpt_api_key' ).clear().type( 'password' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.get( '#excerpt_length' ).clear().type( 35 ); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/integration/language-processing/moderation-openai-moderation.test.js b/tests/cypress/integration/language-processing/moderation-openai-moderation.test.js index 379679b2b..88d728435 100644 --- a/tests/cypress/integration/language-processing/moderation-openai-moderation.test.js +++ b/tests/cypress/integration/language-processing/moderation-openai-moderation.test.js @@ -18,7 +18,7 @@ describe( '[Language processing] Moderation Tests', () => { cy.get( '#openai_api_key' ).clear().type( 'password' ); cy.enableFeature(); cy.get( '.settings-moderation-content-types input#comments' ).check(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/integration/language-processing/resize_content-azure-openai.test.js b/tests/cypress/integration/language-processing/resize_content-azure-openai.test.js index 0431cc4ba..f4540e258 100644 --- a/tests/cypress/integration/language-processing/resize_content-azure-openai.test.js +++ b/tests/cypress/integration/language-processing/resize_content-azure-openai.test.js @@ -26,7 +26,7 @@ describe( '[Language processing] Resize Content Tests', () => { ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); cy.createPost( { diff --git a/tests/cypress/integration/language-processing/resize_content-googleai-gemini-api.test.js b/tests/cypress/integration/language-processing/resize_content-googleai-gemini-api.test.js index 47ec02c0d..b332db229 100644 --- a/tests/cypress/integration/language-processing/resize_content-googleai-gemini-api.test.js +++ b/tests/cypress/integration/language-processing/resize_content-googleai-gemini-api.test.js @@ -22,7 +22,7 @@ describe( '[Language processing] Resize Content Tests', () => { ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); cy.createPost( { diff --git a/tests/cypress/integration/language-processing/resize_content-openai-chatgpt.test.js b/tests/cypress/integration/language-processing/resize_content-openai-chatgpt.test.js index 33a061b9c..182f4330f 100644 --- a/tests/cypress/integration/language-processing/resize_content-openai-chatgpt.test.js +++ b/tests/cypress/integration/language-processing/resize_content-openai-chatgpt.test.js @@ -22,7 +22,7 @@ describe( '[Language processing] Resize Content Tests', () => { ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); cy.createPost( { diff --git a/tests/cypress/integration/language-processing/smart-404-azure-openai.test.js b/tests/cypress/integration/language-processing/smart-404-azure-openai.test.js index cd275497c..fa108db78 100644 --- a/tests/cypress/integration/language-processing/smart-404-azure-openai.test.js +++ b/tests/cypress/integration/language-processing/smart-404-azure-openai.test.js @@ -45,7 +45,7 @@ describe( '[Language processing] Smart 404 - Azure OpenAI Tests', () => { cy.get( '#feature_smart_404_rescore' ).uncheck(); cy.get( '#feature_smart_404_fallback' ).check(); cy.get( '#feature_smart_404_score_function' ).select( 'l1_norm' ); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); // Save settings. cy.saveFeatureSettings(); diff --git a/tests/cypress/integration/language-processing/smart-404-openai.test.js b/tests/cypress/integration/language-processing/smart-404-openai.test.js index 9f7a1a9c8..c3a5ae384 100644 --- a/tests/cypress/integration/language-processing/smart-404-openai.test.js +++ b/tests/cypress/integration/language-processing/smart-404-openai.test.js @@ -37,7 +37,7 @@ describe( '[Language processing] Smart 404 - OpenAI Tests', () => { cy.get( '#feature_smart_404_rescore' ).check(); cy.get( '#feature_smart_404_fallback' ).uncheck(); cy.get( '#feature_smart_404_score_function' ).select( 'dot_product' ); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); // Save settings. cy.saveFeatureSettings(); diff --git a/tests/cypress/integration/language-processing/speech-to-text-openai-whisper.test.js b/tests/cypress/integration/language-processing/speech-to-text-openai-whisper.test.js index 159b61c11..0d8e5e624 100644 --- a/tests/cypress/integration/language-processing/speech-to-text-openai-whisper.test.js +++ b/tests/cypress/integration/language-processing/speech-to-text-openai-whisper.test.js @@ -24,7 +24,7 @@ describe( '[Language processing] Speech to Text Tests', () => { cy.get( '#openai_api_key' ).clear().type( 'password' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js b/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js index 99cebbac5..c9a3b164a 100644 --- a/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js +++ b/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js @@ -25,7 +25,7 @@ describe( '[Language processing] Title Generation Tests', () => { cy.get( 'input#azure_openai_deployment' ).clear().type( 'test' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.get( '#azure_openai_number_of_suggestions' ).clear().type( 1 ); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js b/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js index 6a6d6da89..002318f45 100644 --- a/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js +++ b/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js @@ -21,7 +21,7 @@ describe( '[Language processing] Title Generation Tests', () => { .clear() .type( 'password' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/integration/language-processing/title-generation-openai-chatgpt.test.js b/tests/cypress/integration/language-processing/title-generation-openai-chatgpt.test.js index c97be6512..eec4b5283 100644 --- a/tests/cypress/integration/language-processing/title-generation-openai-chatgpt.test.js +++ b/tests/cypress/integration/language-processing/title-generation-openai-chatgpt.test.js @@ -19,7 +19,7 @@ describe( '[Language processing] Title Generation Tests', () => { cy.selectProvider( 'openai_chatgpt' ); cy.get( '#openai_chatgpt_api_key' ).clear().type( 'password' ); cy.enableFeature(); - cy.get( '.settings-allowed-roles input#administrator' ).check(); + cy.allowFeatureToAdmin(); cy.get( '#openai_chatgpt_number_of_suggestions' ).type( 1 ); cy.saveFeatureSettings(); } ); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 9c3466d8a..4bc718ac9 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -146,6 +146,8 @@ Cypress.Commands.add( 'enableFeatureForRoles', ( feature, roles ) => { cy.visitFeatureSettings( `${ tab }/${ feature }` ); cy.get( '#classifai-logo' ).should( 'exist' ); + cy.openUserPermissionsPanel(); + // Disable access for all roles. cy.get( '.settings-allowed-roles input[type="checkbox"]' ).uncheck( { multiple: true, @@ -175,6 +177,7 @@ Cypress.Commands.add( 'disableFeatureForRoles', ( feature, roles ) => { cy.visitFeatureSettings( `${ tab }/${ feature }` ); cy.wait( 100 ); cy.enableFeature(); + cy.openUserPermissionsPanel(); roles.forEach( ( role ) => { cy.get( `.settings-allowed-roles input#${ role }` ).uncheck( { @@ -200,6 +203,7 @@ Cypress.Commands.add( 'enableFeatureForUsers', ( feature, users ) => { tab = 'image_processing'; } cy.visitFeatureSettings( `${ tab }/${ feature }` ); + cy.openUserPermissionsPanel(); // Disable access for all roles. cy.get( '.settings-allowed-roles input[type="checkbox"]' ).uncheck( { @@ -223,6 +227,7 @@ Cypress.Commands.add( 'enableFeatureForUsers', ( feature, users ) => { * Disable user based access of all users for a feature. */ Cypress.Commands.add( 'disableFeatureForUsers', () => { + cy.openUserPermissionsPanel(); // Disable access for all users. cy.get( '.classifai-settings__users' ).then( ( $body ) => { if ( @@ -248,6 +253,7 @@ Cypress.Commands.add( 'enableFeatureOptOut', ( feature ) => { } cy.visitFeatureSettings( `${ tab }/${ feature }` ); cy.wait( 100 ); + cy.openUserPermissionsPanel(); cy.get( '.settings-allowed-roles input#administrator' ).check(); cy.get( '.classifai-settings__user-based-opt-out input' ).check(); @@ -643,3 +649,22 @@ Cypress.Commands.add( 'visitFeatureSettings', ( featurePath ) => { cy.get( '.components-panel__header h2' ).should( 'exist' ); } } ); + +Cypress.Commands.add( 'openUserPermissionsPanel', () => { + cy.get( + '.components-panel__body.classifai-settings__user-permissions button' + ).then( ( $panelButton ) => { + // Find the panel container. + const $panel = $panelButton.parents( '.components-panel__body' ); + + // Open panel. + if ( ! $panel.hasClass( 'is-opened' ) ) { + cy.wrap( $panelButton ).click(); + } + } ); +} ); + +Cypress.Commands.add( 'allowFeatureToAdmin', () => { + cy.openUserPermissionsPanel(); + cy.get( '.settings-allowed-roles input#administrator' ).check(); +} );