2023-08-18 09:23:53 +00:00
import { commonSelectors } from "Selectors/common" ;
import { workspaceConstantsSelectors } from "Selectors/workspaceConstants" ;
import { workspaceConstantsText } from "Texts/workspaceConstants" ;
2025-01-30 06:42:29 +00:00
import { dataSourceSelector } from "Selectors/dataSource" ;
2025-01-16 06:10:26 +00:00
import { commonText , commonWidgetText } from "Texts/common" ;
2025-01-27 06:42:24 +00:00
export const contantsNameValidation = ( selector , value , errorSelector , error ) => {
cy . get ( selector ) . click ( ) ;
cy . clearAndType ( selector , value ) ;
cy . get ( errorSelector ) . verifyVisibleElement (
2025-01-16 06:10:26 +00:00
"have.text" ,
error
) ;
cy . get ( workspaceConstantsSelectors . addConstantButton ) . should ( "be.disabled" ) ;
2024-05-14 10:19:12 +00:00
} ;
2023-08-18 09:23:53 +00:00
2025-01-02 08:44:42 +00:00
export const addNewconstants = ( name , value , type = "global" ) => {
2025-01-16 06:10:26 +00:00
cy . get ( workspaceConstantsSelectors . addNewConstantButton ) . click ( ) ;
cy . clearAndType ( commonSelectors . workspaceConstantNameInput , name ) ;
cy . get ( commonSelectors . workspaceConstantValueInput ) . click ( ) ;
cy . clearAndType ( commonSelectors . workspaceConstantValueInput , value ) ;
cy . get ( workspaceConstantsSelectors . constantsType ( type ) ) . check ( ) ;
cy . get ( workspaceConstantsSelectors . addConstantButton ) . click ( ) ;
2024-05-14 10:19:12 +00:00
} ;
2025-01-30 06:42:29 +00:00
export const deleteConstant = ( name , constType = "Global" ) => {
switchToConstantTab ( constType ) ;
2025-01-27 06:42:24 +00:00
cy . get (
workspaceConstantsSelectors . constDeleteButton ( name )
) . click ( ) ;
cy . get ( commonSelectors . yesButton ) . click ( ) ;
}
2024-12-06 12:03:32 +00:00
export const existingNameValidation = (
2025-01-16 06:10:26 +00:00
constName ,
constValue ,
type = "Global"
2024-12-06 12:03:32 +00:00
) => {
2025-01-16 06:10:26 +00:00
cy . clearAndType ( commonSelectors . workspaceConstantNameInput , constName ) ;
cy . get ( workspaceConstantsSelectors . constantsType ( type ) ) . check ( ) ;
cy . get ( commonSelectors . workspaceConstantValueInput ) . click ( ) ;
cy . clearAndType ( commonSelectors . workspaceConstantValueInput , constValue ) ;
cy . get ( workspaceConstantsSelectors . addConstantButton ) . click ( ) ;
cy . get ( commonSelectors . toastMessage )
. as ( "toast" )
. should (
"contain.text" ,
workspaceConstantsText . constantsExisitToast ( "Global" )
) ;
} ;
2025-01-27 06:42:24 +00:00
export const addConstantFormUI = ( ) => {
2025-01-16 06:10:26 +00:00
cy . get ( commonSelectors . workspaceConstantsIcon ) . click ( ) ;
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . addNewConstantButton ) . click ( ) ;
cy . get ( workspaceConstantsSelectors . nameFieldLabel ) . should ( 'have.text' , 'Name' ) ;
cy . get ( workspaceConstantsSelectors . nameFieldHelperText ) . should ( 'have.text' , workspaceConstantsText . nameFieldHelperText ) ,
cy . get ( workspaceConstantsSelectors . typeLabel ) . should ( 'have.text' , 'Type' ) ,
cy . get ( workspaceConstantsSelectors . globalConstLabel ) . should ( 'have.text' , 'Global constants' ) ;
cy . get ( workspaceConstantsSelectors . globalConstHelperText ) . should ( 'have.text' , workspaceConstantsText . globalConstHelperText ) ,
cy . get ( workspaceConstantsSelectors . secretsConstLabel ) . should ( 'have.text' , 'Secrets' ) ;
cy . get ( workspaceConstantsSelectors . secretsConstHelperText ) . should ( 'have.text' , workspaceConstantsText . secretsConstHelperText ) ,
cy . get ( workspaceConstantsSelectors . addConstantButton ) . should ( 'have.text' , workspaceConstantsText . addConstantButton ) ;
cy . get ( commonSelectors . cancelButton ) . should ( 'have.text' , 'Cancel' ) . click ( ) ;
}
2025-01-30 06:42:29 +00:00
// Function to switch to a specific constant tab (Global or Secrets)
export const switchToConstantTab = ( constantType ) => {
cy . contains ( "button" , constantType ) . click ( { force : true } ) ;
cy . wait ( 500 ) ; // Allow time for the tab switch
} ;
export const verifyConstantValueVisibility = ( constSelector , constValue ) => {
cy . get ( constSelector ) . click ( ) ;
cy . get ( dataSourceSelector . editorVariablePreview ) . should ( 'contain.text' , constValue ) ;
}
2025-01-27 06:42:24 +00:00
export const manageWorkspaceConstant = ( data ) => {
2025-01-16 06:10:26 +00:00
// Function to perform all constant management steps
const performConstantManagement = ( ) => {
2025-01-27 06:42:24 +00:00
2025-01-16 06:10:26 +00:00
switchToConstantTab ( data . constantType ) ;
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . envName ) . should ( 'have.text' , ` ${ data . envName } (0) ` ) ;
cy . get ( "button.tab.active" ) . contains ( data . constantType ) ;
2025-01-16 06:10:26 +00:00
// Add a new constant
cy . get ( workspaceConstantsSelectors . addNewConstantButton ) . click ( ) ;
cy . get ( workspaceConstantsSelectors . contantFormTitle ) . verifyVisibleElement (
"have.text" ,
workspaceConstantsText . addConstatntText
) ;
// Name and value validation
2025-01-27 06:42:24 +00:00
contantsNameValidation ( commonSelectors . workspaceConstantNameInput , " " , commonSelectors . nameErrorText , commonText . constantsNameError ) ;
contantsNameValidation ( commonSelectors . workspaceConstantNameInput , "9" , commonSelectors . nameErrorText , commonText . constantsNameError ) ;
contantsNameValidation ( commonSelectors . workspaceConstantNameInput , "%" , commonSelectors . nameErrorText , commonText . constantsNameError ) ;
contantsNameValidation ( commonSelectors . workspaceConstantNameInput , "Test spacing" , commonSelectors . nameErrorText , commonText . constantsNameError ) ;
contantsNameValidation (
commonSelectors . workspaceConstantNameInput ,
2025-01-16 06:10:26 +00:00
"Xk4jY2mLn8pQsZ9Rt6vBc7wJaHqOdEfGuVxY3NkMLzPoWX5weetr" ,
2025-01-27 06:42:24 +00:00
commonSelectors . nameErrorText ,
2025-01-16 06:10:26 +00:00
"Constant name has exceeded 50 characters"
) ;
2025-01-27 06:42:24 +00:00
contantsNameValidation ( commonSelectors . workspaceConstantValueInput , " " , commonSelectors . valueErrorText , commonText . constantsValueError ) ;
contantsNameValidation (
commonSelectors . workspaceConstantNameInput ,
"Xk4jY2mLn8pQsZ9Rt6vBc7wJaHqOdEfGuVxY3NkMLzPoWX5wee" ,
commonSelectors . nameErrorText ,
"Maximum length has been reached"
2025-01-16 06:10:26 +00:00
) ;
2025-01-27 06:42:24 +00:00
cy . get ( commonSelectors . workspaceConstantValueInput ) . click ( ) . clear ( ) . type ( "text" ) ;
cy . get ( workspaceConstantsSelectors . addConstantButton ) . should ( "be.disabled" ) ;
2025-01-16 06:10:26 +00:00
cy . get (
workspaceConstantsSelectors . constantsType ( data . constantType )
) . check ( ) ;
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . addConstantButton ) . should ( "be.enabled" ) ;
cy . get ( commonSelectors . cancelButton ) . click ( ) ;
//create constants with max char limit
addNewconstants ( "Xk4jY2mLn8pQsZ9Rt6vBc7wJaHqOdEfGuVxY3NkMLzPoWX5wee" , data . constName , data . constantType ) ;
cy . get ( workspaceConstantsSelectors . constantName ( "Xk4jY2mLn8pQsZ9Rt6vBc7wJaHqOdEfGuVxY3NkMLzPoWX5wee" ) ) . should (
"exist"
) ;
2025-01-16 06:10:26 +00:00
2025-01-27 06:42:24 +00:00
addNewconstants ( data . constName , data . constName , data . constantType ) ;
2025-01-16 06:10:26 +00:00
if ( data . constantType === "Global" ) {
cy . verifyToastMessage (
commonSelectors . toastMessage ,
workspaceConstantsText . constantCreatedToast (
data . constantType . charAt ( 0 ) . toUpperCase ( ) + data . constantType . slice ( 1 )
)
) ;
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . alertInfoText ) . should ( 'have.text' , "To resolve a global workspace constant use {{constants.access_token}}Read documentation" ) ;
}
else if ( data . constantType === "Secrets" ) {
2025-01-16 06:10:26 +00:00
cy . verifyToastMessage (
commonSelectors . toastMessage ,
workspaceConstantsText . secretConstantCreatedToast
) ;
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . alertInfoText ) . should ( 'have.text' , "To resolve a secret workspace constant use {{secrets.access_token}}Read documentation" ) ;
2025-01-16 06:10:26 +00:00
}
// Edit and verify the constant
cy . get ( workspaceConstantsSelectors . constEditButton ( data . constName ) ) . click ( ) ;
cy . get ( '[data-cy="name-input-field"]' ) . should (
"have.attr" ,
"data-tooltip-content" ,
"Cannot edit constant name"
) ;
2025-01-27 06:42:24 +00:00
cy . get ( 'input[type="radio"]' ) . should ( "be.disabled" ) ;
//update same value and add const should be disabled
cy . get ( commonSelectors . workspaceConstantValueInput ) . click ( ) . clear ( ) . type ( data . constName ) ;
cy . get ( workspaceConstantsSelectors . addConstantButton ) . should ( "be.disabled" ) ;
//update different value
cy . clearAndType ( commonSelectors . workspaceConstantValueInput , data . newConstvalue ) ;
2024-12-06 12:03:32 +00:00
cy . get ( workspaceConstantsSelectors . addConstantButton ) . click ( ) ;
2025-01-16 06:10:26 +00:00
cy . verifyToastMessage (
commonSelectors . toastMessage ,
"Constant updated successfully"
) ;
cy . get (
` [data-cy=" ${ data . constName . toLowerCase ( ) } -constant-visibility"] `
) . click ( ) ;
cy . wait ( 500 ) ;
cy . get ( workspaceConstantsSelectors . constantValue ( data . constName ) )
. should ( "be.visible" )
. and ( "have.text" , data . newConstvalue ) ;
// Delete and verify the constant
cy . get (
workspaceConstantsSelectors . constDeleteButton ( data . constName )
) . click ( ) ;
cy . get ( commonSelectors . modalMessage ) . verifyVisibleElement (
"have.text" ,
2025-01-27 06:42:24 +00:00
` Are you sure you want to delete ${ data . constName } from ${ data . envName . toLowerCase ( ) } ? `
2025-01-16 06:10:26 +00:00
) ;
cy . get ( commonSelectors . cancelButton ) . click ( ) ;
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . constantValue ( data . constName ) ) . should (
"exist"
) ;
2025-01-16 06:10:26 +00:00
cy . get (
workspaceConstantsSelectors . constDeleteButton ( data . constName )
) . click ( ) ;
cy . get ( commonSelectors . yesButton ) . click ( ) ;
cy . get ( workspaceConstantsSelectors . constantValue ( data . constName ) ) . should (
"not.exist"
) ;
cy . verifyToastMessage (
commonSelectors . toastMessage ,
"Constant deleted successfully"
) ;
2025-01-27 06:42:24 +00:00
cy . get ( '.tab-count.active' ) . should ( 'have.text' , '(1)' ) ;
//delete existing constant to validate empty screen
2025-01-30 06:42:29 +00:00
deleteConstant ( "Xk4jY2mLn8pQsZ9Rt6vBc7wJaHqOdEfGuVxY3NkMLzPoWX5wee" , data . constantType ) ;
2025-01-16 06:10:26 +00:00
// Verify empty state after deletion
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . emptyStateImage ) . should ( 'be.visible' ) ;
2025-01-16 06:10:26 +00:00
cy . get ( workspaceConstantsSelectors . emptyStateHeader ) . verifyVisibleElement (
"have.text" ,
workspaceConstantsText . emptyStateHeader
) ;
2025-01-27 06:42:24 +00:00
cy . get ( workspaceConstantsSelectors . emptyStateText ) . should ( 'have.text' , workspaceConstantsText . emptyStateText ) ;
cy . get ( workspaceConstantsSelectors . tableAddNewConstButton )
. should ( 'be.visible' ) ;
2025-01-16 06:10:26 +00:00
} ;
// Perform the constant management steps
performConstantManagement ( ) ;
2025-01-27 06:42:24 +00:00
//check env total constant count and search constant functionality
addNewconstants ( "globalconst" , "globalvalue" ) ;
addNewconstants ( "secretconst" , "secretvalue" , "Secrets" ) ;
cy
cy . get ( workspaceConstantsSelectors . envName ) . should ( 'have.text' , ` ${ data . envName } (2) ` ) ;
switchToConstantTab ( "Global" ) ;
cy . clearAndType ( workspaceConstantsSelectors . searchField , "globalconst" ) ;
cy . get ( workspaceConstantsSelectors . constantName ( "globalconst" ) ) . should (
"exist"
) ;
cy . clearAndType ( workspaceConstantsSelectors . searchField , "secretconst" ) ;
cy . get ( workspaceConstantsSelectors . constantName ( "secretconst" ) ) . should (
"not.exist"
) ;
cy . get ( workspaceConstantsSelectors . emptyStateImage ) . should ( 'be.visible' ) ;
cy . get ( workspaceConstantsSelectors . emptyStateHeader ) . should ( 'have.text' , workspaceConstantsText . noResultFoundHeader ) ;
cy . get ( workspaceConstantsSelectors . emptyStateText ) . should ( 'have.text' , workspaceConstantsText . emptyStateText ) ;
cy . get ( workspaceConstantsSelectors . searchField ) . clear ( ) ;
deleteConstant ( "globalconst" ) ;
switchToConstantTab ( "Secrets" ) ;
cy . clearAndType ( workspaceConstantsSelectors . searchField , "secretconst" ) ;
cy . get ( workspaceConstantsSelectors . constantName ( "secretconst" ) ) . should (
"exist"
) ;
cy . clearAndType ( workspaceConstantsSelectors . searchField , "globalconst" ) ;
cy . get ( workspaceConstantsSelectors . constantName ( "globalconst" ) ) . should (
"not.exist"
) ;
cy . get ( workspaceConstantsSelectors . searchField ) . clear ( ) ;
2025-01-30 06:42:29 +00:00
deleteConstant ( "secretconst" , "Secrets" ) ;
2024-12-06 12:03:32 +00:00
} ;