From 2eda97537b63d68b2e9ba06500e3fb491894d10c Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Sat, 7 Feb 2026 17:29:48 +0100 Subject: feat: camper van energy monitoring widget for Plasma 6 Pure QML KPackage widget with Rust background service for real-time Victron energy system monitoring via MQTT and D-Bus. Co-Authored-By: Claude Opus 4.6 --- tests/qml/tst_value_formatting.qml | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/qml/tst_value_formatting.qml (limited to 'tests/qml/tst_value_formatting.qml') diff --git a/tests/qml/tst_value_formatting.qml b/tests/qml/tst_value_formatting.qml new file mode 100644 index 0000000..78d39dc --- /dev/null +++ b/tests/qml/tst_value_formatting.qml @@ -0,0 +1,76 @@ +import QtQuick 6.0 +import QtTest 1.0 +import "../../package/contents/ui" as Ui + +TestCase { + name: "ValueFormatting" + + Ui.FormatUtils { id: fmt } + + // formatSoc + function test_soc_normal() { + compare(fmt.formatSoc(75.3), "75%") + } + + function test_soc_zero() { + compare(fmt.formatSoc(0), "0%") + } + + function test_soc_full() { + compare(fmt.formatSoc(100), "100%") + } + + function test_soc_rounds_up() { + compare(fmt.formatSoc(49.6), "50%") + } + + function test_soc_negative() { + compare(fmt.formatSoc(-1), "--") + } + + function test_soc_undefined() { + compare(fmt.formatSoc(undefined), "--") + } + + function test_soc_null() { + compare(fmt.formatSoc(null), "--") + } + + function test_soc_nan() { + compare(fmt.formatSoc(NaN), "--") + } + + // formatPower + function test_power_connected() { + compare(fmt.formatPower(true, 123.7), "124W") + } + + function test_power_connected_zero() { + compare(fmt.formatPower(true, 0), "0W") + } + + function test_power_disconnected() { + compare(fmt.formatPower(false, 50), "--") + } + + // formatSolar + function test_solar_normal() { + compare(fmt.formatSolar(200.4), "200W") + } + + function test_solar_zero() { + compare(fmt.formatSolar(0), "0W") + } + + function test_solar_negative() { + compare(fmt.formatSolar(-1), "--") + } + + function test_solar_undefined() { + compare(fmt.formatSolar(undefined), "--") + } + + function test_solar_nan() { + compare(fmt.formatSolar(NaN), "--") + } +} -- cgit v1.2.3