The following test illustrates the problem and thus fails at this moment. Any suggestions on how to have a generic selectValue template, while the assignValueButton template is context specific? Would save me large pieces of code duplication…

application test

entity Ent{
  name : String (searchable)
}

entity Container{
  myEnts : Set<Ent>
  myEnt : Ent
}

var globalEnt := Ent{ name := "bla" }
var cont := Container{ }


page root(){
  addEntToCollection( cont.myEnts)
  // selectEnt( cont.myEnt)
}



define assignValueButton( e : Ent ){
  "error, this template should be overridden"
}

define addEntToCollection (col : Ref<Set<Ent>>){
    selectValue()

    define assignValueButton(e : Ent){
       submit action{ col.add(e); }{ "add to collection"}
    }
}

define selectEnt (ent : Ref<Ent>){
    selectValue()

    define assignValueButton(e : Ent){
       submit action{ ent := e; }{ "select"}
    }
}

define selectValue(){  
  placeholder ph { }

  submit action {
    var options := [globalEnt];
    replace("ph", showOptions( options ));
  }[id="thebutton"]{ "show options" }
}

define ignore-access-control ajax showOptions( options : List<Ent>){
  for( e in options ){
    assignValueButton( e )
  }
}

test{
    var d : WebDriver := getFirefoxDriver();
    
    //root first submit button
    d.get(navigate(root()));
    
    var elist : List<WebElement> := d.findElements(SelectBy.id("thebutton"));
    assert(elist.length==1, "expected show options button");
    elist[0].click();
    assert(!d.getPageSource().contains("error"), "Action should replace placeholder with an overridden template, not the globally defined one");
    
}
Submitted by Elmer van Chastelet on 30 January 2014 at 10:00

Log in to post comments