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