diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/UserDetails.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/UserDetails.spec.ts index b89c2298347..166f6998161 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/UserDetails.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/UserDetails.spec.ts @@ -19,6 +19,7 @@ import { UserClass } from '../../support/user/UserClass'; import { performAdminLogin } from '../../utils/admin'; import { descriptionBox, redirectToHomePage } from '../../utils/common'; import { settingClick } from '../../utils/sidebar'; +import { redirectToUserPage } from '../../utils/userDetails'; const user1 = new UserClass(); const user2 = new UserClass(); @@ -65,26 +66,7 @@ test.describe('User with different Roles', () => { test('Non admin user should be able to edit display name and description on own profile', async ({ userPage, }) => { - await redirectToHomePage(userPage); - - await userPage.getByTestId('dropdown-profile').click(); - - // Hover on the profile avatar to close the name tooltip - await userPage.getByTestId('profile-avatar').hover(); - - await userPage.waitForSelector('.profile-dropdown', { state: 'visible' }); - - const getUserDetails = userPage.waitForResponse(`/api/v1/users/name/*`); - - await userPage - .locator('.profile-dropdown') - .getByTestId('user-name') - .click(); - - await getUserDetails; - - // Close the profile dropdown - await userPage.getByTestId('dropdown-profile').click(); + await redirectToUserPage(userPage); // Check if the display name is present await expect( @@ -188,6 +170,32 @@ test.describe('User with different Roles', () => { ).toContainText('No description'); }); + test('Non admin user should not be able to edit the persona or roles', async ({ + userPage, + }) => { + await redirectToUserPage(userPage); + + // Check if the display name is present + await expect( + userPage.getByTestId('user-profile-details').getByTestId('user-name') + ).toHaveText(user1.responseData.displayName); + + await userPage + .locator('.user-profile-container [data-icon="right"]') + .click(); + + // Check for Roles field visibility + await expect(userPage.getByTestId('user-profile-roles')).toBeVisible(); + + // Edit Persona icon shouldn't be visible + await expect( + userPage.getByTestId('persona-list').getByTestId('edit-persona') + ).not.toBeVisible(); + + // Edit Roles icon shouldn't be visible + await expect(userPage.getByTestId('edit-roles-button')).not.toBeVisible(); + }); + test('Non logged in user should not be able to edit display name and description on other users', async ({ userPage, adminPage, diff --git a/openmetadata-ui/src/main/resources/ui/playwright/utils/userDetails.ts b/openmetadata-ui/src/main/resources/ui/playwright/utils/userDetails.ts new file mode 100644 index 00000000000..cf8caa7b0fd --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/userDetails.ts @@ -0,0 +1,34 @@ +/* + * Copyright 2025 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 { Page } from '@playwright/test'; +import { clickOutside, redirectToHomePage } from './common'; + +export const redirectToUserPage = async (page: Page) => { + await redirectToHomePage(page); + + await page.getByTestId('dropdown-profile').click(); + + // Hover on the profile avatar to close the name tooltip + await page.getByTestId('profile-avatar').hover(); + + await page.waitForSelector('.profile-dropdown', { state: 'visible' }); + + const getUserDetails = page.waitForResponse(`/api/v1/users/name/*`); + + await page.locator('.profile-dropdown').getByTestId('user-name').click(); + + await getUserDetails; + + // Close the profile dropdown + await clickOutside(page); +};