Skip to content

Commit

Permalink
✅ ensure correct type checking for xml rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefEZ committed Dec 22, 2023
1 parent 847e72d commit 7ef6872
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tests/unit/test_xml_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ def test_mentionable_select_rendering(self, view: mock.mock.MagicMock):

def test_text_input_rendering(self, view: mock.mock.MagicMock):
message = render_message("tests/routes/select_embeds.xml", "Launch")
self.assertEqual(len(message.view.children), 4)
child = message.view.children[3]
assert isinstance(message, Message)
view = message.view
assert view is not None
self.assertEqual(len(view.children), 4)
child = view.children[3]
self.assertIsInstance(child, discord.ui.TextInput)
self.assertEqual(child.placeholder, "Test Placeholder")

Expand Down Expand Up @@ -159,6 +162,8 @@ def test_expansive_message_with_timeout(self, _: mock.mock.MagicMock):
def test_jinja_view_rendering(self, view: mock.mock.MagicMock):
renderer: Renderer[JinjaEmbeds] = Renderer(Jinja2(), "tests/routes/jinja-test.xml")
message = renderer.render("test1")
assert isinstance(message, Message)
assert message.view
self.assertEqual(len(message.view.children), 1)

def test_combined_rendering(self, view: mock.mock.MagicMock):
Expand Down Expand Up @@ -241,14 +246,20 @@ def test_empty_content_message(self, _: mock.mock.MagicMock):

renderer: Renderer[CompleteEmbeds] = Renderer(Formatter(), template)
message = renderer.render("empty_content_test")
self.assertEqual(message.content.strip(), "")
assert isinstance(message, Message), "Expected Message instance"
content = message.content
assert content is not None
self.assertEqual(content.strip(), "")

def test_multi_line_content_message(self, _: mock.mock.MagicMock):
template = "tests/routes/complete_messages.xml"

renderer: Renderer[CompleteEmbeds] = Renderer(Formatter(), template)
message = renderer.render("multi_line_content_test")
message_lines = message.content.strip().split("\n")
assert isinstance(message, Message), "Expected Message instance"
content = message.content
assert content is not None
message_lines = content.strip().split("\n")
self.assertEqual(len(message_lines), 3)
self.assertEqual(message_lines[0], "- This is a test message")
self.assertEqual(message_lines[1], "- This is a test message")
Expand Down

0 comments on commit 7ef6872

Please sign in to comment.