From a7287dc69ebccdeac8be1ff8e8aa805d111383d6 Mon Sep 17 00:00:00 2001 From: Felix Ruf Date: Fri, 19 Jul 2024 11:47:10 +0200 Subject: [PATCH] adjusted tests --- src/Resources/src/enums/Diet.ts | 2 +- src/Resources/src/stores/dishesStore.ts | 3 +- .../tests/unit/dishes/DishTableRow.spec.ts | 11 +++---- .../tests/unit/fixtures/getCategories.json | 12 ++++---- .../tests/unit/stores/dishesStore.spec.ts | 30 ++++++++++++++++--- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/Resources/src/enums/Diet.ts b/src/Resources/src/enums/Diet.ts index e19a3cc87..75aeeb0d9 100644 --- a/src/Resources/src/enums/Diet.ts +++ b/src/Resources/src/enums/Diet.ts @@ -10,4 +10,4 @@ export function getDietTranslationMap() { dietTranslationMap.set('vegan', 'vegan'); dietTranslationMap.set('fleisch', 'meat'); return dietTranslationMap; -} \ No newline at end of file +} diff --git a/src/Resources/src/stores/dishesStore.ts b/src/Resources/src/stores/dishesStore.ts index 472af4b1a..ee23be980 100644 --- a/src/Resources/src/stores/dishesStore.ts +++ b/src/Resources/src/stores/dishesStore.ts @@ -112,7 +112,8 @@ export function useDishes() { } function dishContainsDiet(dish: Dish, searchStr: string) { - const translatedSearchStr = getDietTranslationMap().get(searchStr.toLowerCase().trim()) ?? searchStr.toLowerCase(); + const translatedSearchStr = + getDietTranslationMap().get(searchStr.toLowerCase().trim()) ?? searchStr.toLowerCase(); return dish.diet.toString().toLowerCase().includes(translatedSearchStr); } diff --git a/src/Resources/tests/unit/dishes/DishTableRow.spec.ts b/src/Resources/tests/unit/dishes/DishTableRow.spec.ts index ed474dc0b..96118f7dd 100644 --- a/src/Resources/tests/unit/dishes/DishTableRow.spec.ts +++ b/src/Resources/tests/unit/dishes/DishTableRow.spec.ts @@ -6,6 +6,7 @@ import Dishes from '../fixtures/getDishes.json'; import Categories from '../fixtures/getCategories.json'; import useApi from '@/api/api'; import { useCategories } from '@/stores/categoriesStore'; +import { Dish } from '@/stores/dishesStore'; const asyncFunc: () => Promise = async () => { new Promise((resolve) => resolve(undefined)); @@ -31,7 +32,7 @@ describe('Test DishTableRow', () => { it('should render the dish from the props with no variations', async () => { const wrapper = mount(DishTableRow, { props: { - dish: Dishes[4], + dish: Dishes[4] as Dish, indexInList: 4 } }); @@ -45,7 +46,7 @@ describe('Test DishTableRow', () => { if (index === 0) { expect(td.text()).toBe(Dishes[4].titleEn); } else if (index === 1) { - expect(td.text()).toBe('Meat'); + expect(td.text()).toBe('Pasta'); } }); }); @@ -53,7 +54,7 @@ describe('Test DishTableRow', () => { it('should render the dish from the props with variations', async () => { const wrapper = mount(DishTableRow, { props: { - dish: Dishes[0], + dish: Dishes[0] as Dish, indexInList: 0 } }); @@ -73,7 +74,7 @@ describe('Test DishTableRow', () => { it('should render the dish variations with topShadow and bottomShadow classes', () => { const wrapper = mount(DishTableRow, { props: { - dish: Dishes[0], + dish: Dishes[0] as Dish, indexInList: 0 } }); @@ -86,7 +87,7 @@ describe('Test DishTableRow', () => { it('should render the dish variation with topBottomShadow class', () => { const wrapper = mount(DishTableRow, { props: { - dish: Dishes[8], + dish: Dishes[8] as Dish, indexInList: 8 } }); diff --git a/src/Resources/tests/unit/fixtures/getCategories.json b/src/Resources/tests/unit/fixtures/getCategories.json index e36b018e0..ad6a34349 100644 --- a/src/Resources/tests/unit/fixtures/getCategories.json +++ b/src/Resources/tests/unit/fixtures/getCategories.json @@ -7,14 +7,14 @@ }, { "id": 5, - "titleDe": "Vegetarisch", - "titleEn": "Vegetarian", - "slug": "vegetarian" + "titleDe": "Suppe", + "titleEn": "Soup", + "slug": "soup" }, { "id": 6, - "titleDe": "Fleisch", - "titleEn": "Meat", - "slug": "meat" + "titleDe": "Pasta", + "titleEn": "Pasta", + "slug": "pasta" } ] diff --git a/src/Resources/tests/unit/stores/dishesStore.spec.ts b/src/Resources/tests/unit/stores/dishesStore.spec.ts index 55f7b0142..8da84c8f2 100644 --- a/src/Resources/tests/unit/stores/dishesStore.spec.ts +++ b/src/Resources/tests/unit/stores/dishesStore.spec.ts @@ -132,11 +132,33 @@ describe('Test dishesStore', () => { setFilter('Vegetarisch'); await new Promise((r) => setTimeout(r, 1100)); for (const dish of filteredDishes.value) { - expect(dish.categoryId).toBe(5); + expect(dish.diet).toBe('vegetarian'); } - expect(filteredDishes.value).not.toContainEqual(Dishes[3]); - expect(filteredDishes.value).toContainEqual(Dishes[0]); - }); + + setFilter('Vegetarian'); + await new Promise((r) => setTimeout(r, 1100)); + for (const dish of filteredDishes.value) { + expect(dish.diet).toBe('vegetarian'); + } + + setFilter('Vegan'); + await new Promise((r) => setTimeout(r, 1100)); + for (const dish of filteredDishes.value) { + expect(dish.diet).toBe('vegan'); + } + + setFilter('Fleisch'); + await new Promise((r) => setTimeout(r, 1100)); + for (const dish of filteredDishes.value) { + expect(dish.diet).toBe('meat'); + } + + setFilter('Pasta'); + await new Promise((r) => setTimeout(r, 1100)); + for (const dish of filteredDishes.value) { + expect(dish.categoryId).toBe(6); + } + }, 10000); it('should update the state after sending a PUT request', async () => { await fetchDishes();