1.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/KnockoutTest.java Tue Mar 26 09:24:26 2013 +0100
1.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/KnockoutTest.java Sun Mar 31 05:34:15 2013 +0200
1.3 @@ -36,7 +36,8 @@
1.4 @Page(xhtml="Knockout.xhtml", className="KnockoutModel", properties={
1.5 @Property(name="name", type=String.class),
1.6 @Property(name="results", type=String.class, array = true),
1.7 - @Property(name="callbackCount", type=int.class)
1.8 + @Property(name="callbackCount", type=int.class),
1.9 + @Property(name="people", type=PersonImpl.class, array = true)
1.10 })
1.11 public class KnockoutTest {
1.12
1.13 @@ -98,11 +99,44 @@
1.14 assert cnt == 2 : "Two children now, but was " + cnt;
1.15 }
1.16
1.17 + @HtmlFragment(
1.18 + "<ul id='ul' data-bind='foreach: people'>\n"
1.19 + + " <li data-bind='text: $data.firstName, click: $root.removePerson'></li>\n"
1.20 + + "</ul>\n"
1.21 + )
1.22 + @BrwsrTest public void displayContentOfArrayOfPeople() {
1.23 + KnockoutModel m = new KnockoutModel();
1.24 + m.getPeople().add(new Person());
1.25 + m.applyBindings();
1.26 +
1.27 + int cnt = countChildren("ul");
1.28 + assert cnt == 1 : "One child, but was " + cnt;
1.29 +
1.30 + m.getPeople().add(new Person());
1.31 +
1.32 + cnt = countChildren("ul");
1.33 + assert cnt == 2 : "Two children now, but was " + cnt;
1.34 +
1.35 + triggerChildClick("ul", 1);
1.36 +
1.37 + assert 1 == m.getCallbackCount() : "One callback " + m.getCallbackCount();
1.38 +
1.39 + cnt = countChildren("ul");
1.40 + assert cnt == 1 : "Again one child, but was " + cnt;
1.41 + }
1.42 +
1.43 @OnFunction
1.44 static void call(KnockoutModel m, String data) {
1.45 m.setName(data);
1.46 m.setCallbackCount(m.getCallbackCount() + 1);
1.47 }
1.48 +
1.49 + @OnFunction
1.50 + static void removePerson(KnockoutModel model, Person data) {
1.51 + model.setCallbackCount(model.getCallbackCount() + 1);
1.52 + model.getPeople().remove(data);
1.53 + }
1.54 +
1.55
1.56 @ComputedProperty
1.57 static String helloMessage(String name) {