Skip to content

Commit 00c2c4d

Browse files
committed
Add tests. Fix lint error. Default to functionality being off
1 parent 85562b3 commit 00c2c4d

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

includes/Classifai/Features/ContentGeneration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function get_feature_default_settings(): array {
275275
'post' => 'post',
276276
],
277277
'provider' => ChatGPT::ID,
278-
'enable_quick_draft' => true,
278+
'enable_quick_draft' => false,
279279
];
280280
}
281281

src/js/features/content-generation/quick-draft/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ domReady( () => {
8383
* Remove any existing notices.
8484
*/
8585
function removeExistingNotices() {
86-
const notices = quickPressForm.parentElement.querySelectorAll( '.notice' );
86+
const notices =
87+
quickPressForm.parentElement.querySelectorAll( '.notice' );
8788
if ( notices.length > 0 ) {
8889
notices.forEach( function ( notice ) {
8990
notice.remove();

src/js/settings/components/feature-additional-settings/content-generation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const ContentGenerationSettings = () => {
7878
) }
7979
>
8080
<ToggleControl
81+
className="settings-enable-quick-draft"
8182
checked={ featureSettings.enable_quick_draft !== false }
8283
onChange={ ( value ) => {
8384
setFeatureSettings( {

tests/cypress/integration/language-processing/content-generation.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,37 @@ describe( '[Language processing] Content Generation Tests', () => {
114114
cy.get( '.classifai-chat-ui' ).should( 'not.exist' );
115115
} );
116116

117+
it( 'Can save Quick Draft integration settings', () => {
118+
cy.visitFeatureSettings(
119+
'language_processing/feature_content_generation'
120+
);
121+
cy.get( '.settings-enable-quick-draft input' ).check();
122+
cy.saveFeatureSettings();
123+
} );
124+
125+
it( 'Can see the generate content button in the Quick Draft widget', () => {
126+
cy.visit( '/wp-admin/index.php' );
127+
cy.get( '#dashboard_quick_press' ).should( 'exist' );
128+
cy.get( '#classifai-generate-content' ).click();
129+
130+
// Should show error message.
131+
cy.get( '#dashboard_quick_press .notice' ).should( 'contain.text', 'Please enter some content to generate a draft from.' );
132+
133+
// Add title and content.
134+
cy.get( '#dashboard_quick_press #title' ).clear().type( 'Test Content Generation post' );
135+
cy.get( '#dashboard_quick_press #content' ).clear().type( '5 tips for using WordPress' );
136+
137+
// Click the generate button.
138+
cy.get( '#classifai-generate-content' ).click();
139+
140+
// Should show success message.
141+
cy.get( '#dashboard_quick_press .notice' ).should( 'contain.text', 'Draft created successfully!' );
142+
143+
// Refresh the page and verify the draft is created.
144+
cy.reload();
145+
cy.get( '#dashboard_quick_press .drafts li:first-child .draft-title' ).should( 'contain.text', 'Test Content Generation post' );
146+
} );
147+
117148
it( 'Can set multiple custom prompts, select one as the default and delete one.', () => {
118149
cy.disableClassicEditor();
119150

tests/cypress/support/commands.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,13 @@ Cypress.Commands.add( 'verifyContentGenerationEnabled', ( enabled = true ) => {
478478
} else {
479479
cy.get( '.classifai-chat-button' ).should( 'not.exist' );
480480
}
481+
482+
cy.visit( '/wp-admin/index.php' );
483+
if ( enabled ) {
484+
cy.get( '#classifai-generate-content' ).should( 'exist' );
485+
} else {
486+
cy.get( '#classifai-generate-content' ).should( 'not.exist' );
487+
}
481488
} );
482489

483490
/**

0 commit comments

Comments
 (0)