|
| 1 | +import { getGeminiAPIData } from '../../plugins/functions'; |
| 2 | + |
| 3 | +describe( '[Language processing] Excerpt Generation Tests', () => { |
| 4 | + before( () => { |
| 5 | + cy.login(); |
| 6 | + cy.visit( |
| 7 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_excerpt_generation' |
| 8 | + ); |
| 9 | + cy.get( '#status' ).check(); |
| 10 | + cy.get( |
| 11 | + '#classifai_feature_excerpt_generation_post_types_post' |
| 12 | + ).check(); |
| 13 | + cy.get( '#submit' ).click(); |
| 14 | + cy.optInAllFeatures(); |
| 15 | + cy.disableClassicEditor(); |
| 16 | + } ); |
| 17 | + |
| 18 | + beforeEach( () => { |
| 19 | + cy.login(); |
| 20 | + } ); |
| 21 | + |
| 22 | + it( 'Can save Google AI (Gemini API) "Language Processing" settings', () => { |
| 23 | + cy.visit( |
| 24 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_excerpt_generation' |
| 25 | + ); |
| 26 | + cy.get( '#provider' ).select( 'googleai_gemini_api' ); |
| 27 | + cy.get( |
| 28 | + 'input[name="classifai_feature_excerpt_generation[googleai_gemini_api][api_key]"]' |
| 29 | + ) |
| 30 | + .clear() |
| 31 | + .type( 'password' ); |
| 32 | + |
| 33 | + cy.get( '#status' ).check(); |
| 34 | + cy.get( |
| 35 | + '#classifai_feature_excerpt_generation_roles_administrator' |
| 36 | + ).check(); |
| 37 | + cy.get( '#length' ).clear().type( 35 ); |
| 38 | + cy.get( '#submit' ).click(); |
| 39 | + } ); |
| 40 | + |
| 41 | + it( 'Can see the generate excerpt button in a post', () => { |
| 42 | + cy.visit( '/wp-admin/plugins.php' ); |
| 43 | + cy.disableClassicEditor(); |
| 44 | + |
| 45 | + const data = getGeminiAPIData(); |
| 46 | + |
| 47 | + // Create test post. |
| 48 | + cy.createPost( { |
| 49 | + title: 'Test ChatGPT post', |
| 50 | + content: 'Test GPT content', |
| 51 | + } ); |
| 52 | + |
| 53 | + // Close post publish panel. |
| 54 | + const closePanelSelector = 'button[aria-label="Close panel"]'; |
| 55 | + cy.get( 'body' ).then( ( $body ) => { |
| 56 | + if ( $body.find( closePanelSelector ).length > 0 ) { |
| 57 | + cy.get( closePanelSelector ).click(); |
| 58 | + } |
| 59 | + } ); |
| 60 | + |
| 61 | + // Open post settings sidebar. |
| 62 | + cy.openDocumentSettingsSidebar(); |
| 63 | + |
| 64 | + // Find and open the excerpt panel. |
| 65 | + const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Excerpt")`; |
| 66 | + |
| 67 | + cy.get( panelButtonSelector ).then( ( $panelButton ) => { |
| 68 | + // Find the panel container. |
| 69 | + const $panel = $panelButton.parents( '.components-panel__body' ); |
| 70 | + |
| 71 | + // Open panel. |
| 72 | + if ( ! $panel.hasClass( 'is-opened' ) ) { |
| 73 | + cy.wrap( $panelButton ).click(); |
| 74 | + } |
| 75 | + |
| 76 | + // Verify button exists. |
| 77 | + cy.wrap( $panel ) |
| 78 | + .find( '.editor-post-excerpt button' ) |
| 79 | + .should( 'exist' ); |
| 80 | + |
| 81 | + // Click on button and verify data loads in. |
| 82 | + cy.wrap( $panel ).find( '.editor-post-excerpt button' ).click(); |
| 83 | + cy.wrap( $panel ).find( 'textarea' ).should( 'have.value', data ); |
| 84 | + } ); |
| 85 | + } ); |
| 86 | + |
| 87 | + it( 'Can see the generate excerpt button in a post (Classic Editor)', () => { |
| 88 | + cy.enableClassicEditor(); |
| 89 | + |
| 90 | + cy.visit( |
| 91 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_excerpt_generation' |
| 92 | + ); |
| 93 | + cy.get( '#status' ).check(); |
| 94 | + cy.get( '#submit' ).click(); |
| 95 | + |
| 96 | + const data = getGeminiAPIData(); |
| 97 | + |
| 98 | + cy.createClassicPost( { |
| 99 | + title: 'Excerpt test classic', |
| 100 | + content: 'Test GPT content.', |
| 101 | + postType: 'post', |
| 102 | + } ); |
| 103 | + |
| 104 | + // Ensure excerpt metabox is shown. |
| 105 | + cy.get( '#show-settings-link' ).click(); |
| 106 | + cy.get( '#postexcerpt-hide' ).check( { force: true } ); |
| 107 | + |
| 108 | + // Verify button exists. |
| 109 | + cy.get( '#classifai-openai__excerpt-generate-btn' ).should( 'exist' ); |
| 110 | + |
| 111 | + // Click on button and verify data loads in. |
| 112 | + cy.get( '#classifai-openai__excerpt-generate-btn' ).click(); |
| 113 | + cy.get( '#excerpt' ).should( 'have.value', data ); |
| 114 | + |
| 115 | + cy.disableClassicEditor(); |
| 116 | + } ); |
| 117 | +} ); |
0 commit comments