Skip to content

Commit

Permalink
adjusted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Ruf committed Jul 19, 2024
1 parent 13502c6 commit a7287dc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Resources/src/enums/Diet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export function getDietTranslationMap() {
dietTranslationMap.set('vegan', 'vegan');
dietTranslationMap.set('fleisch', 'meat');
return dietTranslationMap;
}
}
3 changes: 2 additions & 1 deletion src/Resources/src/stores/dishesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 6 additions & 5 deletions src/Resources/tests/unit/dishes/DishTableRow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> = async () => {
new Promise((resolve) => resolve(undefined));
Expand All @@ -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
}
});
Expand All @@ -45,15 +46,15 @@ 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');
}
});
});

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
}
});
Expand All @@ -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
}
});
Expand All @@ -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
}
});
Expand Down
12 changes: 6 additions & 6 deletions src/Resources/tests/unit/fixtures/getCategories.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
30 changes: 26 additions & 4 deletions src/Resources/tests/unit/stores/dishesStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a7287dc

Please sign in to comment.