Skip to content

Commit

Permalink
๐Ÿฉน ์ธ์› ์ˆ˜ ์ œํ•œ & creatARoomView ํ…Œ์ŠคํŠธ์ฝ”๋“œ ์ž‘์„ฑ
Browse files Browse the repository at this point in the history
  • Loading branch information
NEM-NE committed Dec 1, 2021
1 parent ad7ab28 commit 6dd71ac
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/src/components/common/room-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function RoomCard({
</RoomCardProfileDiv>
<RoomCardUsers>
{userNameList(userNames)}
<ParticipantsNumberSpan>{`${participantsInfo.length} people`}</ParticipantsNumberSpan>
<ParticipantsNumberSpan>{`${participantsInfo.length} / 6 people`}</ParticipantsNumberSpan>
</RoomCardUsers>
</RoomCardInfo>
</RoomCardLayout>
Expand Down
11 changes: 10 additions & 1 deletion client/src/components/room/in-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState, RefObject } from 'react';
import { useSetRecoilState, useResetRecoilState } from 'recoil';
import { FiPlus, FiMic, FiMicOff } from 'react-icons/fi';

import toastListSelector from '@selectors/toast-list';
import roomDocumentIdState from '@atoms/room-document-id';
import roomViewState from '@atoms/room-view-type';
import isOpenRoomState from '@atoms/is-open-room';
Expand All @@ -28,6 +29,7 @@ function InRoomModal() {
const resetRoomDocumentId = useResetRecoilState(roomDocumentIdState);
const setIsOpenRoom = useSetRecoilState(isOpenRoomState);
const setIsOpenModal = useSetRecoilState(isOpenRoomModalState);
const setToastList = useSetRecoilState(toastListSelector);
const [roomInfo, setRoomInfo] = useState<IRooms>();
const [isMic, setMic] = useState(false);
const [
Expand All @@ -38,7 +40,14 @@ function InRoomModal() {
getRoomInfo(roomDocumentId)
.then((res: any) => {
if (!res) setRoomView('notFoundRoomView');
else setRoomInfo(res);
else if (res.participants.length > 5) {
setRoomView('createRoomView');
setToastList({
type: 'danger',
title: '๋ฐฉ ์ ‘์† ์‹คํŒจ',
description: '์ž…์žฅ ๊ฐ€๋Šฅ ์ธ์›์ˆ˜๊ฐ€ ์ดˆ๊ณผ๋˜์–ด ์ž…์žฅ์ด ๋ถˆ๊ฐ€๋Šฅ ํ•ฉ๋‹ˆ๋‹ค',
});
} else setRoomInfo(res);
});

return () => {
Expand Down
103 changes: 101 additions & 2 deletions client/src/components/room/new-view/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import RoomModal from './index';
ํƒœ์Šคํฌ
1. creat a room View์˜ ์š”์†Œ๋“ค์ด ์ œ๋Œ€๋กœ ๋ Œ๋”๋ง์ด ๋˜์—ˆ๋Š”๊ฐ€?
2. RoomTypeCheckBox๋ฅผ ํด๋ฆญํ•˜๋ฉด ํด๋ฆญํ•œ ์š”์†Œ์•  ๋งž๊ฒŒ ์„ ํƒ์ด๋œ๋‹ค.
3. AnonymousCheckBox๋ฅผ ํด๋ฆญํ•˜๋ฉด ์ฒดํฌ๋ฐ•์Šค๊ฐ€ ํ™œ์„ฑํ™”๋œ๋‹ค.
3. closed ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด anonymous ์ฒดํฌ๋ฐ•์Šค๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋œ๋‹ค.
4. TitleInputbar๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ œ๋ชฉ์ด ์ œ๋Œ€๋กœ ์ž…๋ ฅ์ด ๋˜๋Š”๊ฐ€?
5. let's go๋ฅผ ํด๋ฆญํ•˜๋ฉด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š”๊ฐ€?
6. Randomly assigned๋ฅผ ํด๋ฆญํ•˜๋ฉด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š”๊ฐ€?
Expand All @@ -22,30 +22,111 @@ function renderRoomModal() {
const result = render(<RecoilRoot><RoomModal /></RecoilRoot>);

const Title = () => result.getByText(`Let's have fun together!`);
const PublicCheckbox = () => result.getByText('public') as HTMLButtonElement;
const ClosedCheckbox = () => result.getByText('closed') as HTMLButtonElement;
const AnonymousCheckbox = () => result.getByLabelText('Allow anonymous ?') as HTMLInputElement;
const TitleInputLabel = () => result.getByText('Add a Room Title');
const TitleInputbar = () => result.getByTestId('TitleInputbar') as HTMLInputElement;
const LetsGoBtn = () => result.getByText(`Let's Go`);
const RandomBtn = () => result.getByText(`Randomly assigned`);

function changeTitle(title: string) {
userEvent.type(TitleInputbar(), title);
}

async function clickPublic() {
await act(async () => {
userEvent.click(PublicCheckbox());
});
}

async function clickClosed() {
await act(async () => {
userEvent.click(ClosedCheckbox());
});
}

function clickLetsGoBtn() {
userEvent.click(LetsGoBtn());
}

function clickRandomBtn() {
userEvent.click(RandomBtn());
}


return {
result,
Title,
PublicCheckbox,
ClosedCheckbox,
AnonymousCheckbox,
TitleInputLabel,
TitleInputbar,
LetsGoBtn,
RandomBtn,
changeTitle,
clickPublic,
clickClosed,
clickLetsGoBtn,
clickRandomBtn
};
}


describe('RoomModal ํ…Œ์ŠคํŠธ', () => {
it('creat a room View์˜ ์š”์†Œ๋“ค์ด ์ œ๋Œ€๋กœ ๋ Œ๋”๋ง์ด ๋˜์—ˆ๋Š”๊ฐ€?', async () => {
const { Title, TitleInputbar, LetsGoBtn } = renderRoomModal();
const {
Title, PublicCheckbox, ClosedCheckbox, AnonymousCheckbox,
TitleInputLabel, TitleInputbar, LetsGoBtn, RandomBtn,
} = renderRoomModal();

expect(Title()).toBeInTheDocument();
expect(PublicCheckbox()).toBeInTheDocument();
expect(ClosedCheckbox()).toBeInTheDocument();
expect(AnonymousCheckbox()).toBeInTheDocument();
expect(TitleInputLabel()).toBeInTheDocument();
expect(TitleInputbar()).toBeInTheDocument();
expect(LetsGoBtn()).toBeInTheDocument();
expect(RandomBtn()).toBeInTheDocument();
})

it('RoomTypeCheckBox๋ฅผ ํด๋ฆญํ•˜๋ฉด ํด๋ฆญํ•œ ์š”์†Œ์•  ๋งž๊ฒŒ ์„ ํƒ์ด๋œ๋‹ค.', async () => {
const { clickPublic, clickClosed } = renderRoomModal();
let test = document.querySelectorAll('button');
let style = window.getComputedStyle(test[0]);
let style2 = window.getComputedStyle(test[1]);

expect(style.backgroundColor).toBe(`rgb(216, 224, 235)`);
expect(style2.backgroundColor).toBe(`rgb(245, 245, 245)`);

await clickClosed();

test = document.querySelectorAll('button');
style = window.getComputedStyle(test[0]);
style2 = window.getComputedStyle(test[1]);

expect(style.backgroundColor).toBe(`rgb(245, 245, 245)`);
expect(style2.backgroundColor).toBe(`rgb(216, 224, 235)`);

await clickPublic();

test = document.querySelectorAll('button');
style = window.getComputedStyle(test[0]);
style2 = window.getComputedStyle(test[1]);

expect(style.backgroundColor).toBe(`rgb(216, 224, 235)`);
expect(style2.backgroundColor).toBe(`rgb(245, 245, 245)`);
})

it('closed ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด anonymous ์ฒดํฌ๋ฐ•์Šค๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋œ๋‹ค.', async () => {
const { clickClosed, AnonymousCheckbox } = renderRoomModal();

expect(AnonymousCheckbox().parentNode).toBeVisible();

await clickClosed();

expect(AnonymousCheckbox().parentNode).not.toBeVisible();
})

it('TitleInputbar๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ œ๋ชฉ์ด ์ œ๋Œ€๋กœ ์ž…๋ ฅ์ด ๋˜๋Š”๊ฐ€?', async () => {
Expand All @@ -57,4 +138,22 @@ describe('RoomModal ํ…Œ์ŠคํŠธ', () => {

expect(TitleInputbar().value).toBe('title');
})

it('์–‘์‹์— ๋งž๊ฒŒ ๋‹ค ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ Letsgo ๋ฒ„ํŠผ์ด ํ™œ์„ฑํ™” ๋˜๋Š”๊ฐ€?', async () => {
const { changeTitle, LetsGoBtn } = renderRoomModal();

expect(LetsGoBtn()).toBeDisabled();

changeTitle('input title');

expect(LetsGoBtn()).not.toBeDisabled();
});

it('lets go ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด post ์š”์ฒญ์„ ๋ณด๋‚ด๋Š”๊ฐ€?', async () => {

});

it('random ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด post ์š”์ฒญ์„ ๋ณด๋‚ด๋Š”๊ฐ€?', async () => {

});
});

0 comments on commit 6dd71ac

Please sign in to comment.