Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuJLund committed Jul 1, 2024
1 parent 9948c21 commit a6684ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void detach() {
// https://github.com/vaadin/flow/issues/17215
@WebServlet(value = "/*", asyncSupported = true, initParams = {
@WebInitParam(name = "org.atmosphere.websocket.maxIdleTime", value = "300000") })
@VaadinServletConfiguration(productionMode = false, ui = VaadinCreateUI.class)
@VaadinServletConfiguration(productionMode = false, ui = VaadinCreateUI.class, closeIdleSessions = true)
public static class Servlet extends VaadinServlet {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public void editProduct(Product product) {
if (product != null) {
// Ensure the product is up-to-date
if (product.getId() > 0) {
product = refreshProduct(dataProvider, product);
product = refreshProduct(product);
}
form.showForm(true);
} else {
Expand Down Expand Up @@ -448,8 +448,7 @@ public void eventFired(Object event) {
}
}

private Product refreshProduct(ListDataProvider<Product> dataProvider,
Product product) {
private Product refreshProduct(Product product) {
var list = ((List<Product>) dataProvider.getItems());
var updatedProduct = presenter.findProduct(product.getId());
list.set(list.indexOf(product), updatedProduct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ public void deleteProduct() {
public void editProduct() {
var book = test(grid).item(0);
test(grid).click(1, 0);
assertTrue(form.isShown());

var id = book.getId();

test(form.productName).setValue("Edited book");
test(form.save).click();
assertFalse(form.isShown());

var edited = ui.getProductService().getProductById(id);

Expand All @@ -231,6 +233,25 @@ public void editProduct() {
test(grid).styleName(0));
}

@Test
public void openProductChangedByOtherUser() {
var book = test(grid).item(0);

// Simulate other user persisting a change to the database
var edited = ui.getProductService().getProductById(book.getId());
edited.setProductName("Touched book");
ui.getProductService().updateProduct(edited);

test(grid).click(1, 0);
assertTrue(form.isShown());

// Assert that change is visible when product is opened
assertEquals("Touched book", form.productName.getValue());

var name = (String) test(grid).cell(1, 0);
assertEquals("Touched book", name);
}

@Test
public void editLockedProduct() {
var book = test(grid).item(0);
Expand Down Expand Up @@ -379,7 +400,7 @@ public void resizeTest() {

@Test
public void sortingByPrice() {
int size = grid.getDataCommunicator().getDataProviderSize();
int size = test(grid).size();

test(grid).toggleColumnSorting(2);

Expand All @@ -400,7 +421,7 @@ public void sortingByPrice() {

@Test
public void sortingByName() {
int size = grid.getDataCommunicator().getDataProviderSize();
int size = test(grid).size();

test(grid).toggleColumnSorting(1);

Expand Down

0 comments on commit a6684ff

Please sign in to comment.