|
| 1 | +describe( '[Language Processing] Text to Speech (OpenAI) Tests', () => { |
| 2 | + before( () => { |
| 3 | + cy.login(); |
| 4 | + cy.visit( |
| 5 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_text_to_speech_generation' |
| 6 | + ); |
| 7 | + cy.get( |
| 8 | + '#classifai_feature_text_to_speech_generation_post_types_post' |
| 9 | + ).check( 'post' ); |
| 10 | + cy.get( '#provider' ).select( 'openai_text_to_speech' ); |
| 11 | + cy.get( '#tts_model' ).select( 'tts-1' ); |
| 12 | + cy.get( '[name="classifai_feature_text_to_speech_generation[openai_text_to_speech][api_key]"]' ).type( 'password' ); |
| 13 | + cy.get( '#status' ).check(); |
| 14 | + cy.get( '#submit' ).click(); |
| 15 | + |
| 16 | + cy.get( '[name="classifai_feature_text_to_speech_generation[openai_text_to_speech][voice]"]' ).select( 'alloy' ); |
| 17 | + cy.get( '#submit' ).click(); |
| 18 | + cy.optInAllFeatures(); |
| 19 | + cy.disableClassicEditor(); |
| 20 | + } ); |
| 21 | + |
| 22 | + beforeEach( () => { |
| 23 | + cy.login(); |
| 24 | + } ); |
| 25 | + |
| 26 | + it( 'Generates audio from text', () => { |
| 27 | + cy.createPost( { |
| 28 | + title: 'Text to Speech test', |
| 29 | + content: |
| 30 | + "This feature uses OpenAI's Text to Speech capabilities.", |
| 31 | + } ); |
| 32 | + |
| 33 | + cy.get( 'button[aria-label="Close panel"]' ).click(); |
| 34 | + cy.get( 'button[data-label="Post"]' ).click(); |
| 35 | + cy.get( '.classifai-panel' ).click(); |
| 36 | + cy.get( '#classifai-audio-controls__preview-btn' ).should( 'exist' ); |
| 37 | + } ); |
| 38 | + |
| 39 | + it( 'Audio controls are visible if supported by post type', () => { |
| 40 | + cy.visit( '/text-to-speech-test/' ); |
| 41 | + cy.get( '.class-post-audio-controls' ).should( 'be.visible' ); |
| 42 | + } ); |
| 43 | + |
| 44 | + it( 'a11y - aria-labels', () => { |
| 45 | + cy.visit( '/text-to-speech-test/' ); |
| 46 | + cy.get( '.dashicons-controls-play' ).should( 'be.visible' ); |
| 47 | + cy.get( '.class-post-audio-controls' ).should( |
| 48 | + 'have.attr', |
| 49 | + 'aria-label', |
| 50 | + 'Play audio' |
| 51 | + ); |
| 52 | + |
| 53 | + cy.get( '.class-post-audio-controls' ).click(); |
| 54 | + |
| 55 | + cy.get( '.dashicons-controls-play' ).should( 'not.be.visible' ); |
| 56 | + cy.get( '.class-post-audio-controls' ).should( |
| 57 | + 'have.attr', |
| 58 | + 'aria-label', |
| 59 | + 'Pause audio' |
| 60 | + ); |
| 61 | + |
| 62 | + cy.get( '.class-post-audio-controls' ).click(); |
| 63 | + cy.get( '.dashicons-controls-play' ).should( 'be.visible' ); |
| 64 | + cy.get( '.class-post-audio-controls' ).should( |
| 65 | + 'have.attr', |
| 66 | + 'aria-label', |
| 67 | + 'Play audio' |
| 68 | + ); |
| 69 | + } ); |
| 70 | + |
| 71 | + it( 'a11y - keyboard accessibility', () => { |
| 72 | + cy.visit( '/text-to-speech-test/' ); |
| 73 | + cy.get( '.class-post-audio-controls' ) |
| 74 | + .tab( { shift: true } ) |
| 75 | + .tab() |
| 76 | + .type( '{enter}' ); |
| 77 | + cy.get( '.dashicons-controls-pause' ).should( 'be.visible' ); |
| 78 | + cy.get( '.class-post-audio-controls' ).should( |
| 79 | + 'have.attr', |
| 80 | + 'aria-label', |
| 81 | + 'Pause audio' |
| 82 | + ); |
| 83 | + |
| 84 | + cy.get( '.class-post-audio-controls' ).type( '{enter}' ); |
| 85 | + cy.get( '.dashicons-controls-play' ).should( 'be.visible' ); |
| 86 | + cy.get( '.class-post-audio-controls' ).should( |
| 87 | + 'have.attr', |
| 88 | + 'aria-label', |
| 89 | + 'Play audio' |
| 90 | + ); |
| 91 | + } ); |
| 92 | + |
| 93 | + it( 'Can see the enable button in a post (Classic Editor)', () => { |
| 94 | + cy.enableClassicEditor(); |
| 95 | + |
| 96 | + cy.createClassicPost( { |
| 97 | + title: 'Text to Speech test classic', |
| 98 | + content: |
| 99 | + "This feature uses OpenAI's Text to Speech capabilities.", |
| 100 | + postType: 'post', |
| 101 | + } ); |
| 102 | + |
| 103 | + cy.get( '#classifai-text-to-speech-meta-box' ).should( 'exist' ); |
| 104 | + cy.get( '#classifai_synthesize_speech' ).check(); |
| 105 | + cy.get( '#classifai-audio-preview' ).should( 'exist' ); |
| 106 | + |
| 107 | + cy.visit( '/text-to-speech-test/' ); |
| 108 | + cy.get( '.class-post-audio-controls' ).should( 'be.visible' ); |
| 109 | + |
| 110 | + cy.disableClassicEditor(); |
| 111 | + } ); |
| 112 | + |
| 113 | + it( 'Disable support for post type Post', () => { |
| 114 | + cy.disableClassicEditor(); |
| 115 | + |
| 116 | + cy.visit( |
| 117 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_text_to_speech_generation' |
| 118 | + ); |
| 119 | + cy.get( |
| 120 | + '#classifai_feature_text_to_speech_generation_post_types_post' |
| 121 | + ).uncheck( 'post' ); |
| 122 | + cy.get( '#submit' ).click(); |
| 123 | + |
| 124 | + cy.visit( '/text-to-speech-test/' ); |
| 125 | + cy.get( '.class-post-audio-controls' ).should( 'not.exist' ); |
| 126 | + } ); |
| 127 | + |
| 128 | + it( 'Can enable/disable text to speech feature', () => { |
| 129 | + // Disable feature. |
| 130 | + cy.visit( |
| 131 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_text_to_speech_generation' |
| 132 | + ); |
| 133 | + cy.get( '#status' ).uncheck(); |
| 134 | + cy.get( '#submit' ).click(); |
| 135 | + |
| 136 | + // Verify that the feature is not available. |
| 137 | + cy.verifyTextToSpeechEnabled( false ); |
| 138 | + |
| 139 | + // Enable feature. |
| 140 | + cy.visit( |
| 141 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_text_to_speech_generation' |
| 142 | + ); |
| 143 | + cy.get( '#status' ).check(); |
| 144 | + cy.get( |
| 145 | + '#classifai_feature_text_to_speech_generation_post_types_post' |
| 146 | + ).check( 'post' ); |
| 147 | + cy.get( '#submit' ).click(); |
| 148 | + |
| 149 | + // Verify that the feature is available. |
| 150 | + cy.verifyTextToSpeechEnabled( true ); |
| 151 | + } ); |
| 152 | + |
| 153 | + it( 'Can enable/disable text to speech feature by role', () => { |
| 154 | + // Enable feature. |
| 155 | + cy.visit( |
| 156 | + '/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_text_to_speech_generation' |
| 157 | + ); |
| 158 | + cy.get( |
| 159 | + '#classifai_feature_text_to_speech_generation_post_types_post' |
| 160 | + ).check( 'post' ); |
| 161 | + cy.get( '#submit' ).click(); |
| 162 | + |
| 163 | + // Disable admin role. |
| 164 | + cy.disableFeatureForRoles( 'feature_text_to_speech_generation', [ |
| 165 | + 'administrator', |
| 166 | + ] ); |
| 167 | + |
| 168 | + // Verify that the feature is not available. |
| 169 | + cy.verifyTextToSpeechEnabled( false ); |
| 170 | + |
| 171 | + // Enable admin role. |
| 172 | + cy.enableFeatureForRoles( 'feature_text_to_speech_generation', [ |
| 173 | + 'administrator', |
| 174 | + ] ); |
| 175 | + |
| 176 | + // Verify that the feature is available. |
| 177 | + cy.verifyTextToSpeechEnabled( true ); |
| 178 | + } ); |
| 179 | + |
| 180 | + it( 'Can enable/disable text to speech feature by user', () => { |
| 181 | + // Disable admin role. |
| 182 | + cy.disableFeatureForRoles( 'feature_text_to_speech_generation', [ |
| 183 | + 'administrator', |
| 184 | + ] ); |
| 185 | + |
| 186 | + // Verify that the feature is not available. |
| 187 | + cy.verifyTextToSpeechEnabled( false ); |
| 188 | + |
| 189 | + // Enable feature for admin user. |
| 190 | + cy.enableFeatureForUsers( 'feature_text_to_speech_generation', [ |
| 191 | + 'admin', |
| 192 | + ] ); |
| 193 | + |
| 194 | + // Verify that the feature is available. |
| 195 | + cy.verifyTextToSpeechEnabled( true ); |
| 196 | + } ); |
| 197 | + |
| 198 | + it( 'User can opt-out text to speech feature', () => { |
| 199 | + // Enable user based opt-out. |
| 200 | + cy.enableFeatureOptOut( 'feature_text_to_speech_generation' ); |
| 201 | + |
| 202 | + // opt-out |
| 203 | + cy.optOutFeature( 'feature_text_to_speech_generation' ); |
| 204 | + |
| 205 | + // Verify that the feature is not available. |
| 206 | + cy.verifyTextToSpeechEnabled( false ); |
| 207 | + |
| 208 | + // opt-in |
| 209 | + cy.optInFeature( 'feature_text_to_speech_generation' ); |
| 210 | + |
| 211 | + // Verify that the feature is available. |
| 212 | + cy.verifyTextToSpeechEnabled( true ); |
| 213 | + } ); |
| 214 | +} ); |
0 commit comments