Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more explorative tests for webc:for #161

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
package-lock.json
playground
playground
.idea
17 changes: 17 additions & 0 deletions test/looping-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,20 @@ test("script webc:setup feeds data for looping", async t => {
<b>2</b>
<b>3</b>`);
});

test("nesting webc:for over component hierarchy", async t => {
let component = new WebC();
let {contacts} = await import("./stubs/looping/complex/data.js");

component.defineComponents("./test/stubs/looping/components/*.webc");
component.setInputPath("./test/stubs/looping/complex/entry-point.webc");

let { html } = await component.compile({data:{contacts}});

t.true(html.indexOf(`<button onclick="alert('Hello Monica')">Say hello</button>`) > -1)
t.true(html.indexOf(`<li>Ross - 1</li>`) > -1)
t.true(html.indexOf(`<div style="border-color:violet">`) > -1)
t.true(html.indexOf(`<div>Chandler</div>`) > -1)
t.true(html.indexOf(`border: 1px solid green;`) > -1)

})
32 changes: 32 additions & 0 deletions test/stubs/looping/complex/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const contacts = [
{
"name":"Joey",
"color":"blue",
"numbers":[1,2,3]
},
{
"name":"Phoebe",
"color":"pink",
"numbers":[1,2,3]
},
{
"name":"Chandler",
"color":"orange",
"numbers":[1,2,3]
},
{
"name":"Rachel",
"color":"violet",
"numbers":[1,2,3]
},
{
"name":"Monica",
"color":"green",
"numbers":[1,2,3]
},
{
"name":"Ross",
"color":"red",
"numbers":[1,2,3]
}
]
6 changes: 6 additions & 0 deletions test/stubs/looping/complex/entry-point.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--- correct notation to pass down the js object and call it 'info' --->
<card-thing webc:for="c of contacts" :@info="c">
<card-header :@info="c"></card-header>
<card-content :@info="c"></card-content>
<card-actions :@info="c"></card-actions>
</card-thing>
1 change: 1 addition & 0 deletions test/stubs/looping/components/card-actions.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button :onclick="`alert('Hello ${info.name}')`">Say hello</button>
5 changes: 5 additions & 0 deletions test/stubs/looping/components/card-content.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--- loop variable should be accessible here? --->
<div @text="c.name"></div>
<ul>
<li webc:for="num of info.numbers" @text="`${info.name} - ${num}`"></li>
</ul>
1 change: 1 addition & 0 deletions test/stubs/looping/components/card-header.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div @text="info.name"></div>
9 changes: 9 additions & 0 deletions test/stubs/looping/components/card-thing.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--- card --->
<div :style="`border-color:${info.color}`">
<slot></slot>
</div>
<style>
div {
border: 1px solid green;
}
</style>