diff --git a/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js b/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js index d1b9c6cc4..cb1c41efb 100644 --- a/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js +++ b/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js @@ -25,15 +25,30 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => { cy.get( '#classifai_feature_classification_post_types_post' ).check(); cy.get( '#classifai_feature_classification_post_statuses_publish' ).check(); cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category' ).check(); - cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category_threshold' ).type( 80 ); // "Test" requires 80% confidence. At 81%, it does not apply. + cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category_threshold' ).clear().type( 100 ); // "Test" requires 80% confidence. At 81%, it does not apply. cy.get( '#number_of_terms' ).clear().type( 1 ); cy.get( '#submit' ).click(); } ); + it( 'Can see the preview on the settings page', () => { + cy.visit( + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_classification' + ); + + cy.get( '#submit' ).click(); + + // Click the Preview button. + const closePanelSelector = '#get-classifier-preview-data-btn'; + cy.get( closePanelSelector ).click(); + + // Check the term is received and visible. + cy.get( '.tax-row--Category' ).should( 'exist' ); + } ); + it( 'Can create category and post and category will get auto-assigned', () => { // Remove custom taxonomies so those don't interfere with the test. cy.visit( - '/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu' + '/wp-admin/tools.php?page=classifai&tab=language_processing' ); cy.get( '#classifai_feature_classification_openai_embeddings_taxonomies_category' ).uncheck(); cy.get( '#submit' ).click(); @@ -79,25 +94,13 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => { .should( 'be.checked' ); cy.wrap( $panel ) .find( - '.editor-post-taxonomies__hierarchical-terms-list .editor-post-taxonomies__hierarchical-terms-choice:first label' + '.editor-post-taxonomies__hierarchical-terms-list' ) + .children() .contains( 'Test' ); } ); } ); - it( 'Can see the preview on the settings page', () => { - cy.visit( - '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_classification' - ); - - // Click the Preview button. - const closePanelSelector = '#get-classifier-preview-data-btn'; - cy.get( closePanelSelector ).click(); - - // Check the term is received and visible. - cy.get( '.tax-row--Category' ).should( 'exist' ); - } ); - it( 'Can create category and post and category will not get auto-assigned if feature turned off', () => { cy.visit( '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_classification' @@ -203,7 +206,7 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => { it( 'Can enable/disable content classification feature by role', () => { // Remove custom taxonomies so those don't interfere with the test. cy.visit( - '/wp-admin/tools.php?page=classifai&tab=language_processing&provider=watson_nlu' + '/wp-admin/tools.php?page=classifai&tab=language_processing' ); cy.get( '#submit' ).click(); diff --git a/tests/test-plugin/e2e-test-plugin.php b/tests/test-plugin/e2e-test-plugin.php index acc213ac3..aeb47bb52 100644 --- a/tests/test-plugin/e2e-test-plugin.php +++ b/tests/test-plugin/e2e-test-plugin.php @@ -19,6 +19,8 @@ function classifai_test_mock_http_requests( $preempt, $parsed_args, $url ) { if ( strpos( $url, 'http://e2e-test-nlu-server.test/v1/analyze' ) !== false ) { $response = file_get_contents( __DIR__ . '/nlu.json' ); + } elseif ( strpos( $url, 'https://api.openai.com/v1/models' ) !== false ) { + $response = file_get_contents( __DIR__ . '/models.json' ); } elseif ( strpos( $url, 'https://api.openai.com/v1/completions' ) !== false ) { $response = file_get_contents( __DIR__ . '/chatgpt.json' ); } elseif ( strpos( $url, 'https://api.openai.com/v1/chat/completions' ) !== false ) { diff --git a/tests/test-plugin/models.json b/tests/test-plugin/models.json new file mode 100644 index 000000000..4b0ef534d --- /dev/null +++ b/tests/test-plugin/models.json @@ -0,0 +1,23 @@ +{ + "object": "list", + "data": [ + { + "id": "model-id-0", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner" + }, + { + "id": "model-id-1", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner" + }, + { + "id": "model-id-2", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + } + ] +} \ No newline at end of file