Browserless Test: Grid ItemDetailsRenderer

I want to test my Grid that has a ItemDetailsRenderer. I use the following code

grid.setItemDetailsRenderer(
    new ComponentRenderer<>(() -> new MyItemDetailsComponent(someService, someOtherService), MyItemDetailsComponent::setItem)); 
grid.setDetailsVisibleOnClick(true);

using this, I get a detail of the selected row when I click on the row itself.

now, I want to make sure that the details are opened when a user clicks on the row, by using Browserless Tests.

 @Test
    void testGrid_withOneEntity_shouldOpenDetailsOnClick() {
        final GridView gridView = navigate(GridView.class);
       //using selector as grid is private, not public / protected
        Grid<Item> grid = $(Grid.class, gridView).single();
        GridTester<Grid<Item>, Item> gridTest = test(grid);
        assertThat(gridTest.size()).isEqualTo(1); //there is a value present
        assertThat(grid.isDetailsVisibleOnClick()).isTrue(); //setting is present
        gridTest.clickRow(0);//does not open Details

        //lets try with a column
        Grid.Column<Item> column = grid.getColumns().get(0); //get any column, does not matter;
        ComponentTester<Grid.Column<Item>> columnTester = test(column);
        columnTester.click();//does not open details

		//I tried a few other things, but those were the most promising in my book
        assertThat(grid.isDetailsVisible(gridTest.getRow(0))).isTrue();//is always false, no matter what I try
    }

Additional Information:

My Testclass extends SpringBrowserlessTest, and I have @DataJpaTest with some properties present. I am on Vaadin 25.1, with spring boot starter parent on 4.0.4.

I also used

@Import(MyItemDetailsComponent.class, OtherNestedClass.class})

on test class level to import MyItemDetailsComponent and additional, nested dependencies (e.g. a Service that is inside of the MyItemDetailsComponent). When I first only added the MyItemDetailsComponent, I got some Errors because of some missing required classes, e.g.

DataJpaRepositoriesAutoConfiguration matched:
- @ConditionalOnClass found required class ‘org.springframework.data.jpa.repository.JpaRepository’ (OnClassCondition)
and / or
Parameter 1 of constructor in packages.leading.to.this.class.MyItemDetailsComponent required a bean of type 'another.packages.leading.to.this.clas.util.OtherNestedClass that could not be found.

this happend because a underlying service / class thats supposed to be injected / added to the constructor was not found. Those errors where fixed by adding the services as import. The underlying service that is called when a detail is opened is never called. The Constructor of MyItemDetailsComponent is called, and all the correct variables are set, but the myItemDetailsComponent::setItem is never called

GridTester seems not to have method to get details row and now logic for mocking what you would like to do. I would recommend to open ticket about this missing feature:

My hunch is that is should be doable, as it has been implemented in Vaadin 8 version

I am just linking this as reference of what it could potentially look like when done.

1 Like

This a test slice to test only the repositories. If you want to test the application you must use @SpringBootTest

Could that be the problem? If so, I need to reconfigure how my test works. I’m new to Vaadin and Spring, so I’m not sure how quickly I can do that. Could this be the actual reason it’s not working?

I opened a GitHub issue: Grid ItemDetailsRenderer not triggered (itemConsumer of ComponentRenderer not called) · Issue #29 · vaadin/browserless-test · GitHub

In my tests, a click listener works and is invoked — but it doesn’t work when I use
grid.setDetailsVisibleOnClick(true);

So I think general clicking works in this context, but not the grid-details-specific click behavior.