Skip to content

It is possible to programmatically emulate click with disabled button #5414

Closed

Description

@TatuLund

Description

Consider use case I am writing unit tests and using Button#click, I would assume it to fail when Button is disabled.

Expected outcome

Button click event should not be emitted. It will help to detect the cause if Button throws an exception.

Minimal reproducible example

    @Test
    public void testFireClickDisabled() {
        button = new Button();
        button.setEnabled(false);
        AtomicBoolean clicked = new AtomicBoolean(false);
        AtomicBoolean thrown = new AtomicBoolean(false);
        button.addClickListener(e -> {
            clicked.set(true);
        });

        Assert.assertFalse(clicked.get());
        try {
            button.click();
        } catch (IllegalStateException e) {
            thrown.set(true);
        }
        Assert.assertFalse(clicked.get());
        Assert.assertTrue(thrown.get());
    }

Steps to reproduce

Above unit test should pass.

Environment

Vaadin version(s): Vaadin 24.1.7

Browsers

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions