2024-08-31 16:35:26 +05:30
/ *
* Copyright 2024 Collate .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
* http : //www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* /
import { expect , Page } from '@playwright/test' ;
2025-04-15 14:00:33 +05:30
import { BIG_ENTITY_DELETE_TIMEOUT } from '../constant/delete' ;
2024-08-31 16:35:26 +05:30
import { GlobalSettingOptions } from '../constant/settings' ;
import { EntityTypeEndpoint } from '../support/entity/Entity.interface' ;
2025-04-04 17:06:05 +05:30
import { getApiContext , toastNotification } from './common' ;
2025-02-14 15:48:37 +05:30
import { escapeESReservedCharacters } from './entity' ;
2024-08-31 16:35:26 +05:30
export enum Services {
Database = GlobalSettingOptions . DATABASES ,
Messaging = GlobalSettingOptions . MESSAGING ,
Dashboard = GlobalSettingOptions . DASHBOARDS ,
Pipeline = GlobalSettingOptions . PIPELINES ,
MLModels = GlobalSettingOptions . MLMODELS ,
Storage = GlobalSettingOptions . STORAGES ,
Search = GlobalSettingOptions . SEARCH ,
2024-10-08 14:39:55 +05:30
API = GlobalSettingOptions . APIS ,
2024-08-31 16:35:26 +05:30
}
export const getEntityTypeFromService = ( service : Services ) = > {
switch ( service ) {
case Services . Dashboard :
return EntityTypeEndpoint . DashboardService ;
case Services . Database :
return EntityTypeEndpoint . DatabaseService ;
case Services . Storage :
return EntityTypeEndpoint . StorageService ;
case Services . Messaging :
return EntityTypeEndpoint . MessagingService ;
case Services . Search :
return EntityTypeEndpoint . SearchService ;
case Services . MLModels :
return EntityTypeEndpoint . MlModelService ;
case Services . Pipeline :
return EntityTypeEndpoint . PipelineService ;
2024-10-08 14:39:55 +05:30
case Services . API :
return EntityTypeEndpoint . ApiService ;
2024-08-31 16:35:26 +05:30
default :
return EntityTypeEndpoint . DatabaseService ;
}
} ;
export const getServiceCategoryFromService = ( service : Services ) = > {
switch ( service ) {
case Services . Dashboard :
return 'dashboardService' ;
case Services . Database :
return 'databaseService' ;
case Services . Storage :
return 'storageService' ;
case Services . Messaging :
return 'messagingService' ;
case Services . Search :
return 'searchService' ;
case Services . MLModels :
return 'mlmodelService' ;
case Services . Pipeline :
return 'pipelineService' ;
2024-10-08 14:39:55 +05:30
case Services . API :
return 'apiService' ;
2024-08-31 16:35:26 +05:30
default :
return 'databaseService' ;
}
} ;
export const deleteService = async (
typeOfService : Services ,
serviceName : string ,
page : Page
) = > {
2025-02-14 15:48:37 +05:30
const serviceResponse = page . waitForResponse (
` /api/v1/search/query?q=* ${ encodeURIComponent (
escapeESReservedCharacters ( serviceName )
) } * `
) ;
2024-08-31 16:35:26 +05:30
await page . fill ( '[data-testid="searchbar"]' , serviceName ) ;
2025-02-14 15:48:37 +05:30
await serviceResponse ;
2024-08-31 16:35:26 +05:30
// click on created service
await page . click ( ` [data-testid="service-name- ${ serviceName } "] ` ) ;
2025-03-20 21:53:17 +05:30
await expect ( page . getByTestId ( 'entity-header-name' ) ) . toHaveText ( serviceName ) ;
2024-08-31 16:35:26 +05:30
// Clicking on permanent delete radio button and checking the service name
await page . click ( '[data-testid="manage-button"]' ) ;
await page . waitForSelector ( '[data-menu-id*="delete-button"]' ) ;
await page . click ( '[data-testid="delete-button-title"]' ) ;
// Clicking on permanent delete radio button and checking the service name
await page . click ( '[data-testid="hard-delete-option"]' ) ;
await page . click ( ` [data-testid="hard-delete-option"] >> text= ${ serviceName } ` ) ;
await page . fill ( '[data-testid="confirmation-text-input"]' , 'DELETE' ) ;
2024-09-06 17:32:53 +05:30
const deleteResponse = page . waitForResponse ( ( response ) = >
response
. url ( )
. includes (
2025-03-18 10:50:40 +05:30
` /api/v1/services/ ${ getServiceCategoryFromService (
typeOfService
) } s / async `
2024-09-06 17:32:53 +05:30
)
) ;
2024-08-31 16:35:26 +05:30
await page . click ( '[data-testid="confirm-button"]' ) ;
2024-09-06 17:32:53 +05:30
await deleteResponse ;
2024-08-31 16:35:26 +05:30
// Closing the toast notification
2025-04-15 14:00:33 +05:30
await toastNotification (
page ,
/deleted successfully!/ ,
BIG_ENTITY_DELETE_TIMEOUT
) ; // Wait for up to 5 minutes for the toast notification to appear
2024-08-31 16:35:26 +05:30
2025-04-11 10:41:11 +05:30
await page . reload ( ) ;
await page . waitForLoadState ( 'networkidle' ) ;
await page . waitForSelector ( '[data-testid="loader"]' , { state : 'detached' } ) ;
const serviceSearchResponse = page . waitForResponse (
` /api/v1/search/query?q=* ${ encodeURIComponent (
escapeESReservedCharacters ( serviceName )
) } * `
) ;
await page . fill ( '[data-testid="searchbar"]' , serviceName ) ;
await serviceSearchResponse ;
2024-08-31 16:35:26 +05:30
await page . waitForSelector ( ` [data-testid="service-name- ${ serviceName } "] ` , {
2025-04-11 10:41:11 +05:30
state : 'detached' ,
2024-08-31 16:35:26 +05:30
} ) ;
} ;
export const testConnection = async ( page : Page ) = > {
// Test the connection
await page . waitForSelector ( '[data-testid="test-connection-btn"]' ) ;
await page . click ( '[data-testid="test-connection-btn"]' ) ;
const modalTitle = page . locator (
'[data-testid="test-connection-modal"] .ant-modal-title'
) ;
await expect ( modalTitle ) . toBeVisible ( ) ;
await page . getByRole ( 'button' , { name : 'OK' } ) . click ( ) ;
2024-12-05 17:53:14 +05:30
// Wait for the success badge or the warning badge to appear
const successBadge = page . locator ( '[data-testid="success-badge"]' ) ;
const warningBadge = page . locator ( '[data-testid="warning-badge"]' ) ;
await expect ( successBadge . or ( warningBadge ) ) . toBeVisible ( {
2024-09-04 19:02:30 +05:30
timeout : 2.5 * 60 * 1000 ,
2024-08-31 16:35:26 +05:30
} ) ;
await expect ( page . getByTestId ( 'messag-text' ) ) . toContainText (
2024-12-05 17:53:14 +05:30
/Connection test was successful.|Test connection partially successful: Some steps had failures, we will only ingest partial metadata. Click here to view details./g
2024-08-31 16:35:26 +05:30
) ;
} ;
export const checkServiceFieldSectionHighlighting = async (
page : Page ,
field : string
) = > {
await page . waitForSelector ( ` [data-id=" ${ field } "][data-highlighted="true"] ` ) ;
} ;
2025-04-04 17:06:05 +05:30
export const makeRetryRequest = async ( data : {
url : string ;
page : Page ;
retries? : number ;
} ) = > {
const { url , page , retries = 3 } = data ;
const { apiContext } = await getApiContext ( page ) ;
for ( let i = 0 ; i < retries ; i ++ ) {
try {
const response = await apiContext . get ( url ) ;
return response . json ( ) ;
} catch ( error ) {
if ( i === retries - 1 ) {
throw error ;
}
await page . waitForTimeout ( 1000 * ( i + 1 ) ) ; // Exponential backoff
}
}
} ;