import unittest
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
CONVERSION_RATE = (
    ROOT / "hdyc-svelte" / "src" / "lib" / "utils" / "conversionRate.ts"
)


class ConversionRateTooltipFormattingTests(unittest.TestCase):
    def test_conversion_rate_text_uses_formatter(self) -> None:
        text = CONVERSION_RATE.read_text(encoding="utf-8")
        normalized = " ".join(text.split())
        self.assertIn(
            "formatConversionValue(config.factor)",
            normalized,
            "Conversion rate helper must format the factor before inserting it into the tooltip text",
        )
        self.assertIn(
            "formatConversionValue(config.offset ?? 0)",
            normalized,
            "Conversion rate tooltip must format any offset before rendering",
        )


if __name__ == "__main__":
    unittest.main()
