From 672dd7ee63818c85dd49f716dac716af99eb0667 Mon Sep 17 00:00:00 2001 From: TatuJLund Date: Fri, 4 Oct 2024 20:57:52 +0300 Subject: [PATCH] fix: Set book form button initial states and assert --- .../java/org/vaadin/tatu/vaadincreate/crud/form/BookForm.java | 3 ++- .../java/org/vaadin/tatu/vaadincreate/crud/BooksViewTest.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/vaadincreate-ui/src/main/java/org/vaadin/tatu/vaadincreate/crud/form/BookForm.java b/vaadincreate-ui/src/main/java/org/vaadin/tatu/vaadincreate/crud/form/BookForm.java index 80857c6..61f1044 100644 --- a/vaadincreate-ui/src/main/java/org/vaadin/tatu/vaadincreate/crud/form/BookForm.java +++ b/vaadincreate-ui/src/main/java/org/vaadin/tatu/vaadincreate/crud/form/BookForm.java @@ -115,7 +115,6 @@ public BookForm(BooksPresenter presenter) { var hasChanges = binder.hasChanges(); saveButton.setEnabled(hasChanges && isValid); discardButton.setEnabled(hasChanges); - }); saveButton.addClickListener(event -> handleSave()); @@ -330,6 +329,8 @@ public void editProduct(Product product) { deleteButton.setEnabled(product.getId() != null); currentProduct = product; binder.readBean(product); + saveButton.setEnabled(false); + discardButton.setEnabled(false); // Scroll to the top // As this is not a Panel, using JavaScript diff --git a/vaadincreate-ui/src/test/java/org/vaadin/tatu/vaadincreate/crud/BooksViewTest.java b/vaadincreate-ui/src/test/java/org/vaadin/tatu/vaadincreate/crud/BooksViewTest.java index f0e4bef..e77e61b 100644 --- a/vaadincreate-ui/src/test/java/org/vaadin/tatu/vaadincreate/crud/BooksViewTest.java +++ b/vaadincreate-ui/src/test/java/org/vaadin/tatu/vaadincreate/crud/BooksViewTest.java @@ -129,6 +129,8 @@ private void verifySelectedCategoriesAreTheFirst() { @SuppressWarnings("unchecked") public void crossValidationAndDiscard() { test($(view, Button.class).id("new-product")).click(); + assertFalse($(form, Button.class).id("discard-button").isEnabled()); + assertFalse($(form, Button.class).id("save-button").isEnabled()); test($(form, TextField.class).id("product-name")).setValue("Te"); test($(form, AvailabilitySelector.class).id("availability"))