@Override protected void onBind() { super.onBind(); // allow handler registrations binder.bind(); // bind anybody that got added before we were bound if (children != null) { for (final Presenter child : children) { child.bind(); } } }
@Test public void booleanToListInitiallyRemovesWhenTrue() { BooleanProperty b = booleanProperty("b", false); List<String> names = new ArrayList<String>(); names.add("foo"); binder.bind(b).to(names).has("foo"); assertThat(names.size(), is(0)); }
@Test public void stringToKeyUpDoesTrimEntirelyEmptySpaces() { binder.bind(s).toKeyUp(box); box.keyUp('a'); box.keyUp(KeyCodes.KEY_BACKSPACE); assertThat(s.get(), is(nullValue())); }
@Test public void shouldTouchPropertyOnBlur() { binder.bind(s).to(box); box.blur(); assertThat(s.isTouched(), is(true)); }
@Test public void propertyToWidget() { binder.bind(s).to(box); s.set("test"); assertThat(box.getValue(), is("test")); }
@Test public void stringToKeyUpUpdatesModelOnKeyUp() { binder.bind(s).toKeyUp(box); box.press('a'); assertThat(s.get(), is("a")); }
@Test public void errorsThatAlreadyFiredGetAddedToAnErrorList() { s.req().touch(); assertThat(s.isValid(), is(false)); binder.bind(s).errorsTo(errors); assertThat(errors.getList().size(), is(1)); }
@Test public void newPresentersAreAddedToPanel() { binder.bind(names).to(parent, panel, presenterFactory); assertThat(panel.getWidgetCount(), is(0)); names.add("one"); assertLabel(panel.getIsWidget(0), "one"); assertThat(parent.getChildren().size(), is(1)); }
@Test public void propertyToCookieGetsInitialCookieValueUnlessAlreadyTouched() { final StubCookies cookies = new StubCookies(); final StringCookie c = new StringCookie(cookies, "c"); cookies.set("c", "foo"); s.touch(); binder.bind(s).to(c); assertThat(s.get(), is(nullValue())); assertThat(c.getValue(), is(nullValue())); }
@Test public void oldPresentersAreRemovedFromPanel() { binder.bind(names).to(parent, panel, presenterFactory); names.add("one"); names.add("two"); assertThat(panel.getWidgetCount(), is(2)); assertThat(parent.getChildren().size(), is(2)); names.remove("one"); assertThat(panel.getWidgetCount(), is(1)); assertLabel(panel.getIsWidget(0), "two"); assertThat(parent.getChildren().size(), is(1)); }
@Test public void enhanceIgnoresTabKeyUpEvent() { final StubTextBox b = new StubTextBox(); final StringProperty s = stringProperty("s"); binder.bind(s).to(b); binder.enhance(b); b.keyUp(KEY_TAB); assertThat(s.get(), is(nullValue())); }
@Test public void derivedValueToIsElement() { final StringProperty p = stringProperty(new DerivedValue<String>("p") { public String get() { return null; } }); final StubElement e = new StubElement(); // should skip the "set null property logic", otherwise will fail binder.bind(p).to(textOf(e)); }
@Test public void bindEnumCreatesItems() { final SetValue<Color> v = new SetValue<Color>("v", Color.BLUE); final EnumProperty<Color> e = enumProperty(v); final StubListBox box = new StubListBox(); binder.bind(e).to(box, Color.values()); assertThat(box.getItemCount(), is(2)); assertThat(box.getItemText(0), is("Green")); assertThat(box.getItemText(1), is("Blue (not green)")); }
@Test public void booleanToRadioGroupSetsOnUpdateFalse() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", true); binder.bind(b).to(b1, b2); b.set(false); assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), is(true)); }
@Test public void testLambda() { s.set("foo"); binder.bind(() -> s.get() + "bar").to(textOf(anchor)); assertThat(anchor.getText(), is("foobar")); s.set("zaz"); assertThat(anchor.getText(), is("zazbar")); }
@Test public void booleanToRadioGroupSetsOnFalse() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", true); binder.bind(b).to(b1, b2); b2.click(); assertThat(b.get(), is(false)); }
@Test public void testContainsBoundWhenAlreadyTrue() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); p.add("s"); BooleanProperty s = p.contains("s"); b.bind(s).to(c); assertThat(c.getValue(), is(true)); }
@Test public void testContainsBoundWhenModelChanges() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); BooleanProperty s = p.contains("s"); b.bind(s).to(c); p.add("s"); assertThat(c.getValue(), is(true)); }
@Test public void booleanToListPropertyAddsInitiallyWhenTrue() { BooleanProperty b = booleanProperty("b", true); ListProperty<String> names = listProperty("names"); binder.bind(b).to(names).has("foo"); assertThat(names.get(), hasItem("foo")); }