render stubbed RoomButton component on Home
This commit is contained in:
parent
3275fc18d6
commit
3e82a2c410
9 changed files with 74 additions and 7 deletions
13
play-node-go/src/components/Button/Room/Room.js
Normal file
13
play-node-go/src/components/Button/Room/Room.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
import React from 'react';
|
||||
import './Room.scss';
|
||||
|
||||
const RoomButton = (props) => {
|
||||
const roomData = props.room;
|
||||
return (
|
||||
<div className="RoomButton" data-testid="RoomButton">
|
||||
<h4 className="RoomButton__room-name">{roomData.name}</h4>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default RoomButton;
|
9
play-node-go/src/components/Button/Room/Room.scss
Normal file
9
play-node-go/src/components/Button/Room/Room.scss
Normal file
|
@ -0,0 +1,9 @@
|
|||
div.RoomButton {
|
||||
display: block;
|
||||
padding: 1vw;
|
||||
|
||||
.RoomButton__room-name {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
}
|
23
play-node-go/src/components/Button/Room/Room.test.js
Normal file
23
play-node-go/src/components/Button/Room/Room.test.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import Room from './Room';
|
||||
|
||||
const roomData = {
|
||||
id: 1,
|
||||
name: "main",
|
||||
description: "A general place to play Go",
|
||||
language: "EN"
|
||||
}
|
||||
|
||||
test('renders RoomButton without crashing', () => {
|
||||
const { getByTestId } = render(<Room room={roomData} />);
|
||||
const RoomButton = getByTestId('RoomButton');
|
||||
expect(RoomButton).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders RoomButton with Room name', () => {
|
||||
const { getByTestId } = render(<Room room={roomData} />);
|
||||
const RoomButton = getByTestId('RoomButton');
|
||||
expect(RoomButton).toHaveTextContent('main');
|
||||
});
|
||||
|
|
@ -1,8 +1,24 @@
|
|||
import React, { useEffect } from 'react';
|
||||
import './Home.scss';
|
||||
import roomsServices from '../../services/api/roomsServices';
|
||||
import RoomButton from '../../components/Button/Room/Room';
|
||||
|
||||
const Home = props => {
|
||||
const state = props.state;
|
||||
const dispatch = props.dispatch;
|
||||
|
||||
const renderRooms = () => {
|
||||
const rooms = state.rooms || [];
|
||||
if (rooms.length) {
|
||||
return rooms.map(roomData => (
|
||||
<RoomButton
|
||||
key={`room-${roomData.id}`}
|
||||
room={roomData}
|
||||
/>
|
||||
))
|
||||
}
|
||||
return <p>Loading Component</p>
|
||||
}
|
||||
|
||||
const fetchRoomsAPI = async () => {
|
||||
const response = await roomsServices.indexService();
|
||||
|
@ -12,7 +28,7 @@ const Home = props => {
|
|||
message: 'SET_ROOMS',
|
||||
body: response
|
||||
}
|
||||
return props.dispatch(action)
|
||||
return dispatch(action)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +40,7 @@ const Home = props => {
|
|||
<div className="page">
|
||||
|
||||
<div className="Home" data-testid="Home">
|
||||
<p>Home</p>
|
||||
{renderRooms()}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
div.Page div.Home {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
align-items: flex-start;
|
||||
justify-content: flex-start;
|
||||
}
|
|
@ -27,10 +27,10 @@ div.main-wrapper {
|
|||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-grow: 4;
|
||||
display: block;
|
||||
max-width: 80vw;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import './NavBar.scss';
|
||||
import Logo from '../../../components/Logo/Logo';
|
||||
import Logo from '../../../components/Button/Logo/Logo';
|
||||
|
||||
const NavBar = (props) => {
|
||||
|
||||
|
|
Loading…
Reference in a new issue