javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/KnockoutTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 22 Jan 2013 21:57:27 +0100
branchmodel
changeset 530 3ce069ec3312
child 763 ecd7294f1e17
permissions -rw-r--r--
Test to verify Knockout can handle String properties
jaroslav@530
     1
/**
jaroslav@530
     2
 * Back 2 Browser Bytecode Translator
jaroslav@530
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@530
     4
 *
jaroslav@530
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@530
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@530
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@530
     8
 *
jaroslav@530
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@530
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@530
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@530
    12
 * GNU General Public License for more details.
jaroslav@530
    13
 *
jaroslav@530
    14
 * You should have received a copy of the GNU General Public License
jaroslav@530
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@530
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@530
    17
 */
jaroslav@530
    18
package org.apidesign.bck2brwsr.htmlpage;
jaroslav@530
    19
jaroslav@530
    20
import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
jaroslav@530
    21
import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
jaroslav@530
    22
import org.apidesign.bck2brwsr.htmlpage.api.Page;
jaroslav@530
    23
import org.apidesign.bck2brwsr.htmlpage.api.Property;
jaroslav@530
    24
import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
jaroslav@530
    25
import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
jaroslav@530
    26
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@530
    27
import org.testng.annotations.Factory;
jaroslav@530
    28
jaroslav@530
    29
/**
jaroslav@530
    30
 *
jaroslav@530
    31
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@530
    32
 */
jaroslav@530
    33
@Page(xhtml="Knockout.xhtml", className="KnockoutModel", properties={
jaroslav@530
    34
    @Property(name="name", type=String.class)
jaroslav@530
    35
}) 
jaroslav@530
    36
public class KnockoutTest {
jaroslav@530
    37
    
jaroslav@530
    38
    @HtmlFragment(
jaroslav@530
    39
        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
jaroslav@530
    40
        "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
jaroslav@530
    41
        "<button id=\"hello\">Say Hello!</button>\n"
jaroslav@530
    42
    )
jaroslav@530
    43
    @BrwsrTest public void modifyValueAssertChangeInModel() {
jaroslav@530
    44
        KnockoutModel m = new KnockoutModel();
jaroslav@530
    45
        m.setName("Kukuc");
jaroslav@530
    46
        m.applyBindings();
jaroslav@530
    47
        assert "Kukuc".equals(m.INPUT.getValue()) : "Value is really kukuc: " + m.INPUT.getValue();
jaroslav@530
    48
        m.INPUT.setValue("Jardo");
jaroslav@530
    49
        m.triggerEvent(m.INPUT, OnEvent.CHANGE);
jaroslav@530
    50
        assert "Jardo".equals(m.getName()) : "Name property updated: " + m.getName();
jaroslav@530
    51
    }
jaroslav@530
    52
    
jaroslav@530
    53
    @ComputedProperty
jaroslav@530
    54
    static String helloMessage(String name) {
jaroslav@530
    55
        return "Hello " + name + "!";
jaroslav@530
    56
    }
jaroslav@530
    57
    
jaroslav@530
    58
    @Factory
jaroslav@530
    59
    public static Object[] create() {
jaroslav@530
    60
        return VMTest.create(KnockoutTest.class);
jaroslav@530
    61
    }
jaroslav@530
    62
}