From 3cea05b6eb84d5b621ff7aee844686c225831efc Mon Sep 17 00:00:00 2001 From: hellomuthu23 Date: Wed, 14 Feb 2024 22:51:08 +0000 Subject: [PATCH] feat: Add isAllowMembersToManageSession property to PlayerGame and Game interfaces --- .../Players/PlayerCard/PlayerCard.tsx | 2 +- .../Poker/CreateGame/CreateGame.test.tsx | 34 ++++++++++++- .../Poker/CreateGame/CreateGame.tsx | 13 +++++ .../Poker/GameController/GameController.tsx | 2 +- .../Poker/RecentGames/RecentGames.tsx | 8 ++- src/types/game.ts | 2 + src/types/player.ts | 1 + src/utils/isModerator.test.ts | 51 +++++++++++++++++++ src/utils/isModerator.ts | 11 +++- 9 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 src/utils/isModerator.test.ts diff --git a/src/components/Players/PlayerCard/PlayerCard.tsx b/src/components/Players/PlayerCard/PlayerCard.tsx index e20d882..a35c5cc 100644 --- a/src/components/Players/PlayerCard/PlayerCard.tsx +++ b/src/components/Players/PlayerCard/PlayerCard.tsx @@ -34,7 +34,7 @@ export const PlayerCard: React.FC = ({ game, player, currentPla title={player.name} titleTypographyProps={{ variant: 'subtitle2', noWrap: true, title: player.name }} action={ - isModerator(game.createdById, currentPlayerId) && + isModerator(game.createdById, currentPlayerId, game.isAllowMembersToManageSession) && player.id !== currentPlayerId && ( { expect(gamesService.addNewGame).toHaveBeenCalled(); expect(gamesService.addNewGame).toHaveBeenCalledWith( - expect.objectContaining({ createdBy: 'Rock', gameType: 'Fibonacci', name: 'Marvels' }), + expect.objectContaining({ + createdBy: 'Rock', + gameType: 'Fibonacci', + name: 'Marvels', + isAllowMembersToManageSession: false, + }), + ); + }); + it('should be able to create new session with Allow members to manage session', async () => { + render(); + const sessionName = screen.getByPlaceholderText('Enter a session name'); + userEvent.clear(sessionName); + userEvent.type(sessionName, 'Marvels'); + + const userName = screen.getByPlaceholderText('Enter your name'); + userEvent.clear(userName); + userEvent.type(userName, 'Rock'); + + const allowMembersToManageSession = screen.getByText('Allow members to manage session'); + userEvent.click(allowMembersToManageSession); + + const createButton = screen.getByText('Create'); + userEvent.click(createButton); + + expect(gamesService.addNewGame).toHaveBeenCalled(); + + expect(gamesService.addNewGame).toHaveBeenCalledWith( + expect.objectContaining({ + createdBy: 'Rock', + gameType: 'Fibonacci', + name: 'Marvels', + isAllowMembersToManageSession: true, + }), ); }); it('should be able to create new session of TShirt Sizing', async () => { diff --git a/src/components/Poker/CreateGame/CreateGame.tsx b/src/components/Poker/CreateGame/CreateGame.tsx index b8ddacf..21da6cc 100644 --- a/src/components/Poker/CreateGame/CreateGame.tsx +++ b/src/components/Poker/CreateGame/CreateGame.tsx @@ -4,6 +4,7 @@ import { CardActions, CardContent, CardHeader, + Checkbox, FormControlLabel, Grow, Radio, @@ -35,6 +36,7 @@ export const CreateGame = () => { const [gameType, setGameType] = useState(GameType.Fibonacci); const [hasDefaults, setHasDefaults] = useState({ game: true, name: true }); const [loading, setLoading] = useState(false); + const [allowMembersToManageSession, setAllowMembersToManageSession] = useState(false); const [customOptions, setCustomOptions] = React.useState(Array(10).fill('')); const [error, setError] = React.useState(false); const { t } = useTranslation(); @@ -56,6 +58,7 @@ export const CreateGame = () => { name: gameName, createdBy: createdBy, gameType: gameType, + isAllowMembersToManageSession: allowMembersToManageSession, cards: gameType === GameType.Custom ? getCustomCards(customOptions) : getCards(gameType), createdAt: new Date(), }; @@ -183,6 +186,16 @@ export const CreateGame = () => { )} )} + setAllowMembersToManageSession(!allowMembersToManageSession)} + /> + } + label='Allow members to manage session' + />