Normalize conversion factor formatting
This commit is contained in:
27
tests/test_conversion_rate_tooltip.py
Normal file
27
tests/test_conversion_rate_tooltip.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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()
|
||||
26
tests/test_quick_conversion_formatting.py
Normal file
26
tests/test_quick_conversion_formatting.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
QUICK_CONVERSION_EXAMPLE = (
|
||||
ROOT / "hdyc-svelte" / "src" / "lib" / "components" / "QuickConversionExample.svelte"
|
||||
)
|
||||
|
||||
|
||||
class QuickConversionExampleFormattingTests(unittest.TestCase):
|
||||
def test_formula_uses_formatted_factor_and_offset(self) -> None:
|
||||
text = QUICK_CONVERSION_EXAMPLE.read_text(encoding="utf-8")
|
||||
normalized = " ".join(text.split())
|
||||
snippet = (
|
||||
"1 {config.labels.in1} = {formattedFactorValue}{hasOffset ? ` + ${formattedOffsetValue}` : ''} "
|
||||
"{config.labels.in2}"
|
||||
)
|
||||
self.assertIn(
|
||||
snippet,
|
||||
normalized,
|
||||
"The formula snippet should render formatted factor/offset values instead of raw floats",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user