diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/ServiceEntity.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/ServiceEntity.spec.ts index 9b3a3c5df98..f9d59399923 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/ServiceEntity.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/ServiceEntity.spec.ts @@ -11,6 +11,7 @@ * limitations under the License. */ import { test } from '@playwright/test'; +import { CustomPropertySupportedEntityList } from '../../constant/customProperty'; import { DatabaseClass } from '../../support/entity/DatabaseClass'; import { DatabaseSchemaClass } from '../../support/entity/DatabaseSchemaClass'; import { EntityDataClass } from '../../support/entity/EntityDataClass'; @@ -27,6 +28,7 @@ import { getToken, redirectToHomePage, } from '../../utils/common'; +import { CustomPropertyTypeByName } from '../../utils/customProperty'; const entities = [ DatabaseServiceClass, @@ -53,6 +55,7 @@ entities.forEach((EntityClass) => { await EntityDataClass.preRequisitesForTests(apiContext); await entity.create(apiContext); + await entity.prepareForTests(apiContext); await afterAction(); }); @@ -112,12 +115,44 @@ entities.forEach((EntityClass) => { await entity.inactiveAnnouncement(page); }); + // Create custom property only for supported entities + if (CustomPropertySupportedEntityList.includes(entity.endpoint)) { + const properties = Object.values(CustomPropertyTypeByName); + const titleText = properties.join(', '); + + test(`Set & Update ${titleText} Custom Property `, async ({ page }) => { + // increase timeout as it using single test for multiple steps + test.slow(true); + + await test.step(`Set ${titleText} Custom Property`, async () => { + for (const type of properties) { + await entity.setCustomProperty( + page, + entity.customPropertyValue[type].property, + entity.customPropertyValue[type].value + ); + } + }); + + await test.step(`Update ${titleText} Custom Property`, async () => { + for (const type of properties) { + await entity.updateCustomProperty( + page, + entity.customPropertyValue[type].property, + entity.customPropertyValue[type].newValue + ); + } + }); + }); + } + test(`Update displayName`, async ({ page }) => { await entity.renameEntity(page, entity.entity.name); }); test.afterAll('Cleanup', async ({ browser }) => { const { apiContext, afterAction } = await createNewPage(browser); + await entity.cleanup(apiContext); await entity.delete(apiContext); await EntityDataClass.postRequisitesForTests(apiContext); await afterAction(); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/support/entity/EntityClass.ts b/openmetadata-ui/src/main/resources/ui/playwright/support/entity/EntityClass.ts index feb571389ab..eabacd5fc52 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/support/entity/EntityClass.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/support/entity/EntityClass.ts @@ -50,6 +50,7 @@ import { EntityTypeEndpoint, ENTITY_PATH } from './Entity.interface'; export class EntityClass { type: string; endpoint: EntityTypeEndpoint; + cleanupUser: (apiContext: APIRequestContext) => Promise; customPropertyValue: Record< string, @@ -78,13 +79,15 @@ export class EntityClass { this.endpoint ); - this.customPropertyValue = data; + this.customPropertyValue = data.customProperties; + this.cleanupUser = data.cleanupUser; } } async cleanup(apiContext: APIRequestContext) { // Delete custom property only for supported entities if (CustomPropertySupportedEntityList.includes(this.endpoint)) { + await this.cleanupUser(apiContext); const entitySchemaResponse = await apiContext.get( `/api/v1/metadata/types/name/${ENTITY_PATH[this.endpoint]}` ); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/utils/customProperty.ts b/openmetadata-ui/src/main/resources/ui/playwright/utils/customProperty.ts index 0af614ad229..3c7f68f089a 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/utils/customProperty.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/customProperty.ts @@ -15,6 +15,7 @@ import { EntityTypeEndpoint, ENTITY_PATH, } from '../support/entity/Entity.interface'; +import { UserClass } from '../support/user/UserClass'; import { uuid } from './common'; export enum CustomPropertyType { @@ -221,7 +222,10 @@ export const validateValueForProperty = async (data: { } }; -export const getPropertyValues = (type: string) => { +export const getPropertyValues = ( + type: string, + users: Record +) => { switch (type) { case 'integer': return { @@ -272,14 +276,14 @@ export const getPropertyValues = (type: string) => { }; case 'entityReference': return { - value: 'Adam Matthews', - newValue: 'Aaron Singh', + value: users.user1, + newValue: users.user2, }; case 'entityReferenceList': return { - value: 'Aaron Johnson,Organization', - newValue: 'Aaron Warren', + value: `${users.user3},Organization`, + newValue: users.user4, }; default: @@ -315,6 +319,27 @@ export const createCustomPropertyForEntity = async ( property: CustomProperty; } >; + const users: UserClass[] = []; + // Loop to create and add 4 new users to the users array + for (let i = 0; i < 4; i++) { + const user = new UserClass(); + await user.create(apiContext); + users.push(user); + } + + // Reduce the users array to a userNames object with keys as user1, user2, etc., and values as the user's names + const userNames = users.reduce((acc, user, index) => { + acc[`user${index + 1}`] = user.getUserName(); + + return acc; + }, {}); + + // Define an asynchronous function to clean up (delete) all users in the users array + const cleanupUser = async (apiContext: APIRequestContext) => { + for (const user of users) { + await user.delete(apiContext); + } + }; for (const item of propertyList) { const customPropertyResponse = await apiContext.put( @@ -357,12 +382,12 @@ export const createCustomPropertyForEntity = async ( return { ...prev, [propertyTypeName]: { - ...getPropertyValues(propertyTypeName), + ...getPropertyValues(propertyTypeName, userNames), property: curr, }, }; }, {}); } - return customProperties; + return { customProperties, cleanupUser }; };