diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2026-02-07 17:29:48 +0100 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2026-02-07 17:29:48 +0100 |
| commit | 2eda97537b63d68b2e9ba06500e3fb491894d10c (patch) | |
| tree | 52873ad380cd97f4327765aac24659a2b00079b1 /tests/qml | |
feat: camper van energy monitoring widget for Plasma 6main
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/qml')
| -rw-r--r-- | tests/qml/tst_icon_utils.qml | 91 | ||||
| -rw-r--r-- | tests/qml/tst_value_formatting.qml | 76 |
2 files changed, 167 insertions, 0 deletions
diff --git a/tests/qml/tst_icon_utils.qml b/tests/qml/tst_icon_utils.qml new file mode 100644 index 0000000..4b0b67b --- /dev/null +++ b/tests/qml/tst_icon_utils.qml @@ -0,0 +1,91 @@ +import QtQuick 6.0 +import QtTest 1.0 +import "../../package/contents/ui" as Ui + +TestCase { + name: "IconUtils" + + Ui.IconUtils { id: icons } + + // getBatteryIcon — boundary and edge cases + function test_battery_undefined() { + compare(icons.getBatteryIcon(undefined), "\uf244") + } + + function test_battery_null() { + compare(icons.getBatteryIcon(null), "\uf244") + } + + function test_battery_negative() { + compare(icons.getBatteryIcon(-1), "\uf244") + } + + function test_battery_zero() { + compare(icons.getBatteryIcon(0), "\uf244") + } + + function test_battery_low_boundary() { + compare(icons.getBatteryIcon(20), "\uf244") + } + + function test_battery_quarter() { + compare(icons.getBatteryIcon(21), "\uf243") + } + + function test_battery_quarter_boundary() { + compare(icons.getBatteryIcon(40), "\uf243") + } + + function test_battery_half() { + compare(icons.getBatteryIcon(41), "\uf242") + } + + function test_battery_half_boundary() { + compare(icons.getBatteryIcon(60), "\uf242") + } + + function test_battery_three_quarter() { + compare(icons.getBatteryIcon(61), "\uf241") + } + + function test_battery_three_quarter_boundary() { + compare(icons.getBatteryIcon(80), "\uf241") + } + + function test_battery_full() { + compare(icons.getBatteryIcon(81), "\uf240") + } + + function test_battery_full_100() { + compare(icons.getBatteryIcon(100), "\uf240") + } + + // getDirectionIcon — all states + function test_direction_charge() { + compare(icons.getDirectionIcon("charge"), "\uf185") + } + + function test_direction_discharge() { + compare(icons.getDirectionIcon("discharge"), "\uf0e7") + } + + function test_direction_idle() { + compare(icons.getDirectionIcon("idle"), "\uf186") + } + + function test_direction_unknown() { + compare(icons.getDirectionIcon("bogus"), "") + } + + function test_direction_empty() { + compare(icons.getDirectionIcon(""), "") + } + + function test_direction_null() { + compare(icons.getDirectionIcon(null), "") + } + + function test_direction_undefined() { + compare(icons.getDirectionIcon(undefined), "") + } +} 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), "--") + } +} |
