Skip to content

Commit

Permalink
Merge pull request #490 from AOEpeople/bugfix/#264727-participation-l…
Browse files Browse the repository at this point in the history
…imit-input

Bugfix/#264727 participation limit input
  • Loading branch information
hacksch authored Jul 16, 2024
2 parents a7ac846 + 11e97fd commit bbc10b7
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/Mealz/MealBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ MealzMealBundle_menu:
path: /menu/{week}
defaults: { _controller: App\Mealz\MealBundle\Controller\FrontendController::renderIndex }

MealzMealBundle_menu_create:
path: /menu/{week}/create
defaults:
_controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
path: /weeks
permanent: true

MealzMealBundle_weeks:
path: /weeks
defaults: { _controller: App\Mealz\MealBundle\Controller\FrontendController::renderIndex }
Expand Down
18 changes: 15 additions & 3 deletions src/Resources/src/components/menu/MenuParticipationPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
:meal="meal"
class="max-w-[300px] px-2"
/>
<span v-if="mealList.length < 1">
{{ t('menu.noMeals') }}
</span>
</div>
</template>

Expand All @@ -24,6 +27,9 @@ import { Dictionary } from 'types/types';
import MealParticipationInput from './MealParticipationInput.vue';
import { computed } from 'vue';
import { XCircleIcon } from '@heroicons/vue/solid';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const props = defineProps<{
meals: Dictionary<MealDTO[]>;
Expand All @@ -34,9 +40,9 @@ const emit = defineEmits(['closePanel']);
const mealList = computed(() => {
const keys = Object.keys(props.meals);
removeCombinedMealKey(keys);
const returnMealDTOs = [];
const returnMealDTOs: MealDTO[] = [];
keys.forEach((key) => {
if (parseInt(key) > 0) {
if (props.meals[key].length > 0) {
returnMealDTOs.push(...props.meals[key]);
}
});
Expand All @@ -46,7 +52,13 @@ const mealList = computed(() => {
function removeCombinedMealKey(keys: string[]) {
let indexToRemove = -1;
keys.forEach((mealId) => {
if (parseInt(mealId) > 0 && props.meals[mealId][0].dishSlug === 'combined-dish') {
if (
parseInt(mealId) > 0 &&
props.meals[mealId] !== undefined &&
props.meals[mealId] !== null &&
props.meals[mealId].length > 0 &&
props.meals[mealId][0].dishSlug === 'combined-dish'
) {
indexToRemove = keys.indexOf(mealId);
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@
"notFound": "Keine Profile für diese Anfrage gefunden",
"shortQuery": "Min. 3 Buchstaben für Suche eingeben",
"search": "Teilnehmer filtern",
"guest": "Gast"
"guest": "Gast",
"noMeals": "Noch keine Gerichte ausgewählt"
},
"printList": {
"title": "Teilnahmen am ",
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@
"notFound": "No profiles found for this query",
"shortQuery": "Min. 3 Buchstaben für Suche eingeben",
"search": "Filter participant",
"guest": "Gast"
"guest": "Gast",
"noMeals": "No dishes selected yet"
},
"printList": {
"title": "Participations on ",
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/views/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/>
<MenuDay
v-for="(day, index) in menu.days"
:key="day.id"
:key="Object.keys(day.meals).join()"
v-model="menu.days[index]"
:lockDates="lockDates"
class="mt-4"
Expand Down
158 changes: 153 additions & 5 deletions tests/e2e/cypress/e2e/MenuCreationRoundtrip.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ describe('Test Creating a Menu', () => {

cy.get('input')
.eq(12)
.should('have.value', 'Innards DE');
.should('have.value', 'Braaaaaiiinnnzzzzzz DE');

cy.get('input')
.eq(13)
.should('have.value', 'Braaaaaiiinnnzzzzzz DE');
.should('have.value', 'Innards DE');

// Test Participations
cy.get('span').contains('Teilnahmen').click();
Expand All @@ -299,7 +299,7 @@ describe('Test Creating a Menu', () => {
.parent()
.find('td')
.eq(4)
.click()
.click();

cy.wait('@putParticipation');

Expand Down Expand Up @@ -327,7 +327,7 @@ describe('Test Creating a Menu', () => {
.parent()
.find('td')
.eq(4)
.click()
.click();

cy.wait('@putParticipation');

Expand All @@ -353,7 +353,7 @@ describe('Test Creating a Menu', () => {
.parent()
.find('td')
.eq(4)
.click()
.click();

cy.wait('@deleteParticipation');

Expand All @@ -370,6 +370,154 @@ describe('Test Creating a Menu', () => {
.should('not.exist');
});

it('should create a menu with participation limits, delete a meal in the first row of a day and be able to set it again', () => {
cy.get('span > a').contains('Mahlzeiten').click();

cy.wait(['@getWeeks']);

// Go to 7th week (it should not have been created yet because of db reset)
cy.get('h4').eq(6).contains('Woche').click();

cy.wait(['@getDishesCount', '@getCategories', '@getDishes']);

// create menu
// Monday
cy.get('input')
.first()
.parent()
.find('svg')
.eq(1)
.click()
.parent()
.find('input')
.click()
.type('Tasty')
.parent().parent()
.find('li').contains('Tasty Worms DE')
.click();

cy.get('h2').should('contain', 'Woche').click();

cy.get('input')
.eq(1)
.parent()
.find('svg')
.eq(1)
.click()
.parent()
.find('input')
.click()
.parent().parent()
.find('li').contains('Limbs DE')
.click();

cy.get('h2').should('contain', 'Woche').click();

// Save
cy.contains('input', 'Speichern').click();

cy.wait(['@postWeeks', '@getWeeks']);

cy.get('[data-cy="msgClose"]').click();

// change participation limit
cy.get('input')
.first()
.parent()
.parent()
.parent()
.parent()
.find('div.col-start-1')
.first()
.find('button')
.first()
.click();

cy.get('[data-cy="meal-participation-limit-input"]')
.eq(1)
.clear()
.type('17');

cy.get('span').contains('Limit').parent().find('svg').click();

// Delete Meal
cy.get('h2').should('contain', 'Woche').click();

cy.get('input')
.first()
.parent()
.find('svg')
.eq(1)
.click();

cy.get('h2').should('contain', 'Woche').click();

// Save
cy.contains('input', 'Speichern').click();

cy.wait(['@putMenu', '@getWeeks']);

cy.get('[data-cy="msgClose"]').click();

// Check Limbs is now set as first input
cy.get('input')
.first()
.should('have.value', 'Limbs DE');

// Set new second Meal
cy.get('input')
.eq(1)
.parent()
.find('svg')
.eq(1)
.click()
.parent()
.find('input')
.click()
.parent().parent()
.find('li').contains('Braaaaaiiinnnzzzzzz DE')
.click();

cy.get('h2').should('contain', 'Woche').click();

// Save
cy.contains('input', 'Speichern').click();

cy.wait(['@putMenu', '@getWeeks']);

cy.get('[data-cy="msgClose"]').click();

// Check Meals are both saved
cy.get('input')
.first()
.should('have.value', 'Braaaaaiiinnnzzzzzz DE');

cy.get('input')
.eq(1)
.should('have.value', 'Limbs DE');

// Check participation limits
cy.get('input')
.first()
.parent()
.parent()
.parent()
.parent()
.find('div.col-start-1')
.first()
.find('button')
.first()
.click();

cy.get('[data-cy="meal-participation-limit-input"]')
.eq(0)
.should('have.value', 0);

cy.get('[data-cy="meal-participation-limit-input"]')
.eq(1)
.should('have.value', 17);
});

it('should not create a menu if the initial submission of a menu gets aborted', () => {
cy.get('span > a').contains('Mahlzeiten').click();

Expand Down

0 comments on commit bbc10b7

Please sign in to comment.