Skip to content

Commit

Permalink
Merge pull request #5 from m4rc0z/restaurant_infos
Browse files Browse the repository at this point in the history
Restaurant infos
  • Loading branch information
m4rc0z authored Nov 1, 2019
2 parents 784508e + 3665630 commit 1309d95
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 51 deletions.
8 changes: 4 additions & 4 deletions cypress/fixtures/baseMenus.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Datum;Gang1;Gang2;Gang3
01.02.2019;Salat;Schnitzel;Apfelstrudel
02.02.2019;Salat2;Schnitzel2;Apfelstrudel2
03.02.2019;Salat3;Schnitzel3;Apfelstrudel3
Datum;Gang1;Gang2;Gang3;Kategorien
01.02.2019;Salat;Schnitzel;Apfelstrudel;Vegan,Vegetarisch
02.02.2019;Salat2;Schnitzel2;Apfelstrudel2;
03.02.2019;Salat3;Schnitzel3;Apfelstrudel3;
21 changes: 17 additions & 4 deletions cypress/fixtures/getMenusFixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6b",
"date": "2019-08-31T22:00:00.000Z"
"date": "2019-08-31T22:00:00.000Z",
"categories": []
},
{
"courses": [
Expand All @@ -43,7 +44,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6c",
"date": "2019-08-01T22:00:00.000Z"
"date": "2019-08-01T22:00:00.000Z",
"categories": []
},
{
"courses": [
Expand All @@ -64,7 +66,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6d",
"date": "2019-08-02T22:00:00.000Z"
"date": "2019-08-02T22:00:00.000Z",
"categories": []
},
{
"courses": [
Expand All @@ -85,7 +88,17 @@
}
],
"_id": "5d067afcd168d0239dce9d6d",
"date": "2019-04-08T22:00:00.000Z"
"date": "2019-04-08T22:00:00.000Z",
"categories": [
{
"_id": "abc",
"description": "Vegan"
},
{
"_id": "def",
"description": "Vegetarisch"
}
]
}
]
}
12 changes: 8 additions & 4 deletions cypress/fixtures/getMenusFixture2.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6b",
"date": "2019-08-31T22:00:00.000Z"
"date": "2019-08-31T22:00:00.000Z",
"categories": []
},
{
"courses": [
Expand All @@ -43,7 +44,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6c",
"date": "2019-08-01T22:00:00.000Z"
"date": "2019-08-01T22:00:00.000Z",
"categories": []
},
{
"courses": [
Expand All @@ -64,7 +66,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6d",
"date": "2019-08-02T22:00:00.000Z"
"date": "2019-08-02T22:00:00.000Z",
"categories": []
},
{
"courses": [
Expand All @@ -85,7 +88,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6d",
"date": "2019-04-08T22:00:00.000Z"
"date": "2019-04-08T22:00:00.000Z",
"categories": []
}
]
}
6 changes: 4 additions & 2 deletions cypress/fixtures/menusToDelete.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
}
],
"_id": "5d067afcd168d0239dce9d6c",
"date": "2019-08-01T22:00:00.000Z"
"date": "2019-08-01T22:00:00.000Z",
"categories": []
},
{
"courses": [
Expand All @@ -39,6 +40,7 @@
}
],
"_id": "5d067afcd168d0239dce9d6d",
"date": "2019-08-02T22:00:00.000Z"
"date": "2019-08-02T22:00:00.000Z",
"categories": []
}
]
37 changes: 20 additions & 17 deletions cypress/integration/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ describe('App', () => {

describe('Restaurant Menus Non-Admin', () => {
describe('Load Menus', () => {
it('should show requested menus if user is logged in', () => {
it.only('should show requested menus if user is logged in', () => {
cy.server();
cy.fixture('./getMenusFixture.json').as('getMenusFixture');
cy.route(
'GET',
'/api/restaurants/testRestaurant/menus',
'authenticated/api/restaurants/testRestaurant/menus',
'@getMenusFixture',
).as('getMenusForWeek');
cy.visit('/restaurants/testRestaurant', {
Expand All @@ -121,7 +121,10 @@ describe('App', () => {
.get('[data-cy=week15MenuIndex0course2]')
.contains('Schnitzel')
.get('[data-cy=week15MenuIndex0course3]')
.contains('Eis');
.contains('Eis')
.get('[data-cy=week15MenuIndex0categories]')
.contains('Vegan')
.contains('Vegetarisch');

cy
.get('[data-cy=expansionPanelTitle31]')
Expand All @@ -135,7 +138,7 @@ describe('App', () => {
});
});
describe('Save Menus', () => {
function checkMenuOverView(index, dateString, course1, course2, course3) {
function checkMenuOverView(index, dateString, course1, course2, course3, categories) {
cy.get(`[data-cy=menuOverview_${index}_date]`).contains(dateString);
cy.get(`[data-cy=menuOverview_${index}_course1]`).contains(course1);
cy.get(`[data-cy=menuOverview_${index}_course2]`).contains(course2);
Expand Down Expand Up @@ -172,7 +175,7 @@ describe('App', () => {
cy.server();
cy.route({
method: 'PUT',
url: 'api/restaurants/testRestaurant/menus',
url: 'authenticated/api//restaurants/testRestaurant/menus',
status: 200,
response: {},
}).as('saveMenus');
Expand Down Expand Up @@ -209,7 +212,7 @@ describe('App', () => {
cy.server();
cy.route({
method: 'PUT',
url: 'api/restaurants/testRestaurant/menus',
url: 'authenticated/api//restaurants/testRestaurant/menus',
status: 500,
response: {},
}).as('saveMenus');
Expand Down Expand Up @@ -249,14 +252,14 @@ describe('App', () => {
cy.server();
cy.route({
method: 'PUT',
url: 'api/restaurants/testRestaurant/menus',
url: 'authenticated/api//restaurants/testRestaurant/menus',
status: 200,
response: {},
}).as('saveMenus');

cy.route({
method: 'GET',
url: '/api/restaurants/testRestaurant/menus',
url: 'authenticated/api/restaurants/testRestaurant/menus',
onResponse: () => {
done();
},
Expand All @@ -277,7 +280,7 @@ describe('App', () => {
cy.server();
cy.route({
method: 'DELETE',
url: 'api/restaurants/testRestaurant/menus',
url: 'authenticated/api/restaurants/testRestaurant/menus',
status: 200,
response: {},
onRequest(...args) {
Expand All @@ -288,7 +291,7 @@ describe('App', () => {
cy.fixture('./getMenusFixture.json').as('getMenusFixture');
cy.route(
'GET',
'api/restaurants/testRestaurant/menus',
'authenticated/api/restaurants/testRestaurant/menus',
'@getMenusFixture',
).as('getMenusForWeek');

Expand All @@ -309,15 +312,15 @@ describe('App', () => {
cy.server();
cy.route({
method: 'DELETE',
url: '/api/restaurants/testRestaurant/menus',
url: 'authenticated/api/restaurants/testRestaurant/menus',
status: 200,
response: {},
}).as('deleteMenus');

cy.fixture('./getMenusFixture.json').as('getMenusFixture');
cy.route(
'GET',
'/api/restaurants/testRestaurant/menus',
'authenticated/api/restaurants/testRestaurant/menus',
'@getMenusFixture',
).as('getMenusForWeek');

Expand All @@ -344,13 +347,13 @@ describe('App', () => {
cy.fixture('./getMenusFixture.json').as('getMenusFixture');
cy.route(
'GET',
'/api/restaurants/testRestaurant/menus',
'authenticated/api/restaurants/testRestaurant/menus',
'@getMenusFixture',
).as('getMenusForWeek');
cy.fixture('./getMenusFixture2.json').as('getMenusFixture2');
cy.route(
'GET',
'/api/restaurants/testRestaurant2/menus',
'authenticated/api/restaurants/testRestaurant2/menus',
'@getMenusFixture2',
).as('getMenusForWeek2');
cy.visit('/restaurants/testRestaurant', {
Expand Down Expand Up @@ -408,7 +411,7 @@ describe('App', () => {
cy.fixture('./getRestaurantsFixture.json').as('getRestaurants');
cy.route(
'GET',
'/api/restaurants/',
'authenticated/api/restaurants/',
'@getRestaurants',
).as('getRestaurants');

Expand All @@ -434,13 +437,13 @@ describe('App', () => {
cy.fixture('./getMenusFixture.json').as('getMenusFixture');
cy.route(
'GET',
'/api/restaurants/testRestaurant/menus',
'authenticated/api/restaurants/testRestaurant/menus',
'@getMenusFixture',
).as('getMenusForWeek');
cy.fixture('./getMenusFixture2.json').as('getMenusFixture2');
cy.route(
'GET',
'/api/restaurants/testRestaurant2/menus',
'authenticated/api/restaurants/testRestaurant2/menus',
'@getMenusFixture2',
).as('getMenusForWeek2');
cy.visit('/restaurants/testRestaurant', {
Expand Down
7 changes: 7 additions & 0 deletions src/menu/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const MenuList = (props) => {
<FlexColumnContainer>
<FlexContainer>
<HeadingContainer>Wochentag</HeadingContainer>
<HeadingContainer>Preis</HeadingContainer>
<HeadingContainer>Kategorien</HeadingContainer>
<HeadingContainer>Gang 1</HeadingContainer>
<HeadingContainer>Gang 2</HeadingContainer>
<HeadingContainer>Gang 3</HeadingContainer>
Expand All @@ -24,6 +26,11 @@ const MenuList = (props) => {
return (
menu.courses && menu.courses.length > 0 && <FlexContainer key={i}>
<FlexGrowContainer>{getWeekDay(new Date(menu.date))}</FlexGrowContainer>
<FlexGrowContainer>{menu.price}</FlexGrowContainer>
<FlexGrowContainer data-cy={`week${props.weekNumber}MenuIndex${i}categories`}>{menu.categories.reduce((acc, curr) => {
acc += curr.description;
return acc;
}, '')}</FlexGrowContainer>
<FlexGrowContainer data-cy={`week${props.weekNumber}MenuIndex${i}course1`}>{menu.courses[0] && menu.courses[0].description}</FlexGrowContainer>
<FlexGrowContainer data-cy={`week${props.weekNumber}MenuIndex${i}course2`}>{menu.courses[1] && menu.courses[1].description}</FlexGrowContainer>
<FlexGrowContainer data-cy={`week${props.weekNumber}MenuIndex${i}course3`}>{menu.courses[2] && menu.courses[2].description}</FlexGrowContainer>
Expand Down
39 changes: 35 additions & 4 deletions src/menu/RestaurantMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ import {
deleteRestaurantMenusForWeekNumberAction,
getRestaurantMenusAction
} from "../restaurant/redux/restaurantActions";
import CardContent from "@material-ui/core/es/CardContent/CardContent";
import Card from "@material-ui/core/Card/Card";
import IconButton from "@material-ui/core/es/IconButton/IconButton";
import Icon from "@material-ui/icons/Edit";
import styled from "styled-components";

const StyledCardContainer = styled(CardContent)`
display: flex;
justify-content: space-between;
align-items: center;
`;

const StyledCard = styled(Card)`
margin-bottom: 10px;
`;

function RestaurantMenus(props) {

Expand All @@ -19,26 +34,42 @@ function RestaurantMenus(props) {
props.deleteRestaurantMenusForWeekNumberAction(weekNumber, props.restaurantId);
};

// TODO: add back button to navbar for edit case
// TODO: remove link and use restaurant name with edit button
return (
<div data-cy={`menu_container`}>
<StyledCard>
<StyledCardContainer>
<div>
<div>{props.restaurant && props.restaurant.name}</div>
</div>
<div>
<IconButton onClick={() => props.click()}>
<Icon></Icon>
</IconButton>
</div>
</StyledCardContainer>
</StyledCard>
<MenuImport auth={props.auth} restaurantId={props.restaurantId}/>
<MenuPanel menus={props.menus} deleteMenus={(weekNumber) => deleteMenus(weekNumber)}/>
<MenuPanel menus={props.restaurant && props.restaurant.menus}
deleteMenus={(weekNumber) => deleteMenus(weekNumber)}/>
</div>
);
}

RestaurantMenus.propTypes = {
auth: PropTypes.object.isRequired,
menus: PropTypes.array,
restaurant: PropTypes.object,
restaurantId: PropTypes.string.isRequired,
getRestaurantMenusAction: PropTypes.func,
deleteRestaurantMenusForWeekNumberAction: PropTypes.func,
click: PropTypes.func,
};

const mapStateToProps = (state, ownProps) => {
const menus = state.restaurants[ownProps.restaurantId] && state.restaurants[ownProps.restaurantId].menus;
const restaurant = state.restaurants[ownProps.restaurantId];
return ({
menus: menus,
restaurant,
userId: state.auth.userId,
...ownProps
});
Expand Down
Loading

0 comments on commit 1309d95

Please sign in to comment.