File: tst_store.qml

package info (click to toggle)
quickflux 1.1.3%2Bgit20201110.2a37acf-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,036 kB
  • sloc: cpp: 2,874; makefile: 26
file content (90 lines) | stat: -rw-r--r-- 1,872 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import QtQuick 2.0
import QtTest 1.0
import QuickFlux 1.1

TestCase {
    name : "StoreTests"

    ActionCreator {
        id: defaultActionCreator
        signal test1();
    }

    ActionCreator {
        id: actionCreator1
        dispatcher: Dispatcher {
            id: dispatcher1
        }

        signal test1();
    }

    Store {
        id: store1
        property int test1: 0

        Filter {
            type: "test1"
            onDispatched: {
                store1.test1++;
            }
        }
    }

    function test_dispatch() {

        // Unlike AppListener, Store component do not from AppDispatcher directly.
        compare(store1.bindSource, null);

        store1.dispatch("test1");
        compare(store1.test1, 1);

        defaultActionCreator.test1();
        compare(store1.test1, 1);

        actionCreator1.test1();
        compare(store1.test1, 1); // It is not changed

        store1.bind(actionCreator1);
        compare(store1.bindSource, actionCreator1);

        actionCreator1.test1();
        compare(store1.test1, 2);

        defaultActionCreator.test1();
        compare(store1.test1, 2);

    }


    Store {
        id: store2
        property int test1Count: 0
        property int test2Count: 0
        property var messages: [];

        function test1(message) {
            store2.test1Count++;
            messages.push(message);
        }

        function test2() {
            store2.test2Count++;
        }
    }

    function test_filterFunctionEnabled() {
        var m = {value: 1};
        store2.dispatch("test1", m);
        compare(store2.test1Count, 0);
        store2.filterFunctionEnabled = true;
        store2.dispatch("test1", m);
        compare(store2.test1Count, 1);
        compare(store2.messages[0], m);

        store2.dispatch("test2");
        compare(store2.test2Count, 1);
    }

}