"""
Web UI compatible drawing SVG builder tests.
"""
from xml.etree import ElementTree as ET
import pytest
from gns3server.utils.drawings import build_ellipse_svg, build_rectangle_svg, build_text_svg
class TestBuildTextSvg:
def test_single_line(self):
svg, width, height, line_height = build_text_svg("R1", font_size=13)
assert svg == (
''
)
# 2 chars x 13 x 0.8 = 20.8 -> 21; one line of 13 x 1.9 = 24.7 -> 25
assert width == 21
assert height == 25
assert line_height == 25
def test_bold_and_color(self):
svg, _, _, _ = build_text_svg("R1", font_size=13, color="#CC0000", bold=True)
assert 'fill="#CC0000"' in svg
assert 'font-weight="bold"' in svg
def test_escapes_xml_characters(self):
svg, _, _, _ = build_text_svg("a mono_w
def test_empty_line_kept(self):
# a blank line still occupies a line box
_, _, height, line_height = build_text_svg("a\n\nb", font_size=10)
assert height == 3 * line_height
def test_matches_web_ui_serializer_shape(self):
# byte-for-byte structural parity with the Web UI's own text output
svg, width, height, _ = build_text_svg("demo", font_size=11)
assert svg.startswith(f'