Search in sources :

Example 21 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class AbstractSelectionModelTest method testResolveChanges.

/**
 * Test that resolving changes doesn't prevent an event from firing.
 */
public void testResolveChanges() {
    AbstractSelectionModel<String> model = createSelectionModel(null);
    final MockSelectionChangeHandler handler = new MockSelectionChangeHandler();
    model.addSelectionChangeHandler(handler);
    model.setSelected("test1", true);
    handler.assertEventFired(false);
    model.isSelected("test1");
    new Timer() {

        @Override
        public void run() {
            handler.assertEventFired(true);
            finishTest();
        }
    }.schedule(1000);
}
Also used : Timer(org.gwtproject.timer.client.Timer)

Example 22 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class DefaultSelectionModelTest method testNoDuplicateChangeEvent.

public void testNoDuplicateChangeEvent() {
    delayTestFinish(2000);
    final DefaultSelectionModel<String> model = createSelectionModel(null);
    final MockSelectionChangeHandler handler = new AssertOneSelectionChangeEventOnlyHandler();
    model.addSelectionChangeHandler(handler);
    model.setSelected("selected999", false);
    // selection events fire at the end of current event loop (finally command)
    handler.assertEventFired(false);
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            handler.assertEventFired(true);
            // No further selection events should be fired
            model.addSelectionChangeHandler(new FailingSelectionChangeEventHandler());
            model.setSelected("selected999", false);
            model.setSelected("selected999", false);
        }
    });
    new Timer() {

        @Override
        public void run() {
            finishTest();
        }
    }.schedule(1000);
}
Also used : Timer(org.gwtproject.timer.client.Timer) Scheduler(org.gwtproject.core.client.Scheduler)

Example 23 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class MultiSelectionModelTest method testNoDuplicateChangeEventWithKeyProvider.

/**
 * Tests that reselecting the same key from a different item does not fire a
 * change event.
 */
public void testNoDuplicateChangeEventWithKeyProvider() {
    delayTestFinish(2000);
    ProvidesKey<String> keyProvider = item -> item.toUpperCase(Locale.ROOT);
    MultiSelectionModel<String> model = createSelectionModel(keyProvider);
    model.setSelected("test1", true);
    assertTrue(model.isSelected("test1"));
    // Selecting a different item with the same key should not be seen as a
    // selection change
    String replacement = "TEST1";
    model.addSelectionChangeHandler(new FailingSelectionChangeEventHandler());
    model.setSelected(replacement, true);
    assertTrue(model.isSelected(replacement));
    assertEquals(1, model.getSelectedSet().size());
    assertSame(replacement, model.getSelectedSet().iterator().next());
    new Timer() {

        @Override
        public void run() {
            finishTest();
        }
    }.schedule(1000);
}
Also used : J2clTestInput(com.google.j2cl.junit.apt.J2clTestInput) HashSet(java.util.HashSet) Scheduler(org.gwtproject.core.client.Scheduler) Timer(org.gwtproject.timer.client.Timer) Locale(java.util.Locale) Set(java.util.Set) Timer(org.gwtproject.timer.client.Timer)

Example 24 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class SingleSelectionModelTest method testNoDuplicateChangeEvent.

public void testNoDuplicateChangeEvent() {
    delayTestFinish(2000);
    SingleSelectionModel<String> model = createSelectionModel(null);
    MockSelectionChangeHandler handler = new AssertOneSelectionChangeEventOnlyHandler();
    model.addSelectionChangeHandler(handler);
    model.setSelected("test", true);
    // selection events fire at the end of current event loop (finally command)
    handler.assertEventFired(false);
    Scheduler.get().scheduleDeferred(() -> {
        handler.assertEventFired(true);
        // No further selection events should be fired
        model.addSelectionChangeHandler(new FailingSelectionChangeEventHandler());
        model.setSelected("test", true);
        model.setSelected("test", true);
    });
    new Timer() {

        @Override
        public void run() {
            finishTest();
        }
    }.schedule(1000);
}
Also used : Timer(org.gwtproject.timer.client.Timer)

Example 25 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class SingleSelectionModelTest method testNoDuplicateChangeEvent2.

public void testNoDuplicateChangeEvent2() {
    delayTestFinish(2000);
    SingleSelectionModel<String> model = createSelectionModel(null);
    // no event at all should be fired, as selection events fire at the end of current event loop
    // and at that point no state has been effectively changed.
    model.addSelectionChangeHandler(new FailingSelectionChangeEventHandler());
    model.setSelected("test", true);
    model.setSelected("test", false);
    model.setSelected("test", false);
    model.setSelected("test", false);
    new Timer() {

        @Override
        public void run() {
            finishTest();
        }
    }.schedule(1000);
}
Also used : Timer(org.gwtproject.timer.client.Timer)

Aggregations

Timer (org.gwtproject.timer.client.Timer)65 Promise (elemental2.promise.Promise)16 Test (org.junit.Test)15 ScheduledCommand (org.gwtproject.core.client.Scheduler.ScheduledCommand)7 LoadEvent (org.gwtproject.event.dom.client.LoadEvent)7 Button (org.dominokit.domino.ui.button.Button)3 Card (org.dominokit.domino.ui.cards.Card)3 NativeEvent (org.gwtproject.dom.client.NativeEvent)3 HTMLDivElement (elemental2.dom.HTMLDivElement)2 ArrayList (java.util.ArrayList)2 SampleMethod (org.dominokit.domino.SampleMethod)2 UiView (org.dominokit.domino.api.client.annotations.UiView)2 BaseDemoView (org.dominokit.domino.componentcase.client.ui.views.BaseDemoView)2 CodeCard (org.dominokit.domino.componentcase.client.ui.views.CodeCard)2 Column (org.dominokit.domino.ui.grid.Column)2 Row (org.dominokit.domino.ui.grid.Row)2 BlockHeader (org.dominokit.domino.ui.header.BlockHeader)2 Loader (org.dominokit.domino.ui.loaders.Loader)2 Color (org.dominokit.domino.ui.style.Color)2 AnimationHandle (org.gwtproject.animation.client.AnimationScheduler.AnimationHandle)2