Browse Source

Add test for `Element::InsertBefore`

Michael Ragazzon 1 year ago
parent
commit
9908978c37
1 changed files with 22 additions and 7 deletions
  1. 22 7
      Tests/Source/UnitTests/Element.cpp

+ 22 - 7
Tests/Source/UnitTests/Element.cpp

@@ -166,7 +166,12 @@ TEST_CASE("Element")
 	context->Update();
 	context->Render();
 
-	TestsShell::RenderLoop();
+	Element* div = document->GetFirstChild();
+	Element* span = div->GetChild(1);
+	REQUIRE(div);
+	REQUIRE(div->GetTagName() == "div");
+	REQUIRE(span);
+	REQUIRE(span->GetTagName() == "span");
 
 	SUBCASE("Attribute")
 	{
@@ -295,12 +300,6 @@ TEST_CASE("Element")
 	SUBCASE("GetInnerRML")
 	{
 		String inner_rml;
-		Element* div = document->GetFirstChild();
-		Element* span = div->GetChild(1);
-		REQUIRE(div);
-		REQUIRE(div->GetTagName() == "div");
-		REQUIRE(span);
-		REQUIRE(span->GetTagName() == "span");
 
 		inner_rml = document->GetInnerRML();
 		CHECK(inner_rml == R"(<div style="background-color: #ff0000;">This is a <span>sample</span>.</div>)");
@@ -322,6 +321,22 @@ TEST_CASE("Element")
 		CHECK(inner_rml == R"(<div style="cursor: x&lt;y;">This is a <span style="font-weight: bold;">sample</span>.</div>)");
 	}
 
+	SUBCASE("InsertBefore")
+	{
+		String inner_rml;
+
+		inner_rml = document->GetInnerRML();
+		CHECK(inner_rml == R"(<div style="background-color: #ff0000;">This is a <span>sample</span>.</div>)");
+
+		div->InsertBefore(document->CreateElement("img"), span);
+		inner_rml = document->GetInnerRML();
+		CHECK(inner_rml == R"(<div style="background-color: #ff0000;">This is a <img /><span>sample</span>.</div>)");
+
+		div->InsertBefore(document->CreateElement("button"), nullptr)->SetInnerRML("Click me");
+		inner_rml = document->GetInnerRML();
+		CHECK(inner_rml == R"(<div style="background-color: #ff0000;">This is a <img /><span>sample</span>.<button>Click me</button></div>)");
+	}
+
 	document->Close();
 	TestsShell::ShutdownShell();
 }