Skip to content

Commit

Permalink
Add coverage for component head element collection
Browse files Browse the repository at this point in the history
  • Loading branch information
rthrfrd committed Dec 6, 2023
1 parent 3ed42fa commit d8fdedb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions include/webxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -982,14 +982,14 @@ namespace Webxx { namespace internal {
if (!node.data.attributes.empty()) {
render(node.data.attributes, nextComponent);
}
if (node.data.options.selfClosing) {
sendToRender("/");
}
if (nextComponent) {
sendToRender(" ");
sendToRender(componentScopePrefix);
sendToRender(componentName(nextComponent));
}
if (node.data.options.selfClosing) {
sendToRender("/");
}
sendToRender(">");
}

Expand Down
31 changes: 30 additions & 1 deletion test/unit/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ TEST_SUITE("Component") {
h1{{_class{"title"}}, "Hello"},
p{{_class{"summary"}}, "World."},
},

{
link{{_rel{"test"}}},
},
} {}
};

Expand Down Expand Up @@ -75,6 +77,33 @@ TEST_SUITE("Component") {

CHECK(renderCss(myPage) == fmt::format(".title[data-c{0}]{{color:green;}}.summary[data-c{0}]{{color:blue;}}", myComId));
}

SUBCASE("Component head elements are collected and rendered") {
html myPage {
head {
headTarget{},
},
body {
MyCom{},
MyCom{},
},
};

CHECK(render(myPage) == fmt::format(
"<html>"
"<head>"
// Collected elements only appears once:
"<link rel=\"test\" data-c{0}/>"
"</head>"
"<body>"
// HTML appears twice:
"<div data-c{0}><h1 class=\"title\" data-c{0}>Hello</h1><p class=\"summary\" data-c{0}>World.</p></div>"
"<div data-c{0}><h1 class=\"title\" data-c{0}>Hello</h1><p class=\"summary\" data-c{0}>World.</p></div>"
"</body>"
"</html>",
myComId
));
}
}

TEST_CASE("Components can be nested") {
Expand Down

0 comments on commit d8fdedb

Please sign in to comment.