Skip to content

Not able to test customValueSetListener of ComboBox using UI unit Test #1905

@mukherjeesudebi

Description

@mukherjeesudebi

There is no api to trigger the customValueSetListener when setAllowCustomValue is true.

Code to test

@Route("combobox")
public class ComboBoxView extends VerticalLayout {
	private List<String> items = new ArrayList<>(Arrays.asList("Chrome", "Edge", "Firefox", "Safari"));

	public ComboBoxView () {
		TextField textField = new TextField();
		ComboBox<String> comboBox = new ComboBox<>("Browser");
		comboBox.setAllowCustomValue(true);
		comboBox.addCustomValueSetListener(e -> {
			String customValue = e.getDetail();
			items.add(customValue);
			comboBox.setItems(items);
			comboBox.setValue(customValue);
			textField.setValue(comboBox.getValue());
		});
		add(textField, comboBox);
		comboBox.setItems(items);
		comboBox.setHelperText("Select or type a browser");
	}
}

Test code

@Test
public void allowCustomTest() {
	navigate(ComboBoxView .class);
	TextField textField = $(TextField.class).first();
	ComboBox<String> comboBox = $(ComboBox.class).first();
	comboBox.setValue("Other");
	assertEquals("Other", textField.getValue());
}

Error : The test case fails as the listenerer was not called and TextField value is empty
Expected Outcome: The customValueSetListener should be invoked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    UITestJUnit testing the UI

    Projects

    Status

    Maybe

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions