Skip to content

Commit

Permalink
E2E tests update to handle collapsed "User Permissions" panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Oct 18, 2024
1 parent 73150b5 commit 05fca00
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/js/settings/components/user-permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const UserPermissions = () => {
onToggle={ ( opened ) => {
setIsOpen( opened );
} }
className="classifai-settings__user-permissions"
>
<AllowedRoles />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down Expand Up @@ -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' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down
25 changes: 25 additions & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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( {
Expand All @@ -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( {
Expand All @@ -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 (
Expand All @@ -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();

Expand Down Expand Up @@ -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();
} );

0 comments on commit 05fca00

Please sign in to comment.