Skip to content

Commit ac5f607

Browse files
authored
Merge pull request #161 from sombriks/main
more explorative tests for webc:for
2 parents 4070f65 + 88c8ac8 commit ac5f607

File tree

8 files changed

+73
-1
lines changed

8 files changed

+73
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
package-lock.json
3-
playground
3+
playground
4+
.idea

test/looping-test.js

+17
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,20 @@ test("script webc:setup feeds data for looping", async t => {
110110
<b>2</b>
111111
<b>3</b>`);
112112
});
113+
114+
test("nesting webc:for over component hierarchy", async t => {
115+
let component = new WebC();
116+
let {contacts} = await import("./stubs/looping/complex/data.js");
117+
118+
component.defineComponents("./test/stubs/looping/components/*.webc");
119+
component.setInputPath("./test/stubs/looping/complex/entry-point.webc");
120+
121+
let { html } = await component.compile({data:{contacts}});
122+
123+
t.true(html.indexOf(`<button onclick="alert('Hello Monica')">Say hello</button>`) > -1)
124+
t.true(html.indexOf(`<li>Ross - 1</li>`) > -1)
125+
t.true(html.indexOf(`<div style="border-color:violet">`) > -1)
126+
t.true(html.indexOf(`<div>Chandler</div>`) > -1)
127+
t.true(html.indexOf(`border: 1px solid green;`) > -1)
128+
129+
})

test/stubs/looping/complex/data.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const contacts = [
2+
{
3+
"name":"Joey",
4+
"color":"blue",
5+
"numbers":[1,2,3]
6+
},
7+
{
8+
"name":"Phoebe",
9+
"color":"pink",
10+
"numbers":[1,2,3]
11+
},
12+
{
13+
"name":"Chandler",
14+
"color":"orange",
15+
"numbers":[1,2,3]
16+
},
17+
{
18+
"name":"Rachel",
19+
"color":"violet",
20+
"numbers":[1,2,3]
21+
},
22+
{
23+
"name":"Monica",
24+
"color":"green",
25+
"numbers":[1,2,3]
26+
},
27+
{
28+
"name":"Ross",
29+
"color":"red",
30+
"numbers":[1,2,3]
31+
}
32+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!--- correct notation to pass down the js object and call it 'info' --->
2+
<card-thing webc:for="c of contacts" :@info="c">
3+
<card-header :@info="c"></card-header>
4+
<card-content :@info="c"></card-content>
5+
<card-actions :@info="c"></card-actions>
6+
</card-thing>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button :onclick="`alert('Hello ${info.name}')`">Say hello</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!--- loop variable should be accessible here? --->
2+
<div @text="c.name"></div>
3+
<ul>
4+
<li webc:for="num of info.numbers" @text="`${info.name} - ${num}`"></li>
5+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div @text="info.name"></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--- card --->
2+
<div :style="`border-color:${info.color}`">
3+
<slot></slot>
4+
</div>
5+
<style>
6+
div {
7+
border: 1px solid green;
8+
}
9+
</style>

0 commit comments

Comments
 (0)