@Test public void checkRadioButtonClickTwice() { tested = false; RadioButton r1 = new RadioButton("myRadioGroup", "r1"); RadioButton r2 = new RadioButton("myRadioGroup", "r2"); r1.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { tested = !tested; } }); r2.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { tested = !tested; } }); Assert.assertEquals(false, tested); // simule the event Browser.click(r1); Browser.click(r1); Assert.assertEquals(false, tested); Assert.assertEquals(true, r1.getValue()); }
@SuppressWarnings("unchecked") @Test public void checkRPCCallSuccess() { // Setup Button button = GwtReflectionUtils.getPrivateFieldValue(composite, "button"); Label label = GwtReflectionUtils.getPrivateFieldValue(composite, "label"); service.createBean(EasyMock.eq("OCTO"), EasyMock.isA(AsyncCallback.class)); FooBean expected = new FooBean(); expected.setName("mocked"); expectServiceAndCallbackOnSuccess(expected); // replay all @Mock objects replay(); Assert.assertEquals("", label.getText()); // Test Browser.click(button); // Assert // verify all @Mock objects verify(); Assert.assertEquals("Bean \"mocked\" has been created", label.getText()); }
@Test public void runAsync() { // Arrange Button b = new Button(); b.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { GWT.runAsync( new RunAsyncCallback() { public void onFailure(Throwable reason) { fail("GWT.runAsync() has called \"onFailure\" callback"); } public void onSuccess() { success = true; } }); } }); // Act Browser.click(b); // Assert assertTrue(success); }
@Test public void click() { // Arrange CheckBox cb = new CheckBox(); // Pre-Assert assertFalse(cb.getValue()); // Act 1 Browser.click(cb); // Assert 1 assertTrue(cb.getValue()); assertEquals("", errorStringBuilder.toString()); // Act 2 Browser.click(cb); // Assert 2 assertFalse(cb.getValue()); assertEquals("", errorStringBuilder.toString()); }
@Test public void click_disabled() { // Arrange CheckBox cb = new CheckBox(); cb.setEnabled(false); // Act Browser.click(cb); // Assert assertFalse(cb.getValue()); assertTrue( errorStringBuilder .toString() .startsWith( "Cannot dispatch 'mouseover' event : the targeted element has to be enabled : <span class=\"gwt-CheckBox gwt-CheckBox-disabled\"><input type=\"checkbox\"")); }
@Test public void checkRadioButtonClick() { tested = false; RadioButton r = new RadioButton("myRadioGroup", "foo"); r.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { tested = !tested; } }); Assert.assertEquals(false, tested); // simule the event Browser.click(r); Assert.assertEquals(true, tested); Assert.assertEquals(true, r.getValue()); }
@SuppressWarnings("unchecked") @Test public void checkRPCCallFailure() { // Setup Button button = GwtReflectionUtils.getPrivateFieldValue(composite, "button"); Label label = GwtReflectionUtils.getPrivateFieldValue(composite, "label"); service.createBean(EasyMock.eq("OCTO"), EasyMock.isA(AsyncCallback.class)); expectServiceAndCallbackOnFailure(new Exception("Mocked exception")); // replay all @Mock objects replay(); Assert.assertEquals("", label.getText()); // Test Browser.click(button); // Assert // verify all @Mock objects verify(); Assert.assertEquals("Failure : Mocked exception", label.getText()); }
/** Simulates a click event on the item of a SuggestBox with the given index. */ public static void click(SuggestBox parent, int clickedItemIndex) { click(parent, WidgetUtils.getMenuItems(parent).get(clickedItemIndex)); }
/** * @param panel * @param index * @deprecated use {@link Browser#click(ComplexPanel, int)} instead */ public static void click(ComplexPanel panel, int index) { Browser.click(panel, index); }
/** * @param grid * @param row * @param column * @deprecated use {@link Browser#click(Grid, int, int)} instead */ public static void click(Grid grid, int row, int column) { Browser.click(grid, row, column); }
/** * @param parent * @param clickedItemIndex * @deprecated use {@link Browser#click(MenuBar, int)} instead */ public static void click(MenuBar parent, int clickedItemIndex) { Browser.click(parent, clickedItemIndex); }
/** * @param parent * @param clickedItem * @deprecated use {@link Browser#click(MenuBar, MenuItem)} instead */ public static void click(MenuBar parent, MenuItem clickedItem) { Browser.click(parent, clickedItem); }
/** * @param target * @deprecated use {@link Browser#click(Widget)} instead */ public static void click(Widget target) { Browser.click(target); }