Skip to content

Commit bf22aaf

Browse files
committed
Added some SVG tests.
1 parent f75967e commit bf22aaf

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

nui/test/nui/test_render.hpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <nui/frontend/elements.hpp>
1010
#include <nui/frontend/attributes.hpp>
11+
#include <nui/frontend/svg_elements.hpp>
12+
#include <nui/frontend/svg_attributes.hpp>
1113
#include <nui/frontend/dom/reference.hpp>
1214
#include <nui/frontend/utility/stabilize.hpp>
1315

@@ -677,4 +679,58 @@ namespace Nui::Tests
677679

678680
EXPECT_EQ(Nui::val::global("document")["body"]["childNodes"][1]["nodeValue"].as<std::string>(), "Changed");
679681
}
682+
683+
TEST_F(TestRender, CanRenderSvgElement)
684+
{
685+
using namespace Nui::Elements;
686+
namespace se = Nui::Elements::Svg;
687+
namespace sa = Nui::Attributes::Svg;
688+
689+
render(body{}(se::svg{}()));
690+
691+
ASSERT_EQ(Nui::val::global("document")["body"]["children"]["length"].as<long long>(), 1);
692+
EXPECT_EQ(Nui::val::global("document")["body"]["children"][0]["tagName"].as<std::string>(), "svg");
693+
}
694+
695+
TEST_F(TestRender, RenderedSvgNamespaceIsSetCorrectly)
696+
{
697+
using namespace Nui::Elements;
698+
namespace se = Nui::Elements::Svg;
699+
namespace sa = Nui::Attributes::Svg;
700+
701+
render(body{}(se::svg{}()));
702+
703+
ASSERT_EQ(Nui::val::global("document")["body"]["children"]["length"].as<long long>(), 1);
704+
EXPECT_EQ(
705+
Nui::val::global("document")["body"]["children"][0].as<Nui::val>()["namespaceURI"].as<std::string>(),
706+
"http://www.w3.org/2000/svg");
707+
}
708+
709+
TEST_F(TestRender, SvgElementChildIsAppended)
710+
{
711+
using namespace Nui::Elements;
712+
namespace se = Nui::Elements::Svg;
713+
namespace sa = Nui::Attributes::Svg;
714+
715+
render(body{}(se::svg{}(se::circle{}())));
716+
717+
ASSERT_EQ(Nui::val::global("document")["body"]["children"]["length"].as<long long>(), 1);
718+
ASSERT_EQ(Nui::val::global("document")["body"]["children"][0]["children"]["length"].as<long long>(), 1);
719+
EXPECT_EQ(
720+
Nui::val::global("document")["body"]["children"][0]["children"][0]["tagName"].as<std::string>(), "circle");
721+
}
722+
723+
TEST_F(TestRender, SvgElementAttributeIsSet)
724+
{
725+
using namespace Nui::Elements;
726+
namespace se = Nui::Elements::Svg;
727+
namespace sa = Nui::Attributes::Svg;
728+
729+
render(body{}(se::svg{}(se::circle{sa::cx = 10}())));
730+
731+
ASSERT_EQ(Nui::val::global("document")["body"]["children"]["length"].as<long long>(), 1);
732+
ASSERT_EQ(Nui::val::global("document")["body"]["children"][0]["children"]["length"].as<long long>(), 1);
733+
EXPECT_EQ(
734+
Nui::val::global("document")["body"]["children"][0]["children"][0]["attributes"]["cx"].as<long long>(), 10);
735+
}
680736
}

0 commit comments

Comments
 (0)