summaryrefslogtreecommitdiff
path: root/tests/qml/tst_value_formatting.qml
blob: 78d39dc21552c66a6f8da11087b004c6747f8fa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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), "--")
    }
}