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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import QtQuick
import QtTest
import QtLocation
import QtPositioning
import "utils.js" as Utils
TestCase {
id: testCase
name: "PlaceSearchSuggestionModel"
PlaceSearchSuggestionModel {
id: testModel
}
PlaceSearchSuggestionModel {
id: testModelError
}
Plugin {
id: testPlugin
name: "qmlgeo.test.plugin"
allowExperimental: true
}
Plugin {
id: nonExistantPlugin
name: "nonExistantName"
}
Plugin {
id: uninitializedPlugin
}
function test_setAndGet_data() {
var testSearchArea = QtPositioning.circle(QtPositioning.coordinate(10, 20), 5000);
return [
{ tag: "plugin", property: "plugin", signal: "pluginChanged", value: testPlugin },
{ tag: "searchArea", property: "searchArea", signal: "searchAreaChanged", value: testSearchArea, reset: QtPositioning.shape() },
{ tag: "limit", property: "limit", signal: "limitChanged", value: 10, reset: -1 },
{ tag: "searchTerm", property: "searchTerm", signal: "searchTermChanged", value: "Test term", reset: "" },
];
}
function test_setAndGet(data) {
Utils.testObjectProperties(testCase, testModel, data);
}
SignalSpy { id: statusChangedSpy; target: testModel; signalName: "statusChanged" }
SignalSpy { id: suggestionsChangedSpy; target: testModel; signalName: "suggestionsChanged" }
function test_suggestions() {
compare(statusChangedSpy.count, 0);
testModel.plugin = testPlugin;
compare(testModel.status, PlaceSearchSuggestionModel.Null);
testModel.searchTerm = "test";
testModel.update();
compare(testModel.status, PlaceSearchSuggestionModel.Loading);
compare(statusChangedSpy.count, 1);
tryCompare(testModel, "status", PlaceSearchSuggestionModel.Ready);
compare(statusChangedSpy.count, 2);
var expectedSuggestions = [ "test1", "test2", "test3" ];
compare(suggestionsChangedSpy.count, 1);
compare(testModel.suggestions, expectedSuggestions);
testModel.reset();
compare(statusChangedSpy.count, 3);
compare(testModel.status, PlaceSearchSuggestionModel.Null);
compare(suggestionsChangedSpy.count, 2);
compare(testModel.suggestions, []);
testModel.update();
compare(statusChangedSpy.count, 4);
compare(testModel.status, PlaceSearchSuggestionModel.Loading);
testModel.cancel();
compare(statusChangedSpy.count, 5);
compare(testModel.status, PlaceSearchSuggestionModel.Ready);
//check that an encountering an error will cause the model
//to clear its data
testModel.plugin = null;
testModel.update();
tryCompare(testModel.suggestions, "length", 0);
compare(testModel.status, PlaceSearchSuggestionModel.Error);
}
SignalSpy { id: statusChangedSpyError; target: testModelError; signalName: "statusChanged" }
function test_error() {
compare(statusChangedSpyError.count, 0);
//try searching without a plugin instance
testModelError.update();
tryCompare(statusChangedSpyError, "count", 2);
compare(testModelError.status, PlaceSearchSuggestionModel.Error);
statusChangedSpyError.clear();
//Aside: there is some difficulty in checking the transition to the Loading state
//since the model transitions from Loading to Error before the next event loop
//iteration.
//try searching with an uninitialized plugin instance.
testModelError.plugin = uninitializedPlugin;
testModelError.update();
tryCompare(statusChangedSpyError, "count", 2);
compare(testModelError.status, PlaceSearchSuggestionModel.Error);
statusChangedSpyError.clear();
//try searching with plugin a instance
//that has been provided a non-existent name
testModelError.plugin = nonExistantPlugin;
testModelError.update();
tryCompare(statusChangedSpyError, "count", 2);
compare(testModelError.status, PlaceSearchSuggestionModel.Error);
}
}
|