@Override public IsButton newButton() { return new StubButton(); }
@Test public void commandDisablesButton() { final DummyActiveCommand command = new DummyActiveCommand(); final StubButton button = new StubButton(); binder.bind(command).to(button); button.click(); assertThat(button.isEnabled(), is(false)); command.done(); assertThat(button.isEnabled(), is(true)); }
@Test public void onClick() { final StubButton button = new StubButton(); binder.onClick(button).set(s).to("clicked"); button.click(); assertThat(s.get(), is("clicked")); }
@Test public void commandPreventsEventDefault() { final DummyUiCommand command = new DummyUiCommand(); final StubButton button = new StubButton(); binder.bind(command).to(button); final StubClickEvent click = new StubClickEvent(); button.fireEvent(click); assertThat(click.prevented, is(true)); }
@Test public void cancelButtonDoesNotTouchProperties() { final DummyUiCommand command = new DummyUiCommand(); final StringProperty name = stringProperty("name").max(10); p.add(new TextBoxFormLine(name)); ButtonFormAction action = new ButtonFormAction(command, "cancel", false); p.add(action); // given the name is not touched assertThat(name.isTouched(), is(false)); // when cancel is clicked ((StubButton) action.getButton()).click(); // then the property is still not touched assertThat(name.isTouched(), is(false)); // and the command executed assertThat(command.getExecutions(), is(1)); } }
@Test public void commandShowsSpinner() { final DummyActiveCommand command = new DummyActiveCommand(); final StubButton button = new StubButton(); final StubImage spinner = new StubImage(); binder.bind(command).to(button).spin(spinner); assertThat(spinner, is(invisible())); button.click(); assertThat(spinner, is(visible())); command.done(); assertThat(spinner, is(invisible())); }
@Test public void buttonTouchesProperties() { final DummyUiCommand command = new DummyUiCommand(); final StringProperty name = stringProperty("name").req(); p.add(new TextBoxFormLine(name)); ButtonFormAction action = new ButtonFormAction(command, "foo"); p.add(action); // given the name is not touched assertThat(name.isTouched(), is(false)); // when submit is clicked ((StubButton) action.getButton()).click(); // then the property is now touched assertThat(name.isTouched(), is(true)); // and the command did not execute assertThat(command.getExecutions(), is(0)); }
private SomeComponentView() { b = new StubButton(); setWidget(b); ensureDebugId("SomeComponent"); } }