Search in sources :

Example 1 with MetaKeys

use of com.vaadin.testbench.unit.MetaKeys in project testbench by vaadin.

the class ButtonWrapTest method clickWithMeta_metaKeysMarkedAsUsed.

@Test
public void clickWithMeta_metaKeysMarkedAsUsed() {
    Button button = new Button();
    AtomicReference<ClickEvent> event = new AtomicReference<>(null);
    button.addClickListener(clickEvent -> event.set(clickEvent));
    getCurrentView().getElement().appendChild(button.getElement());
    final ButtonWrap button_ = wrap(ButtonWrap.class, button);
    button_.click(new MetaKeys(true, true, true, true));
    Assertions.assertNotNull(event.get(), "event should have fired and recorded");
    Assertions.assertTrue(event.get().isCtrlKey(), "Ctrl should have been used");
    Assertions.assertTrue(event.get().isShiftKey(), "Shift should have been used");
    Assertions.assertTrue(event.get().isAltKey(), "Alt should have been used");
    Assertions.assertTrue(event.get().isMetaKey(), "Meta should have been used");
    button_.click(new MetaKeys(true, true, false, false));
    Assertions.assertTrue(event.get().isCtrlKey(), "Ctrl should have been used");
    Assertions.assertTrue(event.get().isShiftKey(), "Shift should have been used");
    Assertions.assertFalse(event.get().isAltKey(), "Alt should not have been used");
    Assertions.assertFalse(event.get().isMetaKey(), "Meta should not have been used");
}
Also used : MetaKeys(com.vaadin.testbench.unit.MetaKeys) ClickEvent(com.vaadin.flow.component.ClickEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) UIUnitTest(com.vaadin.testbench.unit.UIUnitTest)

Aggregations

ClickEvent (com.vaadin.flow.component.ClickEvent)1 MetaKeys (com.vaadin.testbench.unit.MetaKeys)1 UIUnitTest (com.vaadin.testbench.unit.UIUnitTest)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.jupiter.api.Test)1