-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I´m trying to test ZK app with ZATS, but it doesn´t work with shadow component and choose - apply templates. I mean: I look for id of component inside a template (after click on button to enable shadow component) but received a null of this component.
Is ZATS enabled to work with shadow components? How can I test the load of the right template after event/click?
thanks in advance
It is not enabled per se, because there is no difference. Shadow elements just provide another way to add/remove components to a page.
So if your components appear due to a change to the template/templateUri property the contained components are queryable from ZATS just as normal. However the shadow elements itself aren't supported by ZATS via QueryAgent. Still - if really needed - you can query them directly from the actual component instance behind a ComponentAgent object, which also has a query() method. e.g.:
componentAgent.as(Div.class).query('::shadow#myApply')
Here a small example demonstrating this (uses zscript for simplicity - the same result can be achieved with normal @Command bindings, so don't copy/paste this pattern):
clicking the button will toggle between template1<->template2
zats-shadow.zul
<zk>
<zs cript>
public class MyVm {
private String template = "template1";
public String getTemplate() { return this.template; }
//can't use annotations in zscript, in a java class you can do that
//@Command
//@NotifyChange("template");
public void toggleTemplate() {
this.template = "template1".equals(this.template) ? "template2" : "template1";
BindUtils.postNotifyChange(null, null, this, "template");
}
}
</zscript>
<div id="root" viewModel="@id('vm') @init('MyVm')">
<button id="toggleTemplate" onClick="vm.toggleTemplate()"/>
<!-- <button id="toggleTemplate" onClick="@command('toggleTemplate')"/>-->
<apply id="myApply" dynamicValue="true" template="@load(vm.template)">
<template name="template1">
<div id="template1Content">
Template 1
</div>
</template>
<template name="template2">
<div id="template2Content">
Template 2
</div>
</template>
</apply>
</div>
</zk>
Here a corresponding ZATS test case asserting the updated components inside the different templates. Also shows how to access the inner state of the shadow element directly - if you really need that for a particular reason.
public class ZatsShadowTest {
@ClassRule
public static AutoEnvironment env = new AutoEnvironment("src/main/webapp");
@Rule
public AutoClient autoClient = env.autoClient();
private DesktopAgent desktopAgent;
@Before
public void setup() {
this.desktopAgent = autoClient.connect("/zats-shadow.zul");
}
@After
public void cleanup() {
this.desktopAgent = null;
}
public ComponentAgent root() { return desktopAgent.query("#root"); }
public ComponentAgent template1Content() { return desktopAgent.query("#template1Content"); }
public ComponentAgent template2Content() { return desktopAgent.query("#template2Content"); }
public ComponentAgent toggleTemplate() { return desktopAgent.query("#toggleTemplate"); }
public Apply myApply() { return (Apply) root().as(Div.class).query("::shadow#myApply"); }
@Test
public void testShadowTemplate() {
assertEquals("template1", myApply().getTemplate());
assertNotNull(template1Content());
assertNull(template2Content());
toggleTemplate().click();
assertEquals("template2", myApply().getTemplate());
assertNull(template1Content());
assertNotNull(template2Content());
}
}
Since this works on my side and you didn't provide any non working example. I can't comment on your particular issue.
In any case Shadow elements are nothing a user can/will interact with, that's why they aren't considered in the ZatsMimic library. It should be enough to just assert the actual contents tempalte1Content/template2Content are added/removed as expected.
Asked: 2019-10-23 15:46:54 +0800
Seen: 10 times
Last updated: Oct 24 '19
[ZK8.6 Preview] New media components coming soon!
Bug in Datebox with lenient=false and value 01.04.1981?
javascript cannot catch id of zul component. Please help.
failed to utilize getTop(), getLeft() on div(component). Please help.
Serving zul files from a directory outside web application