fix(client): fixed some issues on the client-side
This commit is contained in:
parent
04a999147c
commit
b77f4aee76
4 changed files with 34 additions and 8 deletions
|
|
@ -55,7 +55,7 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
|
|||
|
||||
// initialize the current unit if it is present
|
||||
unit.ifPresent(unitChoice::setValue);
|
||||
unitChoice.setItems(FXCollections.observableArrayList(Unit.GRAMME, Unit.KILOGRAMME, Unit.TONNE, Unit.INFORMAL));
|
||||
unitChoice.setItems(FXCollections.observableArrayList(Unit.values()));
|
||||
|
||||
// calls makeInputLine to create the inline edit container
|
||||
HBox container = makeInputLine(ingredient, amountInput, unitChoice);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import client.utils.DefaultValueFactory;
|
|||
import client.utils.LocaleAware;
|
||||
import client.utils.LocaleManager;
|
||||
import com.google.inject.Inject;
|
||||
import commons.FormalIngredient;
|
||||
import commons.Recipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -102,12 +103,13 @@ public class IngredientListCtrl implements LocaleAware {
|
|||
* @param event The action event.
|
||||
*/
|
||||
private void handleIngredientAdd(ActionEvent event) {
|
||||
this.ingredients.add(DefaultValueFactory.getDefaultFormalIngredient());
|
||||
FormalIngredient newIngredient = DefaultValueFactory.getDefaultFormalIngredient();
|
||||
this.ingredients.add(newIngredient);
|
||||
this.refresh();
|
||||
this.updateCallback.accept(this.ingredients);
|
||||
|
||||
var select = this.ingredientListView.getSelectionModel();
|
||||
select.select(this.ingredients.size() - 1);
|
||||
select.select(newIngredient);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
* @see DefaultValueFactory#getDefaultVagueIngredient()
|
||||
*/
|
||||
public class DefaultValueFactory {
|
||||
private static final Ingredient defaultIngredient = new Ingredient(0L, "default ingredient", 0., 0., 0.);
|
||||
/**
|
||||
* Instantiates a recipe with a default name and null-ID.
|
||||
* The ID is <code>null</code> such that it can be updated
|
||||
|
|
@ -37,7 +38,7 @@ public class DefaultValueFactory {
|
|||
*/
|
||||
public static FormalIngredient getDefaultFormalIngredient() {
|
||||
return new FormalIngredient(
|
||||
new Ingredient(0L, "default ingredient", 0., 0., 0.),
|
||||
defaultIngredient,
|
||||
0.0,
|
||||
Unit.GRAMME.suffix
|
||||
);
|
||||
|
|
@ -50,8 +51,7 @@ public class DefaultValueFactory {
|
|||
*/
|
||||
public static VagueIngredient getDefaultVagueIngredient() {
|
||||
return new VagueIngredient(
|
||||
new Ingredient(null,
|
||||
"default ingredient", 0., 0., 0.),
|
||||
defaultIngredient,
|
||||
"Some");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package client;
|
||||
|
||||
import client.utils.ServerUtils;
|
||||
import commons.Ingredient;
|
||||
import commons.Recipe;
|
||||
import commons.RecipeIngredient;
|
||||
import commons.VagueIngredient;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -14,6 +18,15 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
class ServerUtilsTest {
|
||||
static ServerUtils dv;
|
||||
static Recipe testRecipe;
|
||||
static final List<Ingredient> ingredients = List.of(
|
||||
new Ingredient("Bread", 1, 2, 3),
|
||||
new Ingredient("Cheese", 2, 2, 2),
|
||||
new Ingredient("Ham", 3, 3, 3)
|
||||
);
|
||||
static final List<RecipeIngredient> testIngredients = List.of(
|
||||
new VagueIngredient(ingredients.get(0), "2 pieces of"),
|
||||
new VagueIngredient(ingredients.get(1), "1 slice of")
|
||||
);
|
||||
final int fakeId = -1; // If suppose ID's are only positive
|
||||
|
||||
@BeforeEach
|
||||
|
|
@ -30,17 +43,28 @@ class ServerUtilsTest {
|
|||
Recipe r = new Recipe();
|
||||
|
||||
r.setName("Tosti");
|
||||
r.setIngredients(List.of("Bread", "Cheese", "Ham"));
|
||||
r.setIngredients(testIngredients);
|
||||
r.setPreparationSteps(List.of("Step 1:", "Step 2"));
|
||||
|
||||
testRecipe = dv.addRecipe(r);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() throws IOException, InterruptedException {
|
||||
dv.getRecipes().stream().map(Recipe::getId).forEach(id -> {
|
||||
try {
|
||||
dv.deleteRecipe(id);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Teardown failed: " + ex.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void addRecipeTest() throws IOException, InterruptedException {
|
||||
Recipe r = new Recipe();
|
||||
r.setName("Eggs on toast");
|
||||
r.setIngredients(List.of("Bread", "egg", "salt"));
|
||||
r.setIngredients(testIngredients);
|
||||
r.setPreparationSteps(List.of("Step 1:", "Step 2"));
|
||||
|
||||
testRecipe = dv.addRecipe(r);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue