mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

Selecting items in a grid #109

Closed satorstefan closed 2 years ago

satorstefan commented 2 years ago

This

      Grid<PropertyDTO> grid = _get(details, Grid.class);

      PropertyDTO result = GridKt._get(grid, 0);

      grid.select(result);

code in the karibu based test is not the same that the client is calling.

The client is using selectFromClient(T item) in the end, which would throw an execption if trying to select items in a grid that does not support selection.

public class GridNoneSelectionModel implements GridSelectionModel { public GridNoneSelectionModel() { }

  public Set<T> getSelectedItems() {
      return Collections.emptySet();
  }

  public Optional<T> getFirstSelectedItem() {
      return Optional.empty();
  }

  public void select(T item) {
  }

  public void deselect(T item) {
  }

  public void deselectAll() {
  }

  public void selectFromClient(T item) {
      throw new IllegalStateException("Client tried to update

selection even though selection mode is currently set to NONE."); }

It seems to me that the client side is calling: @ClientCallable private void select(String key) { Optional var10000 = this.findByKey(String.valueOf(key)); GridSelectionModel var10001 = this.getSelectionModel(); var10000.ifPresent(var10001::selectFromClient); }

Why is there no way in karibu to select the items as the user would do it through the browser? / What is the way to select items in a grid?

mvysny commented 2 years ago

At the moment there's no special support for Grid selection from Karibu-Testing, which means that you can use the standard Grid API grid.select() (which unfortunately does nothing if Grid has no selection). What would be an ideal API? Probably the best would be to have grid._select(item: T) which would deselect all items, then select given item, failing if the grid doesn't support selection. That way, you could rely on what is selected (since grid.select() is ambiguous whether it deselects other items or not).

Also could be interesting to have support for grid._selectAll() which would only work for multi-select and would call AbstractGridMultiSelectionModel.clientSelectAll().

satorstefan commented 2 years ago

grid._select(item: T) sounds good to me.

I am wondering how this would work with a grid that uses lazy loading and were the item to be selected is not visible from the start.

Any idea Martin?

mvysny commented 2 years ago

Depends on how exactly the lazy loading works: whether it works in a bg thread or not. Please find some ideas at https://github.com/mvysny/karibu-testing/tree/master/karibu-testing-v10#testing-asynchronous-application

satorstefan commented 2 years ago

Hello Martin,

Is there a easy to to just test a component without having to add it to the the mainlayout?

Basically I want to test one of my custom component in isolation.

Everything that has a Route should be accessible, correct?

Would it be possible to have a meeting in 2-3 weeks so I could show you once how/and what I do with Karibu?

Best regards Stefan

Message ID: @.***>

mvysny commented 2 years ago

Please open a new ticket for questions unrelated to this ticket.