refactor(test/client): refactor client-side tests

This commit is contained in:
Zhongheng Liu 2025-12-29 14:02:24 +01:00
commit c0add049be
2 changed files with 13 additions and 11 deletions

View file

@ -25,7 +25,8 @@ class ServerUtilsTest {
);
static final List<RecipeIngredient> testIngredients = List.of(
new VagueIngredient(ingredients.get(0), "2 pieces of"),
new VagueIngredient(ingredients.get(1), "1 slice of")
new VagueIngredient(ingredients.get(1), "1 slice of"),
new VagueIngredient(ingredients.get(2), "1 slice of")
);
final int fakeId = -1; // If suppose ID's are only positive
@ -35,11 +36,6 @@ class ServerUtilsTest {
Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available");
//Making sure there is no recipe in the backend yet
for (Recipe recipe : dv.getRecipes()) {
dv.deleteRecipe(recipe.getId());
}
Recipe r = new Recipe();
r.setName("Tosti");
@ -92,7 +88,7 @@ class ServerUtilsTest {
assertEquals(testRecipe.getId(), r.getId());
assertEquals("Tosti", r.getName());
assertIterableEquals(List.of("Bread", "Cheese", "Ham"), r.getIngredients());
assertIterableEquals(testIngredients, r.getIngredients());
assertIterableEquals(List.of("Step 1:", "Step 2"), r.getPreparationSteps());
}

View file

@ -2,7 +2,10 @@ package client.scenes;
import client.utils.PrintExportService;
import client.utils.ServerUtils;
import commons.Ingredient;
import commons.Recipe;
import commons.RecipeIngredient;
import commons.VagueIngredient;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -18,6 +21,9 @@ import static org.junit.jupiter.api.Assertions.*;
public class PrintExportTest {
static ServerUtils dv = new ServerUtils();
private VagueIngredient getVague(String name) {
return new VagueIngredient(new Ingredient(name, 0., 0., 0.), "some");
}
@BeforeEach
public void setup(){
Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available");
@ -25,9 +31,9 @@ public class PrintExportTest {
@Test
public void buildRecipeTextTest(){
List<String> ingredients = new ArrayList<>();
ingredients.add("Banana");
ingredients.add("Bread");
List<RecipeIngredient> ingredients = new ArrayList<>();
ingredients.add(getVague("Banana"));
ingredients.add(getVague("Bread"));
final long testRecipeId = 1234L;
List<String> preparationSteps = new ArrayList<>();
preparationSteps.add("Mix Ingredients");
@ -37,7 +43,7 @@ public class PrintExportTest {
assertEquals("""
Title: Banana Bread
Recipe ID: 1234
Ingredients: Banana, Bread,\s
Ingredients: some Banana, some Bread,\s
Steps:
1: Mix Ingredients
2: Heat in Oven