Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions e2e/pageobjects/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ export class HeaderPageObject extends PageObject {
await this.page.getByRole("listitem").filter({ hasText: username }).isHidden();
}

async transferModeratorRole(username: string) {
async promoteToModerator(username: string) {
await this.page
.getByRole("listitem")
.filter({ hasText: username })
.getByRole("button", { name: "Transfer Moderator Role" })
.getByRole("button", { name: "Promote to Moderator" })
.click();
await this.page.getByRole("button", { name: "Yes, transfer" }).click();
await this.page.getByRole("button", { name: "Yes, promote" }).click();
await this.page
.getByRole("listitem")
.filter({ hasText: username })
.getByRole("button", { name: "Transfer Moderator Role", disabled: true })
.getByRole("button", { name: "Promote to Moderator", disabled: true })
.isVisible();
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/pokerPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test("should kick user and show error page", async ({ page, context }) => {
expect(newPage.url()).toContain("error");
});

test("should accept user and transfer moderator role", async ({ page, context }) => {
test("should accept user and promote to moderator", async ({ page, context }) => {
const pokerPage = new PokerPagePageObject(page, context);
const header = new HeaderPageObject(page, context);
const joinSessionDialog = new JoinSessionDialogPageObject(page, context);
Expand All @@ -110,7 +110,7 @@ test("should accept user and transfer moderator role", async ({ page, context })

await header.openParticipants();
await header.acceptParticipant(newUser);
await header.transferModeratorRole(newUser);
await header.promoteToModerator(newUser);
await header.closeParticipants();

await expect(newPage.getByRole("button", { name: "Set User Story" })).toBeVisible();
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/retroPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test("should kick user and show error page", async ({ context, page }) => {
expect(newPage.url()).toContain("error");
});

test("should accept user and transfer moderator role", async ({ context, page }) => {
test("should accept user and promote to moderator", async ({ context, page }) => {
const retroPage = new RetroPagePageObject(page, context);
const header = new HeaderPageObject(page, context);
const joinSessionDialog = new JoinSessionDialogPageObject(page, context);
Expand All @@ -92,7 +92,7 @@ test("should accept user and transfer moderator role", async ({ context, page })

await header.openParticipants();
await header.acceptParticipant(newUser);
await header.transferModeratorRole(newUser);
await header.promoteToModerator(newUser);
await header.closeParticipants();

await expect(newPage.getByRole("heading", { name: "Test Session" })).toBeVisible();
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/common/components/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface AppHeaderProps {
onKickUser: (userId: string) => void;
onRejectJoinUser: (userId: string) => void;
onAcceptJoinUser: (userId: string) => void;
onTransferModeratorRole: (userId: string) => void;
onPromoteToModerator: (userId: string) => void;
children?: ReactNode;
}

Expand All @@ -26,7 +26,7 @@ export function AppHeader({
onKickUser,
onRejectJoinUser,
onAcceptJoinUser,
onTransferModeratorRole,
onPromoteToModerator,
children,
}: AppHeaderProps) {
const { user } = useUserContext();
Expand Down Expand Up @@ -58,7 +58,7 @@ export function AppHeader({
handleKickUser={onKickUser}
onRejectJoinUser={onRejectJoinUser}
onAcceptJoinUser={onAcceptJoinUser}
onTransferModeratorRole={onTransferModeratorRole}
onPromoteToModerator={onPromoteToModerator}
/>
<SettingsButton>{children}</SettingsButton>
</Toolbar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ParticipantButtonProps {
handleKickUser: (userId: string) => void;
onRejectJoinUser: (userId: string) => void;
onAcceptJoinUser: (userId: string) => void;
onTransferModeratorRole: (userId: string) => void;
onPromoteToModerator: (userId: string) => void;
}

export function ParticipantsButton({
Expand All @@ -20,7 +20,7 @@ export function ParticipantsButton({
handleKickUser,
onRejectJoinUser,
onAcceptJoinUser,
onTransferModeratorRole,
onPromoteToModerator,
}: ParticipantButtonProps) {
const { isOpen, openDialog, closeDialog } = useDialog();
const waitingUsersCount = Object.values(waitingList).length;
Expand Down Expand Up @@ -50,7 +50,7 @@ export function ParticipantsButton({
onKickUser={handleKickUser}
onAcceptJoinUser={onAcceptJoinUser}
onRejectJoinUser={onRejectJoinUser}
onTransferModeratorRole={onTransferModeratorRole}
onPromoteToModerator={onPromoteToModerator}
/>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/common/context/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface UserContextProviderProps {

export const initialUserState: User = {
id: "",
role: "participant",
isModerator: false,
name: "",
};

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/common/dialogs/JoinSessionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function JoinSessionDialog({ onAddToWaitingList }: JoinSessionDialogProps
...user,
id: generateId(),
name,
role: "participant",
isModerator: false,
};
setRoomId(roomId);
setUser(newUser);
Expand Down
14 changes: 7 additions & 7 deletions packages/frontend/src/common/dialogs/Participant.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Box, Typography } from "@mui/material";
import { AddModerator, LocalPolice, Person, RemoveCircle } from "@mui/icons-material";
import { TransferModeratorRoleDialog } from "../../retro/components/dialogs/TransferModeratorRoleDialog";
import { PromoteToModeratorDialog } from "../../retro/components/dialogs/PromoteToModeratorDialog";
import { isModerator } from "../utils/participantsUtils";
import { useUserContext } from "../context/UserContext";
import { User } from "../types/commonTypes";
Expand All @@ -12,12 +12,12 @@ import { TooltipIconButton } from "../components/buttons/TooltipIconButton";
interface ParticipantProps {
participant: User;
handleKickUser: (userId: string) => void;
handleTransferModeratorRole: (userId: string) => void;
handlePromoteToModerator: (userId: string) => void;
}
export function Participant({
participant,
handleKickUser,
handleTransferModeratorRole,
handlePromoteToModerator,
}: ParticipantProps) {
const { isOpen, openDialog, closeDialog } = useDialog();

Expand All @@ -39,10 +39,10 @@ export function Participant({
{isModerator(user) && (
<>
<TooltipIconButton
aria-label="Transfer Moderator Role"
aria-label="Promote to Moderator"
onClick={openDialog}
disabled={isModerator(participant)}
tooltipText="Transfer Moderator Role"
tooltipText="Promote to Moderator"
>
<AddModerator />
</TooltipIconButton>
Expand All @@ -59,11 +59,11 @@ export function Participant({
)}
</Box>
</FlexBox>
<TransferModeratorRoleDialog
<PromoteToModeratorDialog
participant={participant}
isOpen={isOpen}
close={closeDialog}
handleTransferModeratorRole={handleTransferModeratorRole}
handlePromoteToModerator={handlePromoteToModerator}
/>
</>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/common/dialogs/Participants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { UserByUserId } from "../../retro/types/retroTypes";
interface ParticipantsProps {
participants: UserByUserId;
handleKickUser: (userId: string) => void;
handleTransferModeratorRole: (userId: string) => void;
handlePromoteToModerator: (userId: string) => void;
}

export function Participants({
participants,
handleKickUser,
handleTransferModeratorRole,
handlePromoteToModerator,
}: ParticipantsProps) {
return (
<ul style={{ margin: 0, padding: 0 }}>
Expand All @@ -20,7 +20,7 @@ export function Participants({
<Participant
participant={participant}
handleKickUser={handleKickUser}
handleTransferModeratorRole={handleTransferModeratorRole}
handlePromoteToModerator={handlePromoteToModerator}
/>
</li>
))}
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/common/dialogs/ParticipantsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ParticipantDialogProps extends DialogProps {
onKickUser: (userId: string) => void;
onRejectJoinUser: (userId: string) => void;
onAcceptJoinUser: (userId: string) => void;
onTransferModeratorRole: (userId: string) => void;
onPromoteToModerator: (userId: string) => void;
}

export function ParticipantsDialog({
Expand All @@ -31,7 +31,7 @@ export function ParticipantsDialog({
onKickUser,
onRejectJoinUser,
onAcceptJoinUser,
onTransferModeratorRole,
onPromoteToModerator,
participants,
waitingList,
}: ParticipantDialogProps) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export function ParticipantsDialog({
<Participants
participants={participants}
handleKickUser={onKickUser}
handleTransferModeratorRole={onTransferModeratorRole}
handlePromoteToModerator={onPromoteToModerator}
/>
</>
)}
Expand Down
4 changes: 1 addition & 3 deletions packages/frontend/src/common/types/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ export interface BaseAction {
type: string;
}

export type UserRole = "moderator" | "participant";

export interface User {
id: string;
role: UserRole;
isModerator: boolean;
name: string;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/common/types/peerToPeerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export interface KickAction extends BaseAction {
type: "KICK";
}

export interface TransferModeratorRoleAction extends BaseAction {
type: "TRANSFER_MODERATOR_ROLE";
export interface PromoteToModeratorAction extends BaseAction {
type: "PROMOTE_TO_MODERATOR";
payload: string;
}

Expand All @@ -39,6 +39,6 @@ export type PeerToPeerAction<T> =
| JoinSessionAction
| DisconnectAction
| KickAction
| TransferModeratorRoleAction
| PromoteToModeratorAction
| RemoveFromWaitingListAction
| AddToWaitingListAction;
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export function determineNewModerator<T extends User>(users: T[]): T | undefined
const [newModerator] = users.sort((a, b) => a.id.localeCompare(b.id));
if (!newModerator) return;

return { ...newModerator, role: "moderator" };
return { ...newModerator, isModerator: true };
}
8 changes: 4 additions & 4 deletions packages/frontend/src/common/utils/participantsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ export function getRemainingParticipantsWithNewModerator<T extends User>(
};
}

export function findModerator<T extends User>(participants: Record<string, T>) {
return Object.values(participants).find((participant) => isModerator(participant));
export function findModerators<T extends User>(participants: Record<string, T>) {
return Object.values(participants).filter((participant) => isModerator(participant));
}

export function isModerator(user: User) {
return user.role === "moderator";
return user.isModerator;
}

export function hasRemainingModerator<T extends User>(
participants: Record<string, T>,
disconnectedUserId: string
) {
return Object.values(participants).some(
({ id, role }) => disconnectedUserId !== id && role === "moderator"
({ id, isModerator }) => disconnectedUserId !== id && isModerator
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/poker/components/PokerPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function PokerPageContent() {
handleKickUser,
handleAcceptJoinUser,
handleRejectJoinUser,
handleTransferModeratorRole,
handlePromoteToModerator,
handleAddToWaitingList,
} = usePokerContext();
const { user, resetUser } = useUserContext();
Expand Down Expand Up @@ -74,7 +74,7 @@ export function PokerPageContent() {
onKickUser={handleKickUser}
onAcceptJoinUser={handleAcceptJoinUser}
onRejectJoinUser={handleRejectJoinUser}
onTransferModeratorRole={handleTransferModeratorRole}
onPromoteToModerator={handlePromoteToModerator}
/>
<WaitingForApproval />
</>
Expand All @@ -88,7 +88,7 @@ export function PokerPageContent() {
onKickUser={handleKickUser}
onAcceptJoinUser={handleAcceptJoinUser}
onRejectJoinUser={handleRejectJoinUser}
onTransferModeratorRole={handleTransferModeratorRole}
onPromoteToModerator={handlePromoteToModerator}
>
<EstimationUnitSetupMenuItem />
</AppHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function CreatePokerSessionDialog() {
...user,
id: generateId(),
name,
role: "moderator",
isModerator: true,
};
setRoomId(roomId);
setUser(newUser);
Expand Down
10 changes: 5 additions & 5 deletions packages/frontend/src/poker/context/PokerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { useErrorContext } from "../../common/context/ErrorContext";
import {
AddToWaitingListAction,
JoinSessionAction,
PromoteToModeratorAction,
RemoveFromWaitingListAction,
TransferModeratorRoleAction,
} from "../../common/types/peerToPeerTypes";
import { useSyncUser } from "../../common/hooks/useSyncUser";
import { useUserContext } from "../../common/context/UserContext";
Expand All @@ -33,7 +33,7 @@ export interface PokerContextValues {
handleResetUserStory: () => void;
handleSetPokerUnit: (payload: SetPokerUnitAction["payload"]) => void;
handleSendVote: (payload: SendVoteAction["payload"]) => void;
handleTransferModeratorRole: (payload: TransferModeratorRoleAction["payload"]) => void;
handlePromoteToModerator: (payload: PromoteToModeratorAction["payload"]) => void;
handleKickUser: (userId: string) => void;
handleJoinSession: (payload: JoinSessionAction["payload"]) => void;
handleRejectJoinUser: (userId: string) => void;
Expand Down Expand Up @@ -126,8 +126,8 @@ export function PokerContextProvider(props: PokerContextProviderProps) {
dispatchAndBroadcast({ type: "SEND_VOTE", payload });
}

function handleTransferModeratorRole(payload: TransferModeratorRoleAction["payload"]) {
dispatchAndBroadcast({ type: "TRANSFER_MODERATOR_ROLE", payload });
function handlePromoteToModerator(payload: PromoteToModeratorAction["payload"]) {
dispatchAndBroadcast({ type: "PROMOTE_TO_MODERATOR", payload });
}

function handleKickUser(userId: string) {
Expand All @@ -152,7 +152,7 @@ export function PokerContextProvider(props: PokerContextProviderProps) {
handleResetUserStory,
handleSetPokerUnit,
handleSendVote,
handleTransferModeratorRole,
handlePromoteToModerator,
handleKickUser,
handleJoinSession,
handleAddToWaitingList,
Expand Down
Loading