-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
tests/cypress/integration/language-processing/moderation-openai-moderation.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
describe( '[Language processing] Moderation Tests', () => { | ||
before( () => { | ||
cy.login(); | ||
cy.visit( | ||
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_moderation' | ||
); | ||
cy.get( '#submit' ).click(); | ||
cy.optInAllFeatures(); | ||
cy.disableClassicEditor(); | ||
} ); | ||
|
||
beforeEach( () => { | ||
cy.login(); | ||
} ); | ||
|
||
it( 'Can save OpenAI Moderation "Language Processing" settings', () => { | ||
cy.visit( | ||
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_moderation' | ||
); | ||
|
||
cy.get( '#api_key' ).clear().type( 'password' ); | ||
cy.get( '#status' ).check(); | ||
cy.get( | ||
'#classifai_feature_moderation_content_types_comments' | ||
).check(); | ||
cy.get( '#role_based_access' ).check(); | ||
cy.get( '#classifai_feature_moderation_roles_administrator' ).check(); | ||
cy.get( '#submit' ).click(); | ||
} ); | ||
|
||
it( 'Can run moderation on a comment', () => { | ||
cy.visit( '/wp-admin/edit-comments.php' ); | ||
|
||
cy.get( '#cb-select-1' ).check(); | ||
cy.get( '#bulk-action-selector-top' ).select( 'feature_moderation' ); | ||
cy.get( '#doaction' ).click(); | ||
|
||
cy.get( '#comment-1 .column-moderation_flagged div' ).contains( 'Yes' ); | ||
cy.get( '#comment-1 .column-moderation_flags div' ).contains( | ||
'harassment/threatening, violence' | ||
); | ||
} ); | ||
|
||
it( 'Can enable/disable moderation feature', () => { | ||
// Disable features. | ||
cy.visit( | ||
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_moderation' | ||
); | ||
cy.get( '#status' ).uncheck(); | ||
cy.get( '#submit' ).click(); | ||
|
||
// Verify that the feature is not available. | ||
cy.verifyModerationEnabled( false ); | ||
|
||
// Enable feature. | ||
cy.visit( | ||
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_moderation' | ||
); | ||
cy.get( '#status' ).check(); | ||
cy.get( '#submit' ).click(); | ||
|
||
// Verify that the feature is available. | ||
cy.verifyModerationEnabled( true ); | ||
} ); | ||
|
||
it( 'Can enable/disable moderation feature by role', () => { | ||
cy.visit( | ||
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_moderation' | ||
); | ||
cy.get( '#status' ).check(); | ||
cy.get( '#submit' ).click(); | ||
|
||
// Disable admin role. | ||
cy.disableFeatureForRoles( 'feature_moderation', [ 'administrator' ] ); | ||
|
||
// Verify that the feature is not available. | ||
cy.verifyModerationEnabled( false ); | ||
|
||
// enable admin role. | ||
cy.enableFeatureForRoles( 'feature_moderation', [ 'administrator' ] ); | ||
|
||
// Verify that the feature is available. | ||
cy.verifyModerationEnabled( true ); | ||
} ); | ||
|
||
it( 'Can enable/disable moderation feature by user', () => { | ||
cy.visit( | ||
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_moderation' | ||
); | ||
cy.get( '#status' ).check(); | ||
cy.get( '#submit' ).click(); | ||
|
||
// Disable admin role. | ||
cy.disableFeatureForRoles( 'feature_moderation', [ 'administrator' ] ); | ||
|
||
cy.enableFeatureForUsers( 'feature_moderation', [] ); | ||
|
||
// Verify that the feature is not available. | ||
cy.verifyModerationEnabled( false ); | ||
|
||
// Enable feature for admin user. | ||
cy.enableFeatureForUsers( 'feature_moderation', [ 'admin' ] ); | ||
|
||
// Verify that the feature is available. | ||
cy.verifyModerationEnabled( true ); | ||
} ); | ||
|
||
it( 'User can opt-out of moderation feature', () => { | ||
cy.visit( | ||
'/wp-admin/tools.php?page=classifai&tab=language_processing&feature=feature_moderation' | ||
); | ||
cy.get( '#status' ).check(); | ||
cy.get( '#submit' ).click(); | ||
|
||
// Enable user based opt-out. | ||
cy.enableFeatureOptOut( 'feature_moderation' ); | ||
|
||
// opt-out | ||
cy.optOutFeature( 'feature_moderation' ); | ||
|
||
// Verify that the feature is not available. | ||
cy.verifyModerationEnabled( false ); | ||
|
||
// opt-in | ||
cy.optInFeature( 'feature_moderation' ); | ||
|
||
// Verify that the feature is available. | ||
cy.verifyModerationEnabled( true ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"id": "modr-XXXXX", | ||
"model": "text-moderation-005", | ||
"results": [ | ||
{ | ||
"flagged": true, | ||
"categories": { | ||
"sexual": false, | ||
"hate": false, | ||
"harassment": false, | ||
"self-harm": false, | ||
"sexual/minors": false, | ||
"hate/threatening": false, | ||
"violence/graphic": false, | ||
"self-harm/intent": false, | ||
"self-harm/instructions": false, | ||
"harassment/threatening": true, | ||
"violence": true | ||
}, | ||
"category_scores": { | ||
"sexual": 1.2282071e-06, | ||
"hate": 0.010696256, | ||
"harassment": 0.29842457, | ||
"self-harm": 1.5236925e-08, | ||
"sexual/minors": 5.7246268e-08, | ||
"hate/threatening": 0.0060676364, | ||
"violence/graphic": 4.435014e-06, | ||
"self-harm/intent": 8.098441e-10, | ||
"self-harm/instructions": 2.8498655e-11, | ||
"harassment/threatening": 0.63055265, | ||
"violence": 0.99011886 | ||
} | ||
} | ||
] | ||
} |