Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update teams dropdown for admin #19797

Merged
merged 6 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@
import { expect, Page, test as base } from '@playwright/test';
import { GlobalSettingOptions } from '../../constant/settings';
import { USER_DESCRIPTION } from '../../constant/user';
import { TeamClass } from '../../support/team/TeamClass';
import { AdminClass } from '../../support/user/AdminClass';
import { UserClass } from '../../support/user/UserClass';
import { performAdminLogin } from '../../utils/admin';
import { descriptionBox, redirectToHomePage } from '../../utils/common';
import { descriptionBox, redirectToHomePage, uuid } from '../../utils/common';
import { settingClick } from '../../utils/sidebar';
import { redirectToUserPage } from '../../utils/userDetails';

const user1 = new UserClass();
const user2 = new UserClass();
const admin = new AdminClass();
const team = new TeamClass({
name: `a-new-team-${uuid()}`,
displayName: `A New Team ${uuid()}`,
description: 'playwright team description',
teamType: 'Group',
});

// Create 2 page and authenticate 1 with admin and another with normal user
const test = base.extend<{
Expand Down Expand Up @@ -51,6 +58,8 @@ test.describe('User with different Roles', () => {
await user1.create(apiContext);
await user2.create(apiContext);

await team.create(apiContext);

await afterAction();
});

Expand All @@ -60,9 +69,53 @@ test.describe('User with different Roles', () => {
await user1.delete(apiContext);
await user2.delete(apiContext);

await team.delete(apiContext);

await afterAction();
});

test('Admin user can get all the teams hierarchy which editing teams', async ({
sweta1308 marked this conversation as resolved.
Show resolved Hide resolved
adminPage,
}) => {
await redirectToUserPage(adminPage);

// Check if the avatar is visible
await expect(
adminPage
.getByTestId('user-profile-details')
.getByTestId('profile-avatar')
).toBeVisible();

await adminPage
.locator('.user-profile-container [data-icon="right"]')
.click();

await expect(
adminPage.getByTestId('user-team-card-container')
).toBeVisible();

const teamListResponse = adminPage.waitForResponse(
'/api/v1/teams/hierarchy?isJoinable=false'
);

await adminPage.getByTestId('edit-teams-button').click();

await teamListResponse;

await expect(adminPage.getByTestId('team-select')).toBeVisible();

await adminPage.getByTestId('team-select').click();

await adminPage.waitForSelector('.ant-tree-select-dropdown', {
state: 'visible',
});

// Check if newly added team is there or not
await expect(adminPage.locator('.ant-tree-select-dropdown')).toContainText(
team.responseData.displayName
);
});

test('Non admin user should be able to edit display name and description on own profile', async ({
userPage,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ const TeamsSelectable = ({
try {
setIsLoading(true);
const { data } = await getTeamsHierarchy(filterJoinable);
setTeams(data);
const sortedData = [...data].sort((a, b) => {
const nameA = a.fullyQualifiedName ?? '';
const nameB = b.fullyQualifiedName ?? '';

return nameA.localeCompare(nameB);
});
setTeams(sortedData);
showTeamsAlert && setNoTeam(isEmpty(data));
} catch (error) {
showErrorToast(error as AxiosError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const UserProfileTeams = ({
onCancel={handleCloseEditTeam}
onSave={handleTeamsSave}>
<TeamsSelectable
filterJoinable
filterJoinable={!isAdminUser}
maxValueCount={4}
selectedTeams={selectedTeams}
onSelectionChange={setSelectedTeams}
Expand Down
Loading