Skip to content

Commit

Permalink
Improvement in E2E tests and fix E2E tests for WP minimum environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Sep 18, 2024
1 parent 7944d43 commit 121968f
Show file tree
Hide file tree
Showing 26 changed files with 230 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const ImageTagGeneratorSettings = () => {
return (
<SettingsRow label={ __( 'Tag taxonomy', 'classifai' ) }>
<SelectControl
id="feature_image_tags_generator_tag_taxonomy"
onChange={ ( value ) => {
setFeatureSettings( {
tag_taxonomy: value,
Expand Down
8 changes: 3 additions & 5 deletions tests/cypress/integration/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ describe( 'Admin can login and make sure plugin is activated', () => {

it( 'Can visit "Language Processing" settings page.', () => {
// Check Selected Navigation menu
cy.visit(
'/wp-admin/tools.php?page=classifai#/language_processing/feature_classification'
);
cy.visitFeatureSettings( 'language_processing/feature_classification' );
cy.get( '.classifai-tabs' ).should( 'exist' );
cy.get( '.classifai-tabs a.active-tab' )
.first()
Expand All @@ -36,8 +34,8 @@ describe( 'Admin can login and make sure plugin is activated', () => {

it( 'Can see "Image Processing" menu and Can visit "Image Processing" settings page.', () => {
// Check Selected Navigation menu
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_descriptive_text_generator'
cy.visitFeatureSettings(
'image_processing/feature_descriptive_text_generator'
);
cy.get( '.classifai-tabs' ).should( 'exist' );
cy.get( '.classifai-tabs a.active-tab' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ describe( 'Common Feature Fields', () => {

Object.keys( features ).forEach( ( feature ) => {
it( `"${ features[ feature ] }" feature common fields`, () => {
cy.visit(
`/wp-admin/tools.php?page=classifai#/language_processing/${ feature }`
);
cy.visitFeatureSettings( `language_processing/${ feature }` );

cy.get( '.classifai-enable-feature-toggle input' ).should(
'exist'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
describe( 'Image Generation (OpenAI DALL·E) Tests', () => {
before( () => {
cy.login();
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_generation'
);
cy.visitFeatureSettings( 'image_processing/feature_image_generation' );
cy.enableFeature();
cy.selectProvider( 'openai_dalle' );
cy.saveFeatureSettings();
Expand All @@ -15,9 +13,7 @@ describe( 'Image Generation (OpenAI DALL·E) Tests', () => {
} );

it( 'Can save OpenAI "Image Processing" settings', () => {
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_generation'
);
cy.visitFeatureSettings( 'image_processing/feature_image_generation' );
cy.selectProvider( 'openai_dalle' );
cy.get( '#openai_dalle_api_key' ).clear().type( 'password' );
cy.get( 'select#openai_dalle_number_of_images' ).select( '2' );
Expand Down Expand Up @@ -97,19 +93,15 @@ describe( 'Image Generation (OpenAI DALL·E) Tests', () => {

it( 'Can enable/disable image generation feature', () => {
// Disable feature.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_generation'
);
cy.visitFeatureSettings( 'image_processing/feature_image_generation' );
cy.disableFeature();
cy.saveFeatureSettings();

// Verify that the feature is not available.
cy.verifyImageGenerationEnabled( false );

// Enable feature.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_generation'
);
cy.visitFeatureSettings( 'image_processing/feature_image_generation' );
cy.enableFeature();
cy.saveFeatureSettings();

Expand All @@ -118,9 +110,7 @@ describe( 'Image Generation (OpenAI DALL·E) Tests', () => {
} );

it( 'Can generate image directly in media library', () => {
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_generation'
);
cy.visitFeatureSettings( 'image_processing/feature_image_generation' );

cy.enableFeature();
cy.get( '.settings-allowed-roles input#administrator' ).check();
Expand All @@ -145,9 +135,7 @@ describe( 'Image Generation (OpenAI DALL·E) Tests', () => {

it( 'Can enable/disable image generation feature by role', () => {
// Enable feature.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_generation'
);
cy.visitFeatureSettings( 'image_processing/feature_image_generation' );
cy.enableFeature();
cy.saveFeatureSettings();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ describe( 'Image processing Tests', () => {
];

imageProcessingFeatures.forEach( ( feature ) => {
cy.visit(
`/wp-admin/tools.php?page=classifai#/image_processing/${ feature }`
);
cy.visitFeatureSettings( `image_processing/${ feature }` );
cy.enableFeature();
cy.selectProvider( 'ms_computer_vision' );
cy.get( '#ms_computer_vision_endpoint_url' )
.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.get( '.classifai-settings__user-based-opt-out input' ).uncheck();
// Disable access for all users.
cy.disableFeatureForUsers();

cy.saveFeatureSettings();
} );

Expand All @@ -37,8 +39,8 @@ describe( 'Image processing Tests', () => {
} );

it( 'Can see Azure AI Vision Image processing actions on edit media page and verify Generated data.', () => {
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_descriptive_text_generator'
cy.visitFeatureSettings(
'image_processing/feature_descriptive_text_generator'
);
cy.get( '.classifai-descriptive-text-fields input#alt' ).check();
cy.saveFeatureSettings();
Expand Down Expand Up @@ -113,74 +115,74 @@ describe( 'Image processing Tests', () => {
};

// Disable features
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_descriptive_text_generator'
cy.visitFeatureSettings(
'image_processing/feature_descriptive_text_generator'
);
cy.wait( 1000 );
cy.get( '.classifai-descriptive-text-fields input#alt' ).uncheck();
cy.get( '.classifai-descriptive-text-fields input#caption' ).uncheck();
cy.get(
'.classifai-descriptive-text-fields input#description'
).uncheck();
cy.saveFeatureSettings();

cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_tags_generator'
cy.visitFeatureSettings(
'image_processing/feature_image_tags_generator'
);
cy.wait( 1000 );
cy.disableFeature();
cy.saveFeatureSettings();

cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_cropping'
);
cy.visitFeatureSettings( 'image_processing/feature_image_cropping' );
cy.wait( 1000 );
cy.disableFeature();
cy.saveFeatureSettings();

cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_to_text_generator'
cy.visitFeatureSettings(
'image_processing/feature_image_to_text_generator'
);
cy.wait( 1000 );
cy.wait( 1500 ); // Add delay to avoid flaky test in WP minimum (6.1) environment.
cy.disableFeature();
cy.saveFeatureSettings();

// Verify that the feature is not available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( false, options );

// Enable features.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_descriptive_text_generator'
cy.visitFeatureSettings(
'image_processing/feature_descriptive_text_generator'
);
cy.get( '.classifai-descriptive-text-fields input#alt' ).check();
cy.get( '.classifai-descriptive-text-fields input#caption' ).check();
cy.get(
'.classifai-descriptive-text-fields input#description'
).check();
cy.wait( 1500 );
cy.enableFeature();
cy.saveFeatureSettings();

cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_tags_generator'
cy.visitFeatureSettings(
'image_processing/feature_image_tags_generator'
);
cy.wait( 1000 );
cy.wait( 1500 );
cy.enableFeature();
cy.saveFeatureSettings();

cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_cropping'
);
cy.wait( 1000 );
cy.visitFeatureSettings( 'image_processing/feature_image_cropping' );
cy.wait( 1500 );
cy.enableFeature();
cy.saveFeatureSettings();

cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_image_to_text_generator'
cy.visitFeatureSettings(
'image_processing/feature_image_to_text_generator'
);
cy.wait( 1000 );
cy.wait( 1500 );
cy.enableFeature();
cy.saveFeatureSettings();

// Verify that the feature is available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( true, options );
} );

Expand All @@ -191,11 +193,12 @@ describe( 'Image processing Tests', () => {
};

// Enable features.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_descriptive_text_generator'
cy.visitFeatureSettings(
'image_processing/feature_descriptive_text_generator'
);
cy.get( '.classifai-descriptive-text-fields input#alt' ).check();
cy.enableFeature();
cy.get( '.classifai-descriptive-text-fields input#alt' ).check();
cy.wait( 500 );
cy.saveFeatureSettings();

// Disable access to admin role.
Expand All @@ -213,6 +216,7 @@ describe( 'Image processing Tests', () => {
] );

// Verify that the feature is not available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( false, options );

// Enable access to admin role.
Expand All @@ -230,6 +234,7 @@ describe( 'Image processing Tests', () => {
] );

// Verify that the feature is available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( true, options );
} );

Expand All @@ -254,6 +259,7 @@ describe( 'Image processing Tests', () => {
] );

// Verify that the feature is not available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( false, options );

cy.enableFeatureForUsers( 'feature_descriptive_text_generator', [
Expand All @@ -266,6 +272,7 @@ describe( 'Image processing Tests', () => {
] );

// Verify that the feature is available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( true, options );
} );

Expand All @@ -288,6 +295,7 @@ describe( 'Image processing Tests', () => {
cy.optOutFeature( 'feature_image_to_text_generator' );

// Verify that the feature is not available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( false, options );

// opt-in
Expand All @@ -297,6 +305,7 @@ describe( 'Image processing Tests', () => {
cy.optInFeature( 'feature_image_to_text_generator' );

// Verify that the feature is available.
cy.wait( 1000 );
cy.verifyAIVisionEnabled( true, options );
} );
} );
20 changes: 10 additions & 10 deletions tests/cypress/integration/image-processing/pdf-read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { getPDFData } from '../../plugins/functions';
describe( 'PDF read Tests', () => {
before( () => {
cy.login();
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_pdf_to_text_generation'
cy.visitFeatureSettings(
'image_processing/feature_pdf_to_text_generation'
);
cy.enableFeature();
cy.saveFeatureSettings();
Expand All @@ -17,8 +17,8 @@ describe( 'PDF read Tests', () => {

let pdfEditLink = '';
it( 'Can save "PDF scanning" settings', () => {
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_pdf_to_text_generation'
cy.visitFeatureSettings(
'image_processing/feature_pdf_to_text_generation'
);
cy.selectProvider( 'ms_computer_vision' );
cy.get( '#ms_computer_vision_endpoint_url' )
Expand Down Expand Up @@ -60,8 +60,8 @@ describe( 'PDF read Tests', () => {

it( 'Can enable/disable PDF scanning feature', () => {
// Disable feature.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_pdf_to_text_generation'
cy.visitFeatureSettings(
'image_processing/feature_pdf_to_text_generation'
);
cy.disableFeature();
cy.saveFeatureSettings();
Expand All @@ -73,8 +73,8 @@ describe( 'PDF read Tests', () => {
);

// Enable admin role.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_pdf_to_text_generation'
cy.visitFeatureSettings(
'image_processing/feature_pdf_to_text_generation'
);
cy.enableFeature();
cy.saveFeatureSettings();
Expand All @@ -88,8 +88,8 @@ describe( 'PDF read Tests', () => {

it( 'Can enable/disable PDF scanning feature by role', () => {
// Enable feature.
cy.visit(
'/wp-admin/tools.php?page=classifai#/image_processing/feature_pdf_to_text_generation'
cy.visitFeatureSettings(
'image_processing/feature_pdf_to_text_generation'
);
cy.enableFeature();
cy.saveFeatureSettings();
Expand Down
Loading

0 comments on commit 121968f

Please sign in to comment.